ericvsmith / dataclasses

Apache License 2.0
587 stars 53 forks source link

no attribute _ClassVar #168

Closed shahzebsiddiqui closed 3 years ago

shahzebsiddiqui commented 3 years ago

@ericvsmith rich library depends on dataclasses and i have tested this code on Ubunutu 18.04 container with several python instances including python 3.8.6, system python 3.7.3 which results in same error. Do you have a fix for this or is this library intended to work only with python 3.6

see related issue https://github.com/willmcgugan/rich/issues/1613

spack@f91cb8c2c6ff:~/buildtest$ python3.7 ./bin/buildtest --help
Traceback (most recent call last):
  File "./bin/buildtest", line 14, in <module>
    import buildtest.main
  File "/home/spack/buildtest/buildtest/main.py", line 6, in <module>
    from buildtest.cli import get_parser
  File "/home/spack/buildtest/buildtest/cli/__init__.py", line 8, in <module>
    from buildtest.defaults import BUILD_REPORT
  File "/home/spack/buildtest/buildtest/defaults.py", line 9, in <module>
    from rich.console import Console
  File "/home/spack/buildtest/.packages/rich/console.py", line 55, in <module>
    from .pretty import Pretty, is_expandable
  File "/home/spack/buildtest/.packages/rich/pretty.py", line 316, in <module>
    @dataclass
  File "/home/spack/buildtest/.packages/dataclasses.py", line 958, in dataclass
    return wrap(_cls)
  File "/home/spack/buildtest/.packages/dataclasses.py", line 950, in wrap
    return _process_class(cls, init, repr, eq, order, unsafe_hash, frozen)
  File "/home/spack/buildtest/.packages/dataclasses.py", line 801, in _process_class
    for name, type in cls_annotations.items()]
  File "/home/spack/buildtest/.packages/dataclasses.py", line 801, in <listcomp>
    for name, type in cls_annotations.items()]
  File "/home/spack/buildtest/.packages/dataclasses.py", line 659, in _get_field
    if (_is_classvar(a_type, typing)
  File "/home/spack/buildtest/.packages/dataclasses.py", line 550, in _is_classvar
    return type(a_type) is typing._ClassVar
AttributeError: module 'typing' has no attribute '_ClassVar'
ericvsmith commented 3 years ago

For >= 3.7, just use the version of dataclasses built in to that version of Python. This backport is only designed to work with 3.6.