Stewori / pytypes

Typing-toolbox for Python 3 _and_ 2.7 w.r.t. PEP 484.
Apache License 2.0
200 stars 20 forks source link

Some differences between Python 3.6 and 3.8 #103

Open mitar opened 2 years ago

mitar commented 2 years ago

I know that Python 3.7/3.8 support is still in progress and I was testing the master branch and found some differences so I am reporting them to maybe use them as unit tests. With Python 3.6:

>>> import typing
>>> from pytypes import type_util
>>> type_util._issubclass(type_util.deep_type({}), typing.Union[typing.Dict, type(None)])
True
>>> type_util._issubclass(type_util.deep_type({}), typing.Union[typing.Dict[str, typing.Any], type(None)])
True
>>> type_util._issubclass(type_util.deep_type({}), typing.Dict[str, typing.Any])
True

Python 3.8:

>>> import typing
>>> from pytypes import type_util
>>> type_util._issubclass(type_util.deep_type({}), typing.Union[typing.Dict, type(None)])
True
>>> type_util._issubclass(type_util.deep_type({}), typing.Union[typing.Dict[str, typing.Any], type(None)])
False
>>> type_util._issubclass(type_util.deep_type({}), typing.Dict[str, typing.Any])
True
Stewori commented 2 years ago

Definitely, the Python 3.6 variant looks correct to me. I will consider this a proper bug to be fixed.

mitar commented 2 years ago

Another set. Python 3.6:

>>> import typing
>>> from pytypes import type_util
>>> class Foo(dict):
...   pass
... 
>>> type_util._issubclass(type_util.deep_type({}), dict)
True
>>> type_util._issubclass(type_util.deep_type({}), typing.Dict)
True
>>> type_util._issubclass(type_util.deep_type(Foo()), typing.Dict)
True

Python 3.8:

>>> import typing
>>> from pytypes import type_util
>>> class Foo(dict):
...   pass
... 
>>> type_util._issubclass(type_util.deep_type({}), dict)
True
>>> type_util._issubclass(type_util.deep_type({}), typing.Dict)
True
>>> type_util._issubclass(type_util.deep_type(Foo()), typing.Dict)
False
mitar commented 2 years ago

Another difference. It should be True, but on Python 3.8 returns False.

type_util._issubclass(type_util.deep_type([{'cc': 1, 'dd': 2}, {'ee': 1, 'ff': 2}]), typing.Sequence[object])