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

Regression in 0.19.0 #232

Closed
sobolevn opened this issue Apr 1, 2024 · 4 comments
Closed

Regression in 0.19.0 #232

sobolevn opened this issue Apr 1, 2024 · 4 comments
Labels
bug Something isn't working

Comments

@sobolevn
Copy link

sobolevn commented Apr 1, 2024

Hi 👋

After upgrading my project from 0.18.0 to 0.19.0 my CI started failing with:

 stats:
  modules:     113
    checked:   94
    excluded:  19
    skipped:   1

  classes:     90
    has slots: 88
    no slots:  2
    n/a:       0
ERROR: Failed to import 'returns.contrib.hypothesis.containers'.
       Due to ImportError("cannot import name 'strategy_from_container' from partially initialized module 'returns.contrib.hypothesis.containers' (most likely due to a circular import) (/home/runner/work/returns/returns/returns/contrib/hypothesis/containers.py)")
Oh no, found some problems!

Afected Python versions: 3.10 and 3.11:

Is it a bug in my project? Or is it a bug in slotscheck?

@ariebovenberg
Copy link
Owner

Thanks for posting the issue. The import mechanism was improved in 0.19, which ironically could surface more important errors. I'll have a look soon.

@sobolevn
Copy link
Author

sobolevn commented Apr 1, 2024

@ariebovenberg
Copy link
Owner

I'm almost sure this issue is only surfacing now because modules are imported in arbitrary order, and that this ordering is changed since 0.19.

A related issue is #178

As to the actual cause, I have a feeling it's either:

  1. Some packages are set up in such a way that submodules need to be imported in particular order. This is a problem for tools like slotscheck which traverse the module in some other way.
  2. slotscheck is doing something wrong in importing submodules. It's suspicious that the problematic module here and in error when (indirectly) importing mypy during package introspection #178 both include the names of other modules (mypy and hypothesis, respectively) and these types of situations often trigger the "partially initialized" ImportError.

For cause nr. 1, these are potential solutions:

  1. slotscheck somehow detects which modules should be imported first, in order to avoid partially initialized dependencies (unfortunately, a quick google didn't yield any easy solutions 😬)
  2. Allow users to specify which modules should be imported before others (a bit combursome, but perhaps the import error can give a hint)

For cause nr. 2, additional study is needed.

Some workarounds to get things working again:

  • in CI configuration, set PYTHONHASHSEED to a fixed value that is known to work
  • if there's nothing to check in the module, exclude it from slotscheck

@ariebovenberg
Copy link
Owner

I've created a tracking issue for the underlying issue (see above). See there for further discussion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants