Skip to content

Commit

Permalink
Fix dcargs.conf.SuppressFixed bug + test
Browse files Browse the repository at this point in the history
  • Loading branch information
brentyi committed Oct 5, 2022
1 parent 86aa11a commit d5e6f80
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
3 changes: 1 addition & 2 deletions dcargs/_arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>"]
include = ["./dcargs/**/*"]
Expand Down
16 changes: 15 additions & 1 deletion tests/test_helptext.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

0 comments on commit d5e6f80

Please sign in to comment.