2.12.2021, 9:00 - 11:00: Due to updates GitLab may be unavailable for some minutes between 09:00 and 11:00.

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: # try:
base_type = base_type.__origin__ # base_type = base_type.__origin__
except AttributeError: # except AttributeError:
pass # pass
try: # try:
mro = inspect.getmro(sub_type) # sub_type = sub_type.__origin__
except AttributeError: # except AttributeError:
mro = [] # pass
for t in sub_type.__mro_entries__([sub_type]): def origin(t):
mro.extend(inspect.getmro(t)) try:
# print(" " if base_type in mro else "!", base_type, sub_type, mro) ot = t.__origin__
return base_type in mro except AttributeError:
return t
return ot if ot is not None else t
return issubclass(origin(sub_type), origin(base_type))
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