Skip to content

Commit

Permalink
fix: py36 compatibility for get_origin(Annotated)
Browse files Browse the repository at this point in the history
  • Loading branch information
jnoortheen committed Feb 16, 2021
1 parent b969fee commit 20abc00
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
6 changes: 5 additions & 1 deletion arger/typing_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
from inspect import isclass
from typing import Any, FrozenSet, List, Set, Tuple, TypeVar, Union

import typing_extensions as tpe

NEW_TYPING = sys.version_info[:3] >= (3, 7, 0) # PEP 560


Expand Down Expand Up @@ -34,12 +36,14 @@ def define_old_types():

def get_origin(tp):
"""Return the python class for the GenericAlias. Dict->dict, List->list..."""
origin = _get_origin(tp)

origin = _get_origin(tp)
if not NEW_TYPING and hasattr(tp, "__name__"):
old_type_origins = define_old_types()
if tp.__name__ in old_type_origins:
return old_type_origins[tp.__name__]
if tp.__name__ == "Annotated" and tp.__args__:
return tp.__args__[0]
return origin


Expand Down
4 changes: 2 additions & 2 deletions tasks.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import shlex
import subprocess as sp
import sys

from delegator import run
from typing_extensions import Literal
import subprocess as sp

from arger import Arger

arger = Arger(
Expand Down

0 comments on commit 20abc00

Please sign in to comment.