Skip to content

Conversation

@pablogsal
Copy link
Member

@pablogsal pablogsal commented Dec 6, 2025

⚠️ Dear reviewers, to avoid collapsing the GitHub API with a lot of comments, please open PRs against the base branch with any suggestions or fixes if you are sure are not controversial ⚠️


📚 Documentation preview 📚: https://cpython-previews--142351.org.readthedocs.build/

DinoV and others added 30 commits October 2, 2025 13:22
Highlight lazy imports in the new REPL
@picnixz
Copy link
Member

picnixz commented Dec 6, 2025

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!

@pablogsal pablogsal requested a review from willingc as a code owner December 6, 2025 18:34
pair: name; binding
pair: keyword; from
pair: keyword; as
pair: keyword; lazy
Copy link
Member

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.

Copy link
Member

@picnixz picnixz left a 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));
Copy link
Member

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) {
Copy link
Member

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?

Comment on lines +906 to +907

lazy import json
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
lazy import json
lazy import json
lazy import sys

For 'json' in sys.modules to run.

@pablogsal
Copy link
Member Author

@DinoV @colesbury I haven't paid attention to FT when I updated the draft implementation so please take a special look at that

@pablogsal
Copy link
Member Author

pablogsal commented Dec 6, 2025

@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 ./python -m test test_import.test_lazy_imports -v shows some tsan problems.

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)
Copy link
Member

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# Lazy import syntax (PEP 810) not yet supported by Ruff
# Lazy import syntax (PEP 810) is not yet supported by Ruff

@picnixz
Copy link
Member

picnixz commented Dec 7, 2025

@StanFromIreland assertIn/assertNotIn is addressed in LazyImportsCabal#28

@StanFromIreland
Copy link
Member

Great minds think alike;-) I had opened LazyImportsCabal#27 for it.

@picnixz
Copy link
Member

picnixz commented Dec 7, 2025

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?

@StanFromIreland
Copy link
Member

Do you mind merging my PR in yours?

Done :-)

@AlexWaygood AlexWaygood removed their request for review December 7, 2025 10:47
@picnixz
Copy link
Member

picnixz commented Dec 7, 2025

@pablogsal

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants