-
Notifications
You must be signed in to change notification settings - Fork 1.6k
[red-knot] Simplify visibility constraint handling for *-import definitions
#17486
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
Conversation
|
c760611 to
e662997
Compare
|
neutral on codspeed: https://codspeed.io/astral-sh/ruff/branches/alex%2Foptimize-star-imports |
dcreager
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 doubt this provides a meaningful speedup in many cases, since it's just very uncommon to use a
*-import definition to override a pre-existing definition. I'm filing the PR anyway, however, as it ends up simplifying the code inbuilder.rsa fair bit. We no longer have to branch on whether the symbol is newly added or not; we can just do the same thing in both cases.
Simplified code with no performance regression counts as a win to me!
|
|
||
| #[derive(Clone, Debug, PartialEq, Eq)] | ||
| pub(super) struct SymbolState { | ||
| pub(in crate::semantic_index) struct SymbolState { |
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 do have pub(grandparent) as a possibility, I did not know that! I still worry that we might be over-thinking visibility within this crate, but that is not at all a blocker for this PR.
29b64a2 to
53afc0a
Compare
* main: Update pre-commit dependencies (#17506) [red-knot] Simplify visibility constraint handling for `*`-import definitions (#17486) [red-knot] Detect (some) invalid protocols (#17488) [red-knot] Correctly identify protocol classes (#17487) Update dependency ruff to v0.11.6 (#17516) Update Rust crate shellexpand to v3.1.1 (#17512) Update Rust crate proc-macro2 to v1.0.95 (#17510) Update Rust crate rand to v0.9.1 (#17511) Update Rust crate libc to v0.2.172 (#17509) Update Rust crate jiff to v0.2.9 (#17508) Update Rust crate clap to v4.5.37 (#17507) Update astral-sh/setup-uv action to v5.4.2 (#17504) Update taiki-e/install-action digest to 09dc018 (#17503) [red-knot] infer attribute assignments bound in comprehensions (#17396) [red-knot] simplify gradually-equivalent types out of unions and intersections (#17467) [red-knot] pull primer projects to run from file (#17473)
* main: (37 commits) [red-knot] Add list of failing/slow ecosystem projects (#17474) [red-knot] mypy_primer: extend ecosystem checks (#17544) [red-knot] Move `InstanceType` to its own submodule (#17525) [red-knot] mypy_primer: capture backtraces (#17543) [red-knot] mypy_primer: Use upstream repo (#17500) [red-knot] `typing.dataclass_transform` (#17445) Update dependency react-resizable-panels to v2.1.8 (#17513) Update dependency smol-toml to v1.3.3 (#17505) Update dependency uuid to v11.1.0 (#17517) Update actions/setup-node action to v4.4.0 (#17514) [red-knot] Fix variable name (#17532) [red-knot] Add basic subtyping between class literal and callable (#17469) [`pyupgrade`] Add fix safety section to docs (`UP030`) (#17443) [`perflint`] Allow list function calls to be replaced with a comprehension (`PERF401`) (#17519) Update pre-commit dependencies (#17506) [red-knot] Simplify visibility constraint handling for `*`-import definitions (#17486) [red-knot] Detect (some) invalid protocols (#17488) [red-knot] Correctly identify protocol classes (#17487) Update dependency ruff to v0.11.6 (#17516) Update Rust crate shellexpand to v3.1.1 (#17512) ...
Summary
A bank-holiday-weekend refactoring PR 😆
I was curious about just how invasive the change would be if I took action on my comment in #17375 (comment) (optimising the slow path for
*imports as well as the fast path). It turns out, not very invasive at all! Only one new API has to be added to the use-def map, and it's a fairly innocuous API in my opinion.I doubt this provides a meaningful speedup in many cases, since it's just very uncommon to use a
*-import definition to override a pre-existing definition. I'm filing the PR anyway, however, as it ends up simplifying the code inbuilder.rsa fair bit. We no longer have to branch on whether the symbol is newly added or not; we can just do the same thing in both cases.Test Plan
cargo test -p red_knot_python_semantic