Skip to content

Commit

Permalink
Fix Literal type labeling for Python <3.10.
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewwardrop committed Aug 15, 2024
1 parent a370649 commit e82beb5
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions spec_classes/utils/type_checking.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,9 @@ def type_label(attr_type: Type) -> str:
method general.
"""
if hasattr(attr_type, "__origin__"): # Generics
label = type_label(attr_type.__origin__)
if attr_type.__origin__ is Literal:
return (
f"{label}[{', '.join(repr(arg) for arg in attr_type.__args__)}]"
)
return f"Literal[{', '.join(repr(arg) for arg in attr_type.__args__)}]"
label = type_label(attr_type.__origin__)
if hasattr(attr_type, "__args__") and not any(
isinstance(arg, TypeVar) for arg in attr_type.__args__
):
Expand Down

0 comments on commit e82beb5

Please sign in to comment.