Commit 37f225a0 authored by eckhart's avatar eckhart
Browse files

- toolkit.issubtype: Bugs for Python 3.7 fixed

parent d008de94
...@@ -112,20 +112,23 @@ def is_filename(strg: str) -> bool: ...@@ -112,20 +112,23 @@ def is_filename(strg: str) -> bool:
def issubtype(sub_type, base_type): def issubtype(sub_type, base_type):
if sys.version_info.major <= 3 and sys.version_info.minor <= 6: # if sys.version_info.major <= 3 and sys.version_info.minor <= 6:
return issubclass(sub_type, base_type) # return issubclass(sub_type, base_type)
# try:
# base_type = base_type.__origin__
# except AttributeError:
# pass
# try:
# sub_type = sub_type.__origin__
# except AttributeError:
# pass
def origin(t):
try: try:
base_type = base_type.__origin__ ot = t.__origin__
except AttributeError: except AttributeError:
pass return t
try: return ot if ot is not None else t
mro = inspect.getmro(sub_type) return issubclass(origin(sub_type), origin(base_type))
except AttributeError:
mro = []
for t in sub_type.__mro_entries__([sub_type]):
mro.extend(inspect.getmro(t))
# print(" " if base_type in mro else "!", base_type, sub_type, mro)
return base_type in mro
def isgenerictype(t): def isgenerictype(t):
......
...@@ -153,7 +153,7 @@ class TestStringHelpers: ...@@ -153,7 +153,7 @@ class TestStringHelpers:
class TestTypeSystemSupport: class TestTypeSystemSupport:
def test_issubtype(self): def test_issubtype(self):
assert issubtype(typing.List, typing.List) assert issubtype(typing.List, collections.abc.Sequence)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment