Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
badw-it
DHParser
Commits
37f225a0
Commit
37f225a0
authored
Jul 02, 2018
by
eckhart
Browse files
- toolkit.issubtype: Bugs for Python 3.7 fixed
parent
d008de94
Changes
2
Hide whitespace changes
Inline
Side-by-side
DHParser/toolkit.py
View file @
37f225a0
...
...
@@ -112,20 +112,23 @@ def is_filename(strg: str) -> bool:
def
issubtype
(
sub_type
,
base_type
):
if
sys
.
version_info
.
major
<=
3
and
sys
.
version_info
.
minor
<=
6
:
return
issubclass
(
sub_type
,
base_type
)
try
:
base_type
=
base_type
.
__origin__
except
AttributeError
:
pass
try
:
mro
=
inspect
.
getmro
(
sub_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
# if sys.version_info.major <= 3 and sys.version_info.minor <= 6:
# 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
:
ot
=
t
.
__origin__
except
AttributeError
:
return
t
return
ot
if
ot
is
not
None
else
t
return
issubclass
(
origin
(
sub_type
),
origin
(
base_type
))
def
isgenerictype
(
t
):
...
...
test/test_toolkit.py
View file @
37f225a0
...
...
@@ -153,7 +153,7 @@ class TestStringHelpers:
class
TestTypeSystemSupport
:
def
test_issubtype
(
self
):
assert
issubtype
(
typing
.
List
,
typing
.
List
)
assert
issubtype
(
typing
.
List
,
collections
.
abc
.
Sequence
)
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment