-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Auto-detect src paths for execution environments with autoSearchPaths enabled #11209
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
…hs and add comprehensive tests for autoSearchPaths functionality
|
Diff from mypy_primer, showing the effect of this PR on open source code: sympy (https://github.com/sympy/sympy)
- .../projects/sympy/sympy/solvers/ode/nonhomogeneous.py:467:28 - error: Argument of type "Unknown | None" cannot be assigned to parameter "expr" of type "Expr" in function "make_args"
+ .../projects/sympy/sympy/solvers/ode/nonhomogeneous.py:467:28 - error: Argument of type "Expr | Unknown | None" cannot be assigned to parameter "expr" of type "Expr" in function "make_args"
- Type "Unknown | None" is not assignable to type "Expr"
+ Type "Expr | Unknown | None" is not assignable to type "Expr"
+ Attribute "pop" is unknown (reportAttributeAccessIssue)
+ .../projects/sympy/sympy/solvers/ode/ode.py:610:22 - error: Cannot access attribute "pop" for class "tuple[()]"
+ Attribute "pop" is unknown (reportAttributeAccessIssue)
+ .../projects/sympy/sympy/solvers/ode/ode.py:610:22 - error: Cannot access attribute "pop" for class "tuple[str, ...]"
+ .../projects/sympy/sympy/solvers/ode/ode.py:1516:38 - error: Object of type "None" is not subscriptable (reportOptionalSubscript)
+ .../projects/sympy/sympy/solvers/ode/ode.py:1517:38 - error: Object of type "None" is not subscriptable (reportOptionalSubscript)
+ .../projects/sympy/sympy/solvers/ode/ode.py:1527:9 - error: No overloads for "update" match the provided arguments (reportCallIssue)
+ .../projects/sympy/sympy/solvers/ode/ode.py:1527:12 - error: "update" is not a known attribute of "None" (reportOptionalMemberAccess)
+ .../projects/sympy/sympy/solvers/ode/ode.py:1527:19 - error: Argument of type "Unknown | dict[Unknown, Unknown] | None" cannot be assigned to parameter "m" of type "Iterable[tuple[str, Unknown]]" in function "update"
+ Type "Unknown | dict[Unknown, Unknown] | None" is not assignable to type "Iterable[tuple[str, Unknown]]"
+ "None" is incompatible with protocol "Iterable[tuple[str, Unknown]]"
+ "__iter__" is not present (reportArgumentType)
+ .../projects/sympy/sympy/solvers/ode/ode.py:1534:43 - error: Object of type "None" is not subscriptable (reportOptionalSubscript)
+ .../projects/sympy/sympy/solvers/ode/ode.py:1534:64 - error: Object of type "None" is not subscriptable (reportOptionalSubscript)
+ .../projects/sympy/sympy/solvers/ode/ode.py:1540:9 - error: No overloads for "update" match the provided arguments (reportCallIssue)
+ .../projects/sympy/sympy/solvers/ode/ode.py:1540:12 - error: "update" is not a known attribute of "None" (reportOptionalMemberAccess)
+ .../projects/sympy/sympy/solvers/ode/ode.py:1540:19 - error: Argument of type "Unknown | dict[Unknown, Unknown] | None" cannot be assigned to parameter "m" of type "Iterable[tuple[str, Unknown]]" in function "update"
+ Type "Unknown | dict[Unknown, Unknown] | None" is not assignable to type "Iterable[tuple[str, Unknown]]"
+ "None" is incompatible with protocol "Iterable[tuple[str, Unknown]]"
+ "__iter__" is not present (reportArgumentType)
+ .../projects/sympy/sympy/solvers/ode/ode.py:1547:43 - error: Object of type "None" is not subscriptable (reportOptionalSubscript)
+ .../projects/sympy/sympy/solvers/ode/ode.py:1547:74 - error: Object of type "None" is not subscriptable (reportOptionalSubscript)
+ .../projects/sympy/sympy/solvers/ode/ode.py:1553:9 - error: No overloads for "update" match the provided arguments (reportCallIssue)
+ .../projects/sympy/sympy/solvers/ode/ode.py:1553:12 - error: "update" is not a known attribute of "None" (reportOptionalMemberAccess)
+ .../projects/sympy/sympy/solvers/ode/ode.py:1553:19 - error: Argument of type "Unknown | dict[Unknown, Unknown] | None" cannot be assigned to parameter "m" of type "Iterable[tuple[str, Unknown]]" in function "update"
+ Type "Unknown | dict[Unknown, Unknown] | None" is not assignable to type "Iterable[tuple[str, Unknown]]"
+ "None" is incompatible with protocol "Iterable[tuple[str, Unknown]]"
+ "__iter__" is not present (reportArgumentType)
+ .../projects/sympy/sympy/solvers/ode/ode.py:1560:49 - error: Object of type "None" is not subscriptable (reportOptionalSubscript)
+ .../projects/sympy/sympy/solvers/ode/ode.py:1560:70 - error: Object of type "None" is not subscriptable (reportOptionalSubscript)
- .../projects/sympy/sympy/solvers/ode/ode.py:1691:36 - error: Cannot access attribute "lhs" for class "Expr"
- Attribute "lhs" is unknown (reportAttributeAccessIssue)
- .../projects/sympy/sympy/solvers/ode/ode.py:1691:55 - error: Cannot access attribute "rhs" for class "Expr"
- Attribute "rhs" is unknown (reportAttributeAccessIssue)
- .../projects/sympy/sympy/solvers/ode/ode.py:1692:36 - error: Cannot access attribute "lhs" for class "Expr"
- Attribute "lhs" is unknown (reportAttributeAccessIssue)
- .../projects/sympy/sympy/solvers/ode/ode.py:1693:17 - error: No overloads for "__setitem__" match the provided arguments (reportCallIssue)
- .../projects/sympy/sympy/solvers/ode/ode.py:1693:17 - error: Argument of type "Equality | BooleanFalse | BooleanTrue | Unknown | Expr" cannot be assigned to parameter "value" of type "Equality | BooleanFalse | BooleanTrue" in function "__setitem__"
- Type "Equality | BooleanFalse | BooleanTrue | Unknown | Expr" is not assignable to type "Equality | BooleanFalse | BooleanTrue"
- Type "Expr" is not assignable to type "Equality | BooleanFalse | BooleanTrue"
- "Expr" is not assignable to "Equality"
- "Expr" is not assignable to "BooleanFalse"
- "Expr" is not assignable to "BooleanTrue" (reportArgumentType)
+ .../projects/sympy/sympy/solvers/ode/ode.py:3380:7 - error: "update" is not a known attribute of "None" (reportOptionalMemberAccess)
+ .../projects/sympy/sympy/solvers/ode/ode.py:3380:38 - error: Object of type "None" is not subscriptable (reportOptionalSubscript)
+ .../projects/sympy/sympy/solvers/ode/ode.py:3381:7 - error: "update" is not a known attribute of "None" (reportOptionalMemberAccess)
+ .../projects/sympy/sympy/solvers/ode/ode.py:3381:38 - error: Object of type "None" is not subscriptable (reportOptionalSubscript)
+ .../projects/sympy/sympy/solvers/ode/ode.py:3382:14 - error: Object of type "None" is not subscriptable (reportOptionalSubscript)
+ .../projects/sympy/sympy/solvers/ode/ode.py:3383:14 - error: Object of type "None" is not subscriptable (reportOptionalSubscript)
+ .../projects/sympy/sympy/solvers/ode/ode.py:3384:14 - error: Object of type "None" is not subscriptable (reportOptionalSubscript)
+ .../projects/sympy/sympy/solvers/ode/ode.py:3396:50 - error: Object of type "None" is not subscriptable (reportOptionalSubscript)
+ .../projects/sympy/sympy/solvers/ode/ode.py:3397:50 - error: Object of type "None" is not subscriptable (reportOptionalSubscript)
+ .../projects/sympy/sympy/solvers/ode/ode.py:3398:50 - error: Object of type "None" is not subscriptable (reportOptionalSubscript)
+ .../projects/sympy/sympy/solvers/ode/ode.py:3438:5 - error: No overloads for "update" match the provided arguments (reportCallIssue)
+ .../projects/sympy/sympy/solvers/ode/ode.py:3438:7 - error: "update" is not a known attribute of "None" (reportOptionalMemberAccess)
+ .../projects/sympy/sympy/solvers/ode/ode.py:3438:14 - error: Argument of type "Unknown | dict[Unknown, Unknown] | None" cannot be assigned to parameter "m" of type "Iterable[tuple[str, Unknown]]" in function "update"
+ Type "Unknown | dict[Unknown, Unknown] | None" is not assignable to type "Iterable[tuple[str, Unknown]]"
+ "None" is incompatible with protocol "Iterable[tuple[str, Unknown]]"
+ "__iter__" is not present (reportArgumentType)
+ .../projects/sympy/sympy/solvers/ode/ode.py:3439:18 - error: Object of type "None" is not subscriptable (reportOptionalSubscript)
+ .../projects/sympy/sympy/solvers/ode/ode.py:3439:43 - error: Object of type "None" is not subscriptable (reportOptionalSubscript)
+ .../projects/sympy/sympy/solvers/ode/ode.py:3440:9 - error: Object of type "None" is not subscriptable (reportOptionalSubscript)
+ .../projects/sympy/sympy/solvers/ode/ode.py:3440:16 - error: Object of type "None" is not subscriptable (reportOptionalSubscript)
+ .../projects/sympy/sympy/solvers/ode/ode.py:3440:24 - error: Object of type "None" is not subscriptable (reportOptionalSubscript)
+ .../projects/sympy/sympy/solvers/ode/ode.py:3440:31 - error: Object of type "None" is not subscriptable (reportOptionalSubscript)
+ .../projects/sympy/sympy/solvers/ode/ode.py:3441:9 - error: Object of type "None" is not subscriptable (reportOptionalSubscript)
+ .../projects/sympy/sympy/solvers/ode/ode.py:3441:15 - error: Object of type "None" is not subscriptable (reportOptionalSubscript)
+ .../projects/sympy/sympy/solvers/ode/ode.py:3441:23 - error: Object of type "None" is not subscriptable (reportOptionalSubscript)
+ .../projects/sympy/sympy/solvers/ode/ode.py:3441:30 - error: Object of type "None" is not subscriptable (reportOptionalSubscript)
+ .../projects/sympy/sympy/solvers/ode/ode.py:3442:7 - error: "update" is not a known attribute of "None" (reportOptionalMemberAccess)
+ .../projects/sympy/sympy/solvers/ode/ode.py:3442:46 - error: Object of type "None" is not subscriptable (reportOptionalSubscript)
+ .../projects/sympy/sympy/solvers/ode/ode.py:3442:54 - error: Object of type "None" is not subscriptable (reportOptionalSubscript)
+ .../projects/sympy/sympy/solvers/ode/ode.py:3443:9 - error: Object of type "None" is not subscriptable (reportOptionalSubscript)
+ .../projects/sympy/sympy/solvers/ode/ode.py:3443:19 - error: Object of type "None" is not subscriptable (reportOptionalSubscript)
+ .../projects/sympy/sympy/solvers/ode/ode.py:3443:29 - error: Object of type "None" is not subscriptable (reportOptionalSubscript)
+ .../projects/sympy/sympy/solvers/ode/ode.py:3444:10 - error: Object of type "None" is not subscriptable (reportOptionalSubscript)
... (truncated 98 lines) ...
|
|
This change doesn't make sense to me. The |
|
alright, I will close the issue then. thank you! |
Description
Fixes an issue where
python.analysis.autoSearchPathsonly auto-detected and added<project-root>/srcto extraPaths, but did not apply the same logic to execution environment roots. When a project has multiple execution environments with their ownsrcdirectories (e.g.,env1/src,env2/src), these were not being automatically added to the search paths.This change extends the auto-detection behavior to also check for and add
<executionEnvironment.root>/srcdirectories when:autoSearchPathsis enabledextraPathssrcdirectory exists and is not a package (no__init__.py)This mirrors the existing behavior for project-root
srcdirectories and helps maintain consistent import resolution across multi-environment projects.How you figured out what to do
The investigation focused on two key areas:
configOptions.ts: Located the existing auto-detection logic ininitializeFromJson()that handles project-rootsrcpaths. The logic checks forautoSearchPaths, verifies thesrcdirectory exists, and ensures it's not a package before adding it.setupExecutionEnvironments(): Extended this method to apply similar auto-detection logic to each execution environment's root directory.The implementation needed to respect the suppression mechanism where explicitly setting
extraPathsto an empty array (either at config or environment level) prevents auto-detection.Implementation
Key changes:
Refactored auto-detection logic into a reusable static method
_tryGetAutoDetectedSrcExtraPath()that:srcsubdirectorysrcexists and is not a packageundefinedotherwiseExtended
setupExecutionEnvironments()to:fs(FileSystem) andautoSearchPathsparametersextraPathswas specified at the config levelextraPathswere specifiedUpdated call sites in
service.tsandtestState.tsto pass the required parametersTesting
Added comprehensive test coverage in
config.test.tswith the following scenarios:AutoSearchPathsOnWithExecutionEnvironmentRoots: Verifies auto-detection addssrcpaths for multiple execution environmentsAutoSearchPathsOnWithExecutionEnvironmentRootsConfigExtraPathsEmptySuppresses: Ensures emptyextraPathsat config level suppresses auto-detectionAutoSearchPathsOnWithExecutionEnvironmentRootsEnvExtraPathsEmptySuppresses: Ensures emptyextraPathsat environment level suppresses auto-detectionAutoSearchPathsOnWithExecutionEnvironmentRootsSrcIsPkgSuppresses: Verifiessrcdirectories containing__init__.pyare not addedAutoSearchPathsOnWithExecutionEnvironmentRootDotDedupes: Ensures no duplicates when execution environment root is "." (project root)Test fixtures include sample projects with various configurations to cover all edge cases.
Addresses
Addresses microsoft/pylance-release#7378