question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Dataclasses has become a dependency of dacite on python 3.7.x

See original GitHub issue

I’m getting a confusing error with dacite 0.0.25. I’m using dacite in anAWS Lambda function (which is why the traceback looks a little funny), and I’m getting the following exception when importing dacite.config.Config:

AttributeError: module 'typing' has no attribute '_ClassVar'
Traceback (most recent call last):
  File "/var/lang/lib/python3.7/imp.py", line 234, in load_module
    return load_source(name, filename, file)
  File "/var/lang/lib/python3.7/imp.py", line 171, in load_source
    module = _load(spec)
  File "<frozen importlib._bootstrap>", line 696, in _load
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 728, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/var/task/cris/queue_event.py", line 8, in <module>
    from dacite import Config, from_dict
  File "/var/task/dacite/__init__.py", line 1, in <module>
    from dacite.config import Config
  File "/var/task/dacite/config.py", line 14, in <module>
    @dataclass
  File "/var/task/dataclasses.py", line 958, in dataclass
    return wrap(_cls)
  File "/var/task/dataclasses.py", line 950, in wrap
    return _process_class(cls, init, repr, eq, order, unsafe_hash, frozen)
  File "/var/task/dataclasses.py", line 801, in _process_class
    for name, type in cls_annotations.items()]
  File "/var/task/dataclasses.py", line 801, in <listcomp>
    for name, type in cls_annotations.items()]
  File "/var/task/dataclasses.py", line 659, in _get_field
    if (_is_classvar(a_type, typing)
  File "/var/task/dataclasses.py", line 550, in _is_classvar
    return type(a_type) is typing._ClassVar

For some reason, the 0.0.25 release introduces dataclasses==0.6 as a dependency even though I’m on python 3.7.2

% pip --version
pip 19.0.3 from /usr/local/opt/pyenv/versions/3.7.2/envs/test/lib/python3.7/site-packages/pip (python 3.7)
% python --version
Python 3.7.2
% pip freeze
% pip install dacite
Collecting dacite
  Using cached https://files.pythonhosted.org/packages/48/a8/218d76025df9b63f6896f91a432a2ccbc658efb8c404e2d0af8c28f89dde/dacite-0.0.25-py3-none-any.whl
Collecting dataclasses (from dacite)
  Using cached https://files.pythonhosted.org/packages/26/2f/1095cdc2868052dd1e64520f7c0d5c8c550ad297e944e641dbf1ffbb9a5d/dataclasses-0.6-py3-none-any.whl
Installing collected packages: dataclasses, dacite
Successfully installed dacite-0.0.25 dataclasses-0.6
% pip freeze
dacite==0.0.25
dataclasses==0.6

If I attempt to install the 0.0.24, the dataclasses dependency is not present

pip install dacite==0.0.24
Collecting dacite==0.0.24
  Using cached https://files.pythonhosted.org/packages/60/a8/50cc19f7254f688c41140fd33531499f7d0b529617757c119a5b0e95ce01/dacite-0.0.24-py3-none-any.whl
Installing collected packages: dacite
Successfully installed dacite-0.0.24
% pip freeze
dacite==0.0.24

I went through the setup.py and cannot really understand where the dataclasses dependency leaks in on a 3.7 python. At the moment I’ve resorted to downgrading to 0.0.24 for my use case.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
konradhalascommented, Apr 19, 2019

Fixed, please try with newest version 0.0.26. Now I explicite “deploy” package on PyPI with Python 3.7 version.

0reactions
beetreecommented, Feb 16, 2020

Still having the same issue with version 1.2.0

Here’s log from lambda:

Function Logs:
START RequestId: d4d174f0-60ea-474c-bcad-d865736d2fc0 Version: $LATEST
[ERROR] AttributeError: module 'typing' has no attribute '_ClassVar'
Traceback (most recent call last):
  File "/var/lang/lib/python3.8/imp.py", line 234, in load_module
    return load_source(name, filename, file)
  File "/var/lang/lib/python3.8/imp.py", line 171, in load_source
    module = _load(spec)
  File "<frozen importlib._bootstrap>", line 702, in _load
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 783, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/var/task/src/new_order/order_load_from_shopify.py", line 2, in <module>
    from lib.Order import Order
  File "/var/task/lib/Order.py", line 3, in <module>
    from dacite import from_dict
  File "/var/task/aws_packages/dacite/__init__.py", line 1, in <module>
    from dacite.config import Config
  File "/var/task/aws_packages/dacite/config.py", line 6, in <module>
    class Config:
  File "/var/task/aws_packages/dataclasses.py", line 958, in dataclass
    return wrap(_cls)
  File "/var/task/aws_packages/dataclasses.py", line 950, in wrap
    return _process_class(cls, init, repr, eq, order, unsafe_hash, frozen)
  File "/var/task/aws_packages/dataclasses.py", line 800, in _process_class
    cls_fields = [_get_field(cls, name, type)
  File "/var/task/aws_packages/dataclasses.py", line 800, in <listcomp>
    cls_fields = [_get_field(cls, name, type)
  File "/var/task/aws_packages/dataclasses.py", line 659, in _get_field
    if (_is_classvar(a_type, typing)
  File "/var/task/aws_packages/dataclasses.py", line 550, in _is_classvar
    return type(a_type) is typing._ClassVarEND RequestId: d4d174f0-60ea-474c-bcad-d865736d2fc0
REPORT RequestId: d4d174f0-60ea-474c-bcad-d865736d2fc0	Duration: 4879.35 ms	Billed Duration: 4900 ms	Memory Size: 128 MB	Max Memory Used: 30 MB	
Unknown application error occurred
Read more comments on GitHub >

github_iconTop Results From Across the Web

dacite - PyPI
This module simplifies creation of data classes (PEP 557) from dictionaries. Installation. To install dacite, simply use pip (or pipenv):
Read more >
dataclasses — Data Classes — Python 3.11.1 documentation
The dataclass() decorator examines the class to find field s. A field is defined as a class variable that has a type annotation....
Read more >
Python dataclass from a nested dict - Stack Overflow
I'm the author of dacite - the tool that simplifies creation of data classes from dictionaries. This library has only one function from_dict ......
Read more >
Data Classes in Python 3.7+ (Guide)
Data classes are one of the new features of Python 3.7. With data classes you do not have to write boilerplate code to...
Read more >
dataclass to json python | The AI Search Engine You Control
You should be able to pass default argument to json.dumps , which will be called whenever the encoder finds an object that it...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found