[3.15] gh-155194: Fix not raising on non-module import - #155188
Conversation
| assert_python_ok("-c", code) | ||
|
|
||
| def test_non_package_lazily_imported(self): | ||
| """Accessing a nonexistent lazy submodule via parent attr raises AttributeError.""" |
There was a problem hiding this comment.
| """Accessing a nonexistent lazy submodule via parent attr raises AttributeError.""" | |
| """Accessing a nonexistent lazy submodule via parent attr raises ModuleNotFoundError.""" |
| ); | ||
| Py_DECREF(name); | ||
| } | ||
| obj = _PyEval_ImportNameWithImport( |
There was a problem hiding this comment.
Hm, does this change the error for lazy from ... import nonexistent_attr? We don't seem to have explicit tests for what that raises, just the chaining test?
There was a problem hiding this comment.
Nope, that'll be the same. In the from case we're already doing a full import (it's probably not super clear here because that's when lz_attr is not NULL and that's maybe not the best name)
|
Is there a reason there is a 3.15 specific PR here rather than backporting the one targeting main once that's merged? #155189 If so, it might be good to explain that in the PR description. |
Mainly because if we don't fix it in 3.15 I don't think we should ever fix it - it would probably be a breaking change as people would come to depend upon it so I think we should fix it here first or not fix it at all. |
Let's get Hugo's opinion on getting this into the next RC then, and if he's okay with that, apply it to main first. (Doing things in the other direction makes future merges more awkward.) FWIW, I think this is such a clear corner case that I think it would be fine to change in 3.15.1 as well, but I'm not in charge :) |
|
@hugovk ^ |
As initially reported here: https://discuss.python.org/t/sys-lazy-modules-clarification/108385
lazy import math.pihas divergent behavior fromimport math.pi. Currently we allow this to work and just give you themathmodule. Instead we should raiseModuleNotFoundErrorbecausemath.piis not a module.This would be a breaking change in the future so starting w/ fixing it in 3.15 because fixing it only in later versions would probably be bad.