-
-
Notifications
You must be signed in to change notification settings - Fork 33.6k
gh-142349: Implement PEP 810 #142351
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
base: main
Are you sure you want to change the base?
gh-142349: Implement PEP 810 #142351
Conversation
…s on bad usage of lazy
Highlight lazy imports in the new REPL
|
I'll be doing small reviews because I'm not on my dev session and it takes too long for creating a PR :') I promise I won't be too nitpicky! |
| pair: name; binding | ||
| pair: keyword; from | ||
| pair: keyword; as | ||
| pair: keyword; lazy |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest you move this to the below section on lazy specifically.
picnixz
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll review more tomorrow when I'm on my dev session, it'll be easier. But here are a few comments and questions about import.c
| PyObject *old = _Py_atomic_exchange_ptr(&LAZY_IMPORTS_FILTER(interp), Py_XNewRef(filter)); | ||
| Py_XDECREF(old); | ||
| #else | ||
| Py_XSETREF(LAZY_IMPORTS_FILTER(interp), Py_XNewRef(filter)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This makes me wondeer whether we couldn't have a FT helper for this. It's probably not the only place that will need this in the future.
|
|
||
| // Add the module name to sys.lazy_modules set (PEP 810) | ||
| PyObject *lazy_modules_set = interp->imports.lazy_modules_set; | ||
| if (lazy_modules_set != NULL) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When is it possible to have lazy_modules_set NULL?
|
|
||
| lazy import json |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| lazy import json | |
| lazy import json | |
| lazy import sys |
For 'json' in sys.modules to run.
|
@DinoV @colesbury I haven't paid attention to FT when I updated the draft implementation so please take a special look at that |
In particular I think I got them in 470b9e4 but not sure if that's the best way to fix this. |
| def test_global_off(self): | ||
| """Mode 'none' should disable lazy imports entirely.""" | ||
| import test.test_import.data.lazy_imports.global_off | ||
| self.assertTrue("test.test_import.data.lazy_imports.basic2" in sys.modules) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can use assertIn instead, a suggestion that applies for all cases: LazyImportsCabal#27
| # New grammar constructions may not yet be recognized by Ruff, | ||
| # and tests re-use the same names as only the grammar is being checked. | ||
| "test_grammar.py", | ||
| # Lazy import syntax (PEP 810) not yet supported by Ruff |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| # Lazy import syntax (PEP 810) not yet supported by Ruff | |
| # Lazy import syntax (PEP 810) is not yet supported by Ruff |
|
@StanFromIreland assertIn/assertNotIn is addressed in LazyImportsCabal#28 |
|
Great minds think alike;-) I had opened LazyImportsCabal#27 for it. |
|
There was also an hasattr check thatq we could change and I also changed import order to make them alphabetically sorted. Do you mind merging my PR in yours? |
Done :-) |
There are other places where PEP-7 is not applied but I won't bother changing those places if I'm not changing the effective code as well. Ideally, I should add tests for checking that my UAFs fixes are correct but we can do it once they're reviewed and merged. |
📚 Documentation preview 📚: https://cpython-previews--142351.org.readthedocs.build/