Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Import breaks on >=Python3.7 because of dataclasses package #630

Closed
sransara opened this issue Mar 18, 2023 · 1 comment
Closed

Import breaks on >=Python3.7 because of dataclasses package #630

sransara opened this issue Mar 18, 2023 · 1 comment

Comments

@sransara
Copy link

sransara commented Mar 18, 2023

When the pip packages are higher priority than stdlib packages, importing ontobio fails because the dataclasses package is broken >=Python 3.7. ontobio depends on dataclasses package directly.

Suggested fixes here is to change the dataclasses requirement to only install for <python3.7 with: (PR with fix: #631)

dataclasses>='0.7';python_version<'3.7'

To replicate the issue:

❯ docker run --rm -it python:3.7 sh -c 'pip install ontobio && python'
[... docker & pip installer output removed for brevity ...]
Python 3.7.16 (default, Mar 14 2023, 03:47:39) 
[GCC 10.2.1 20210110] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.path
['', '/usr/local/lib/python37.zip', '/usr/local/lib/python3.7', '/usr/local/lib/python3.7/lib-dynload', '/usr/local/lib/python3.7/site-packages']
>>> # Simulate environment where pip installed site-packages comes before stdlib packages
>>> sys.path.reverse()
>>> sys.path
['/usr/local/lib/python3.7/site-packages', '/usr/local/lib/python3.7/lib-dynload', '/usr/local/lib/python3.7', '/usr/local/lib/python37.zip', '']
>>>
>>> import ontobio
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.7/site-packages/ontobio/__init__.py", line 6, in <module>
    from .ontol_factory import OntologyFactory
  File "/usr/local/lib/python3.7/site-packages/ontobio/ontol_factory.py", line 7, in <module>
    import ontobio.obograph_util as obograph_util
  File "/usr/local/lib/python3.7/site-packages/ontobio/obograph_util.py", line 8, in <module>
    from ontobio.golr.golr_associations import search_associations
  File "/usr/local/lib/python3.7/site-packages/ontobio/golr/golr_associations.py", line 13, in <module>
    from ontobio.golr.golr_query import *
  File "/usr/local/lib/python3.7/site-packages/ontobio/golr/golr_query.py", line 48, in <module>
    from ontobio.model.GolrResults import SearchResults, AutocompleteResult, Highlight
  File "/usr/local/lib/python3.7/site-packages/ontobio/model/GolrResults.py", line 5, in <module>
    @dataclass(frozen=True)
  File "/usr/local/lib/python3.7/site-packages/dataclasses.py", line 950, in wrap
    return _process_class(cls, init, repr, eq, order, unsafe_hash, frozen)
  File "/usr/local/lib/python3.7/site-packages/dataclasses.py", line 801, in _process_class
    for name, type in cls_annotations.items()]
  File "/usr/local/lib/python3.7/site-packages/dataclasses.py", line 801, in <listcomp>
    for name, type in cls_annotations.items()]
  File "/usr/local/lib/python3.7/site-packages/dataclasses.py", line 659, in _get_field
    if (_is_classvar(a_type, typing)
  File "/usr/local/lib/python3.7/site-packages/dataclasses.py", line 550, in _is_classvar
    return type(a_type) is typing._ClassVar
AttributeError: module 'typing' has no attribute '_ClassVar'
@sransara
Copy link
Author

No longer necessary since: 34f4300 where required Python version has been upgraded to > Python 3.9

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant