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

[Bug]: No ImportError when calling from neuroconv.utils import NWBMetaDataEncoder #1141

Open
2 tasks done
rly opened this issue Nov 14, 2024 · 1 comment · May be fixed by #1142
Open
2 tasks done

[Bug]: No ImportError when calling from neuroconv.utils import NWBMetaDataEncoder #1141

rly opened this issue Nov 14, 2024 · 1 comment · May be fixed by #1142
Labels

Comments

@rly
Copy link
Contributor

rly commented Nov 14, 2024

What happened?

In #1050, some classes such as NWBMetaDataEncoder were renamed _NWBMetaDataEncoder. This breaks code in NWB GUIDE that calls from neuroconv.utils import NWBMetaDataEncoder. Because of the override to __getitem__ in neuroconv/utils/__init__.py (#1033), the line from neuroconv.utils import NWBMetaDataEncoder now fails silently. It should return something like ImportError: cannot import name 'AA' from 'collections' (/Users/rly/mambaforge/envs/test/lib/python3.12/collections/__init__.py) but NWBMetaDataEncoder is set to None without an error. This was confusing to debug.

I suggest changing __getitem__ to end with something like:

if name in globals():
    return globals()[name]
raise ImportError(f"cannot import name '{name}' from 'neuroconv.utils'")

ref: https://peps.python.org/pep-0562/

I am also in favor of making NWBMetaDataEncoder public again since it is used by NWB GUIDE. But if not, I can just copy the code over to NeuroConv...

Steps to Reproduce

from neuroconv.utils import serjsklfjskl

Traceback

No response

Operating System

macOS

Python Executable

Python

Python Version

3.12

Package Versions

neuroconv==0.6.5

Code of Conduct

@h-mayorquin
Copy link
Collaborator

h-mayorquin commented Nov 14, 2024

Let's make it public again. This was an oversight by both Cody and I when we were trying to clean the API docs. I asked him whether someone could be using this and both of us failed to be cautious enough I guess.

Concerning the silent error with import, damn, they always warn about you about hacking dunders and side effects...

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

Successfully merging a pull request may close this issue.

2 participants