konradhalas / dacite

Simple creation of data classes from dictionaries.
MIT License
1.76k stars 106 forks source link

Issue with python 3.9.b1 #98

Closed ondrejmular closed 4 years ago

ondrejmular commented 4 years ago

Hey, first of all thank you for a great lib!

In Fedora, all python packages are currently being rebuild and tested with the latest Python 3.9 beta1. And it seems like there have been some changes in internals of typing module.

After a really quick investigation I found that accessing __args__ attribute of a type object (e.g. typing.Mapping, used in tests) raises an AttributeError exception.

I tried to fix that issue in this commit https://github.com/ondrejmular/dacite/commit/37a7d1f4083126ce698797ff945340560764fc4d. With this commit, dacite test suite is passing.

I have not created a PR just yet, as after a further research I found that there are some other changes that may affect functionality of this lib even though tests are passing. I've noticed that _special attribute is missing as well (at least in typing.Mapping), and I think I've seen this attribute used somewhere in the codebase. I wasn't able to find anything related to this in what's new in python 3.9.

Here is a difference that I found between python 3.8 and python 3.9 yet:

[root@node1 ~]# python3
Python 3.8.2 (default, Feb 28 2020, 00:00:00)
[GCC 10.0.1 20200216 (Red Hat 10.0.1-0.8)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import typing
>>> typing.Mapping.__args__
(~KT, +VT_co)
>>> typing.Mapping.__dict__
{'_inst': True, '_special': True, '_name': 'Mapping', '__origin__': <class 'collections.abc.Mapping'>, '__args__': (~KT, +VT_co), '__parameters__': (~KT, +VT_co), '__slots__': None}
>>>
[root@node2 ~]# python3
Python 3.9.0b1 (default, May 21 2020, 00:00:00)
[GCC 10.1.1 20200507 (Red Hat 10.1.1-1)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import typing
>>> typing.Mapping.__args__
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib64/python3.9/typing.py", line 640, in __getattr__
    raise AttributeError(attr)
AttributeError: __args__
>>> typing.Mapping.__dict__
{'_inst': True, '_name': 'Mapping', '__origin__': <class 'collections.abc.Mapping'>, '__slots__': None, '_nparams': 2, '__doc__': 'A generic version of collections.abc.Mapping.'}
>>>
konradhalas commented 4 years ago

hi @ondrejmular - thank you for reporting this issue and I glad you like dacite :)

That's interesting - I run all tests with Python 3.9.0a6+ a few weeks ago and everything was green, but I've just updated Python 3.9 and OFC it doesn't work right now.

I will take a closer look where is the problem and of course I will update dacite.

ondrejmular commented 4 years ago

Hello, do you have any estimate when this can be fixed? I need to decide whether I should wait for your fixed version or temporarily use my patch which fixed our use case. Thanks

konradhalas commented 4 years ago

@ondrejmular my estimation is "-5min" ;)

Please check 1.5.1 version, should be fixed now.