Skip to content
Myr

ignore empty env vars consistently

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

authored by David Lord · committed by David Lord · parent 25a8879 · Browse files · 2 files+19 added−3 removed
This commit

State

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

Diff stats

2 files+19 added−3 removed

  • other:+19 added−3 removed

2 files+19 added−3 removed

modified:src/click/core.py+16 added-3 removed
2023 unmodified lines
20242025 def resolve_envvar_value(self, ctx):2026 if self.envvar is None:2027 return20282029 if isinstance(self.envvar, (tuple, list)):2030 for envvar in self.envvar:2031 rv = os.environ.get(envvar)2031 if rv is not None:20322033 if rv:2034 return rv2035 else:2036 rv = os.environ.get(self.envvar)20372036 if rv != "":2038 if rv:2039 return rv20402041 def value_from_envvar(self, ctx):2042 rv = self.resolve_envvar_value(ctx)20432044 if rv is not None and self.nargs != 1:2045 rv = self.type.split_envvar_value(rv)20462047 return rv20482049 def handle_parse_result(self, ctx, opts, args):2050 with augment_usage_errors(ctx, param=self):
376 unmodified lines
2427 rv = super().resolve_envvar_value(ctx)24282429 if rv is not None:2430 return rv24312432 if self.allow_from_autoenv and ctx.auto_envvar_prefix is not None:2433 envvar = f"{ctx.auto_envvar_prefix}_{self.name.upper()}"2429 return os.environ.get(envvar)2434 rv = os.environ.get(envvar)24352436 if rv:2437 return rv24382439 def value_from_envvar(self, ctx):2440 rv = self.resolve_envvar_value(ctx)24412442 if rv is None:2443 return None24442445 value_depth = (self.nargs != 1) + bool(self.multiple)24462447 if value_depth > 0 and rv is not None:2448 rv = self.type.split_envvar_value(rv)24492450 if self.multiple and self.nargs != 1:2451 rv = batch(rv, self.nargs)24522453 return rv24542455 def consume_value(self, ctx, opts):2456 value, source = super().consume_value(ctx, opts)
79 unmodified lines
modified:CHANGES.rst+3 added
129 unmodified lines
130- Options with ``nargs`` > 1 no longer raise an error if a default is131 not given. Parameters with ``nargs`` > 1 default to ``None``, and132 parameters with ``multiple=True`` or ``nargs=-1`` default to an133 empty tuple. :issue:`472`134- Handle empty env vars as though the option were not passed. This135 extends the change introduced in 7.1 to be consistent in more cases.136 :issue:`1285`137138139Version 7.1.2140-------------
635 unmodified lines