Skip to content

Commit

Permalink
Fixed bug that results in a false positive when resolving a multi-par…
Browse files Browse the repository at this point in the history
…t import target that involves a circular dependency. This addresses #9267. (#9268)
  • Loading branch information
erictraut authored Oct 20, 2024
1 parent 80d24c8 commit 7c7703a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
6 changes: 1 addition & 5 deletions packages/pyright-internal/src/analyzer/declarationUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -401,11 +401,7 @@ export function resolveAliasDeclaration(
// imports a submodule using itself as the import target. For example, if
// the module is foo, and the foo.__init__.py file contains the statement
// "from foo import bar", we want to import the foo/bar.py submodule.
if (
curDeclaration.uri.equals(declaration.uri) &&
curDeclaration.type === DeclarationType.Alias &&
curDeclaration.submoduleFallback
) {
if (curDeclaration.type === DeclarationType.Alias && curDeclaration.submoduleFallback) {
return resolveAliasDeclaration(importLookup, curDeclaration.submoduleFallback, options);
}
return {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/// <reference path="typings/fourslash.d.ts" />

// @filename: pkg/__init__.py
//// from . import sub1
//// from .sub2 import *

// @filename: pkg/sub1.py
//// a = 1
//// b = 2

// @filename: pkg/sub2.py
//// from . import sub1
//// from .sub1 import a

// @filename: test.py
//// import pkg.sub1
//// pkg.sub1.[|/*marker*/b|]()

// @ts-ignore
helper.verifyHover('markdown', {
marker: '```python\n(variable) b: int\n```',
});

0 comments on commit 7c7703a

Please sign in to comment.