Resolve classes and functions relative to script name#10965
Resolve classes and functions relative to script name#10965charliermarsh merged 3 commits intomainfrom
Conversation
| Some(resolved) | ||
|
|
||
| // If we have a fully-qualified path for the module, use it. | ||
| if let Some(path) = self.module.path() { |
There was a problem hiding this comment.
I consider changing Module to return &[script_name] in the script case, but the path is typically used for resolving relative imports, and I'm not sure it makes as much sense for us to resolve relative imports relative to the script name given that it's definitionally a standalone script.
|
Not worth unit test coverage? |
fe43292 to
7cb7348
Compare
|
Will try. |
7cb7348 to
819b7d8
Compare
|
| code | total | + violation | - violation | + fix | - fix |
|---|---|---|---|---|---|
| PYI001 | 1 | 1 | 0 | 0 | 0 |
Linter (preview)
ℹ️ ecosystem check detected linter changes. (+1 -0 violations, +0 -0 fixes in 1 projects; 43 projects unchanged)
python/typeshed (+1 -0 violations, +0 -0 fixes)
ruff check --no-cache --exit-zero --ignore RUF9 --output-format concise --preview --select E,F,FA,I,PYI,RUF,UP,W
+ stdlib/typing.pyi:330:10: PYI001 Name of private `TypeVar` must start with `_`
Changes by rule (1 rules affected)
| code | total | + violation | - violation | + fix | - fix |
|---|---|---|---|---|---|
| PYI001 | 1 | 1 | 0 | 0 | 0 |
819b7d8 to
6f57dd9
Compare
|
I think those typeshed changes are arguably good but I'll let @AlexWaygood review. |
The The builtins hit seems like a false positive though — the existing annotation looks correct there. Something now isn't being inferred as being a builtin symbol because we're actually in builtins.pyi itself? |
Oh! I missed that the error was going away rather than being introduced! The typeshed hits both look like clear improvements, then 😃 |
80fa654 to
23565b5
Compare
CodSpeed Performance ReportMerging #10965 will not alter performanceComparing Summary
|
23565b5 to
80dc306
Compare
80dc306 to
86d521e
Compare
86d521e to
835052c
Compare
d459e4a to
eff605f
Compare
|
Thank you all for handling this so quickly!! |
|
No problem, sorry that it took a few days to merge -- I had to debug a performance regression 😂 |
Summary
If the user is analyzing a script (i.e., we have no module path), it seems reasonable to use the script name when trying to identify paths to objects defined within the script.
Closes #10960.
Test Plan
Ran:
check --isolated --select=B008 \ --config 'lint.flake8-bugbear.extend-immutable-calls=["test.A"]' \ test.pyOn: