From d5e6f8095d3000ab0ae89335b1c3b3dab199c080 Mon Sep 17 00:00:00 2001 From: Brent Yi Date: Tue, 4 Oct 2022 17:45:54 -0700 Subject: [PATCH] Fix `dcargs.conf.SuppressFixed` bug + test --- dcargs/_arguments.py | 3 +-- pyproject.toml | 2 +- tests/test_helptext.py | 16 +++++++++++++++- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/dcargs/_arguments.py b/dcargs/_arguments.py index dfa94a1c..8efeaa9b 100644 --- a/dcargs/_arguments.py +++ b/dcargs/_arguments.py @@ -297,8 +297,7 @@ def _rule_generate_helptext( # If the suppress marker is attached, hide the argument. if _markers.Suppress in arg.field.markers or ( - _markers.SuppressFixed in arg.field.markers - and _markers.Fixed in arg.field.markers + _markers.SuppressFixed in arg.field.markers and lowered.is_fixed() ): return dataclasses.replace(lowered, help=argparse.SUPPRESS) diff --git a/pyproject.toml b/pyproject.toml index 1245b58f..89a20155 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "dcargs" -version = "0.3.18" +version = "0.3.19" description = "Strongly typed, zero-effort CLI interfaces" authors = ["brentyi "] include = ["./dcargs/**/*"] diff --git a/tests/test_helptext.py b/tests/test_helptext.py index 61b64c11..2246f110 100644 --- a/tests/test_helptext.py +++ b/tests/test_helptext.py @@ -626,7 +626,7 @@ def main(x: Any = Struct()): assert "--x.b" not in helptext -def test_suppress_fixed(): +def test_suppress_manual_fixed(): @dataclasses.dataclass class Struct: a: int = 5 @@ -638,3 +638,17 @@ def main(x: Any = Struct()): helptext = _get_helptext(main) assert "--x.a" in helptext assert "--x.b" not in helptext + + +def test_suppress_auto_fixed(): + @dataclasses.dataclass + class Struct: + a: int = 5 + b: Callable = lambda x: 5 + + def main(x: dcargs.conf.SuppressFixed[Any] = Struct()): + pass + + helptext = _get_helptext(main) + assert "--x.a" in helptext + assert "--x.b" not in helptext