Skip to content
Myr

Lint

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 06847da · Browse files · 2 files+19 added−15 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−15 removed

  • tests:+14 added−10 removed
  • other:+5 added−5 removed

2 files+19 added−15 removed

modified:src/click/core.py+5 added-5 removed
2420 unmodified lines
24212422 # Return the first non-empty value of the list of environment variables.2423 if rv:2424 return rv2425 # Else, absence of value is interpreted as an environment variable that is2426 # not set, so proceed to the next one.2425 # Else, absence of value is interpreted as an environment variable that2426 # is not set, so proceed to the next one.24272428 return None24292430 def value_from_envvar(self, ctx: Context) -> str | cabc.Sequence[str] | None:
310 unmodified lines
2741 # This message is a convoluted way to explain that if you want things2742 # to be equal, make them equal.2743 # warnings.warn(2744 # "A flag's `default` value will no longer be aligned with its "2745 # "`flag_value` if `default=True` in Click 9.0. If you want the flag to "2746 # "get the same `default` as its `flag_value`, update the option to "2747 # "make its `default` parameter equal to its `flag_value`.",2745 # "`flag_value` if `default=True` in Click 9.0. If you want the flag "2746 # "to get the same `default` as its `flag_value`, update the option "2747 # "to make its `default` parameter equal to its `flag_value`.",2748 # DeprecationWarning,2749 # stacklevel=2,2750 # )2751 self.default = self.flag_value
576 unmodified lines
modified:tests/test_options.py+14 added-10 removed
1719 unmodified lines
1720class EnumSentinel(enum.Enum):1721 FALSY_SENTINEL = object()17221723 def __bool__(self) -> Literal[False]:1724 """Force the sentinel to be falsy to make sure it is not caught by Click internal1725 implementation.1724 """Force the sentinel to be falsy to make sure it is not caught by Click1725 internal implementation.17261727 Falsy sentinels have been discussed in:1728 https://github.com/pallets/click/pull/3030#pullrequestreview-31066047951729 https://github.com/pallets/click/pull/3030#pullrequestreview-3108471552
125 unmodified lines
18551856@pytest.mark.parametrize(1857 ("opt_params", "args", "expected"),1858 [1859 # Check that the flag value is returned as-is when the option is passed, and not normalized1860 # to a boolean, even if it is explicitly declared as a flag.1859 # Check that the flag value is returned as-is when the option is passed, and1860 # not normalized to a boolean, even if it is explicitly declared as a flag.1861 ({"type": EngineType, "flag_value": None}, ["--pro"], None),1862 (1863 {"type": EngineType, "is_flag": True, "flag_value": None},1864 ["--pro"],
9 unmodified lines
1874 {"type": EngineType, "is_flag": True, "default": EngineType.OSS},1875 ["--pro"],1876 EngineType.OSS,1877 ),1878 # The default value is returned as-is when the option is not passed, whatever the flag value.1878 # The default value is returned as-is when the option is not passed, whatever1879 # the flag value.1880 ({"type": EngineType, "flag_value": None}, [], None),1881 ({"type": EngineType, "is_flag": True, "flag_value": None}, [], None),1882 ({"type": EngineType, "flag_value": EngineType.OSS}, [], None),1883 (
5 unmodified lines
1889 {"type": EngineType, "is_flag": True, "default": EngineType.OSS},1890 [],1891 EngineType.OSS,1892 ),1892 # The option has not enough parameters to be detected as flag-like, so it requires an argument.1893 # The option has not enough parameters to be detected as flag-like, so it1894 # requires an argument.1895 (1896 {"type": EngineType, "default": EngineType.OSS},1897 ["--pro"],1898 re.compile(re.escape("Error: Option '--pro' requires an argument.\n")),
27 unmodified lines
1926 [],1927 "EngineType.OSS",1928 ),1929 ({"type": str, "flag_value": EngineType.OSS, "default": 42}, [], "42"),1928 # But having the flag value set to integer is automaticcally recognized by Click.1930 # But having the flag value set to integer is automaticcally recognized by1931 # Click.1932 ({"flag_value": 1, "default": True}, [], 1),1933 ({"flag_value": 1, "default": 42}, [], 42),1934 ({"type": int, "flag_value": 1, "default": True}, [], 1),1935 ({"type": int, "flag_value": 1, "default": 42}, [], 42),
24 unmodified lines
1960@pytest.mark.parametrize(1961 ("opt1_params", "opt2_params", "args", "expected"),1962 [1963 # Dual options sharing the same variable name, are not competitive, and the1961 # flag value is returned as-is. Especially when the type is force to be unprocessed.1964 # flag value is returned as-is. Especially when the type is force to be1965 # unprocessed.1966 (1967 {"flag_value": EngineType.OSS, "type": UNPROCESSED},1968 {"flag_value": EngineType.PRO, "type": UNPROCESSED},1969 [],
10 unmodified lines
1980 {"flag_value": EngineType.PRO, "type": UNPROCESSED},1981 ["--opt2"],1982 EngineType.PRO,1983 ),1980 # Check that passing exotic flag values like classes is supported, but are rendered to strings1981 # when the type is not specified.1984 # Check that passing exotic flag values like classes is supported, but are1985 # rendered to strings when the type is not specified.1986 (1987 {"flag_value": Class1, "default": True},1988 {"flag_value": Class2},1989 [],
128 unmodified lines