Skip to content

Commit

Permalink
Fix container subcommands for Python 3.10
Browse files Browse the repository at this point in the history
  • Loading branch information
brentyi committed Mar 12, 2023
1 parent 8ccd20b commit 6ed7282
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "tyro"
version = "0.4.1"
version = "0.4.2"
description = "Strongly typed, zero-effort CLI interfaces"
authors = ["brentyi <[email protected]>"]
include = ["./tyro/**/*"]
Expand Down Expand Up @@ -66,6 +66,7 @@ exclude_lines = [

# or assert statements & errors
"assert",
"raise AssertionError",

# or anything that's not implemented
"NotImplementedError()",
Expand Down
9 changes: 5 additions & 4 deletions tyro/_strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,13 @@ def _subparser_name_from_type(cls: Type) -> Tuple[str, bool]:

# Subparser name from class name.
def get_name(cls: Type) -> str:
if hasattr(cls, "__name__"):
return hyphen_separated_from_camel_case(cls.__name__)
elif hasattr(get_origin(cls), "__name__"):
parts = [get_origin(cls).__name__] # type: ignore
orig = get_origin(cls)
if orig is not None and hasattr(orig, "__name__"):
parts = [orig.__name__] # type: ignore
parts.extend(map(get_name, get_args(cls)))
return "-".join(parts)
elif hasattr(cls, "__name__"):
return hyphen_separated_from_camel_case(cls.__name__)
else:
raise AssertionError(
f"Tried to interpret {cls} as a subcommand, but could not infer name"
Expand Down

0 comments on commit 6ed7282

Please sign in to comment.