dandi / dandi-schema

Schemata for DANDI archive project
Apache License 2.0
7 stars 10 forks source link

Test failure for `=dandischema-0.9.1` (`ImportError: cannot import name 'MappingProxyType' from partially initialized module 'types'`) #226

Closed TheChymera closed 9 months ago

TheChymera commented 9 months ago

Full build/test log here → https://ppb.chymera.eu/0e8952.html

Any idea what could be causing this? I don't think there's any circular import, at least none I could find.

Full traceback (also included in the above log):

python3.11 -m pytest -vv -ra -l -Wdefault --color=yes -o console_output_style=count -o tmp_path_retention_count=0 -o tmp_path_retention_policy=failed -p no:cov -p no:flake8 -p no:flakes -p no:pylint -p no:markdown -p no:sugar -p no:xvfb -p no:pytest-describe -p no:plus -p no:tavern -p no:salt-factories tests
Could not import runpy module
Traceback (most recent call last):
  File "<frozen runpy>", line 15, in <module>
  File "<frozen importlib.util>", line 14, in <module>
  File "/usr/lib/python3.11/contextlib.py", line 7, in <module>
    from functools import wraps
  File "/usr/lib/python3.11/functools.py", line 22, in <module>
    from types import GenericAlias
  File "/var/tmp/portage/dev-python/dandi-schema-0.9.1/work/dandi-schema-0.9.1/dandischema/types.py", line 4, in <module>
    from typing import Type
  File "/usr/lib/python3.11/typing.py", line 29, in <module>
    import re as stdlib_re  # Avoid confusion with the re we export.
    ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/re/__init__.py", line 124, in <module>
    import enum
  File "/usr/lib/python3.11/enum.py", line 3, in <module>
    from types import MappingProxyType, DynamicClassAttribute
ImportError: cannot import name 'MappingProxyType' from partially initialized module 'types' (most likely due to a circular import) (/var/tmp/portage/dev-python/dandi-schema-0.9.1/work/dandi-schema-0.9.1/dandischema/types.py)
yarikoptic commented 9 months ago

never saw it and I do not see circularity here since there is no types in the stack (besides dandischema/types). @jwodder did you see anything like that?

jwodder commented 9 months ago

@TheChymera What were the current directory and value of sys.path when you ran the tests? It looks like the dandischema/ source directory (rather than the directory containing it) was on sys.path, leading to dandischema/types.py overriding Python's builtin types module.

TheChymera commented 9 months ago

@jwodder you're right, I was running the tests from the wrong directory. The types thing really confused me, probably because the circular import suggestion sent me down the wrong path. Thank you in any case. Any interest perhaps in renaming it, or is it standard for package types to be called types as opposed to package_types or builtin_types?

jwodder commented 9 months ago

@TheChymera There's no need to rename it, as it's only a problem if the wrong directory is in sys.path.

TheChymera commented 9 months ago

ok, then the issue is resolved. Thanks.