Skip to content
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

Changed the type of __path__ from Iterable[str] to `MutableSequen… #10062

Merged
merged 1 commit into from
Mar 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/pyright-internal/src/analyzer/binder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ export class Binder extends ParseTreeWalker {
this._addImplicitSymbolToCurrentScope('__loader__', node, 'Any');
this._addImplicitSymbolToCurrentScope('__package__', node, 'str | None');
this._addImplicitSymbolToCurrentScope('__spec__', node, 'Any');
this._addImplicitSymbolToCurrentScope('__path__', node, 'Iterable[str]');
this._addImplicitSymbolToCurrentScope('__path__', node, 'MutableSequence[str]');
this._addImplicitSymbolToCurrentScope('__file__', node, 'str');
this._addImplicitSymbolToCurrentScope('__cached__', node, 'str');
this._addImplicitSymbolToCurrentScope('__dict__', node, 'Dict[str, Any]');
Expand Down
9 changes: 8 additions & 1 deletion packages/pyright-internal/src/analyzer/declaration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,14 @@ export const enum DeclarationType {
Alias,
}

export type IntrinsicType = 'Any' | 'str' | 'str | None' | 'int' | 'Iterable[str]' | 'type[self]' | 'Dict[str, Any]';
export type IntrinsicType =
| 'Any'
| 'str'
| 'str | None'
| 'int'
| 'MutableSequence[str]'
| 'type[self]'
| 'Dict[str, Any]';

export interface DeclarationBase {
// Category of this symbol (function, variable, etc.).
Expand Down
8 changes: 4 additions & 4 deletions packages/pyright-internal/src/analyzer/typeEvaluator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22164,11 +22164,11 @@ export function createTypeEvaluator(
return { type: intType };
}

if (declaration.intrinsicType === 'Iterable[str]') {
const iterableType = getBuiltInType(declaration.node, 'Iterable');
if (isInstantiableClass(iterableType)) {
if (declaration.intrinsicType === 'MutableSequence[str]') {
const sequenceType = getBuiltInType(declaration.node, 'MutableSequence');
if (isInstantiableClass(sequenceType)) {
return {
type: ClassType.cloneAsInstance(ClassType.specialize(iterableType, [strType])),
type: ClassType.cloneAsInstance(ClassType.specialize(sequenceType, [strType])),
};
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/pyright-internal/src/tests/samples/import1.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# This sample tests the type analyzer's handling of the built-in
# __import__ function.

reveal_type(__path__, expected_text="Iterable[str]")
reveal_type(__path__, expected_text="MutableSequence[str]")

# This should not generate a type error.
__path__ = __import__("pkgutil").extend_path(__path__, __name__)
2 changes: 1 addition & 1 deletion packages/pyright-internal/src/tests/samples/module3.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
reveal_type(datetime.__loader__, expected_text="Any")
reveal_type(datetime.__package__, expected_text="str | None")
reveal_type(datetime.__spec__, expected_text="Any")
reveal_type(datetime.__path__, expected_text="Iterable[str]")
reveal_type(datetime.__path__, expected_text="MutableSequence[str]")
reveal_type(datetime.__file__, expected_text="str")
reveal_type(datetime.__cached__, expected_text="str")
reveal_type(datetime.__dict__, expected_text="dict[str, Any]")
Expand Down
Loading