Skip to content
Myr

Don't refactor variable names unnecessarily

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Kevin Deldycke · committed by Kevin Deldycke · parent c442c05 · Browse files · 1 file+19 added−19 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Trailers

  • Address: https://github.com/pallets/click/pull/3030/files#r2289177206

Diff stats

1 file+19 added−19 removed

  • other:+19 added−19 removed

1 file+19 added−19 removed

modified:src/click/core.py+19 added-19 removed
2405 unmodified lines
2406 return None24072408 envvars = [self.envvar] if isinstance(self.envvar, str) else self.envvar2409 for envvar in envvars:2410 raw_value = os.environ.get(envvar)2410 rv = os.environ.get(envvar)24112412 # Return the first non-empty value of the list of environment variables.2413 if raw_value:2414 return raw_value2413 if rv:2414 return rv2415 # Else, absence of value is interpreted as an environment variable that is2416 # not set, so proceed to the next one.24172418 return None
4 unmodified lines
2423 Returns the string as-is or splits it into a sequence of strings if the2424 parameter is expecting multiple values (i.e. its :attr:`nargs` property is set2425 to a value other than ``1``).2426 """2427 raw_value = self.resolve_envvar_value(ctx)2427 rv = self.resolve_envvar_value(ctx)24282429 if raw_value is not None and self.nargs != 1:2430 return self.type.split_envvar_value(raw_value)2429 if rv is not None and self.nargs != 1:2430 return self.type.split_envvar_value(rv)24312432 return raw_value2432 return rv24332434 def handle_parse_result(2435 self, ctx: Context, opts: cabc.Mapping[str, t.Any], args: list[str]2436 ) -> tuple[t.Any, list[str]]:
598 unmodified lines
3035 the :attr:`envvar` property, we fallback on :attr:`Context.auto_envvar_prefix`3036 to build dynamiccaly the environment variable name using the3037 :python:`{ctx.auto_envvar_prefix}_{self.name.upper()}` template.3038 """3039 raw_value = super().resolve_envvar_value(ctx)3039 rv = super().resolve_envvar_value(ctx)30403041 if raw_value is not None:3042 return raw_value3041 if rv is not None:3042 return rv30433044 if (3045 self.allow_from_autoenv3046 and ctx.auto_envvar_prefix is not None3047 and self.name is not None3048 ):3049 envvar = f"{ctx.auto_envvar_prefix}_{self.name.upper()}"3050 raw_value = os.environ.get(envvar)3050 rv = os.environ.get(envvar)30513052 # Return the first non-empty value of the list of environment variables.3053 if raw_value:3054 return raw_value3053 if rv:3054 return rv3055 # Else, absence of value is interpreted as an environment variable that is3056 # not set, so proceed to the next one.30573058 return None
9 unmodified lines
30683069 This method also takes care of repeated options (i.e. options with3070 :attr:`multiple` set to ``True``).3071 """3072 raw_value = self.resolve_envvar_value(ctx)3072 rv = self.resolve_envvar_value(ctx)30733074 # Absent environment variable or an empty string is interpreted as unset.3075 if raw_value is None:3075 if rv is None:3076 return None30773078 # Non-boolean flags are more liberal in what they accept. But a flag being a3079 # flag, its envvar value still needs to be analyzed to determine if the flag is3080 # activated or not.3081 if self.is_flag and not self.is_bool_flag:3082 # If the flag_value is set and match the envvar value, return it3083 # directly.3084 if self.flag_value is not UNSET and raw_value == self.flag_value:3084 if self.flag_value is not UNSET and rv == self.flag_value:3085 return self.flag_value3086 # Analyze the envvar value as a boolean to know if the flag is3087 # activated or not.3088 return types.BoolParamType.str_to_bool(raw_value)3088 return types.BoolParamType.str_to_bool(rv)30893090 # Split the envvar value if it is allowed to be repeated.3091 value_depth = (self.nargs != 1) + bool(self.multiple)3092 if value_depth > 0:3093 multi_rv = self.type.split_envvar_value(raw_value)3093 multi_rv = self.type.split_envvar_value(rv)3094 if self.multiple and self.nargs != 1:3095 multi_rv = batch(multi_rv, self.nargs) # type: ignore[assignment]30963097 return multi_rv30983099 return raw_value3099 return rv31003101 def consume_value(3102 self, ctx: Context, opts: cabc.Mapping[str, Parameter]3103 ) -> tuple[t.Any, ParameterSource]:
169 unmodified lines