Skip to content

Conversation

@tannguyencse19
Copy link
Contributor

Summary

Add a static type name lookup variant that skips class-scope flow entries whose value style is FlowStyle::FunctionDef.
Route lookups performed under Usage::StaticTypeInformation to this static type lookup path, leaving all other usages unchanged.

Fixes #1697

Test Plan

cargo test -p pyrefly test_overload_method_name_matches_class

@meta-cla meta-cla bot added the cla signed label Jan 2, 2026
@kinto0 kinto0 requested a review from rchen152 January 5, 2026 18:15
@rchen152 rchen152 self-assigned this Jan 5, 2026
&& is_class
&& flow_info
.value()
.is_some_and(|value| matches!(value.style, FlowStyle::FunctionDef(..)))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't quite right. If a name is shadowed by a function definition, a type checker should error if it is used as a type annotation: https://github.com/python/typing/blob/211b0cb5470e856f6093f7c3d688295f72f78bb6/conformance/tests/annotations_forward_refs.py#L89. We should only skip @overload-decorated signatures.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rchen152 I push a new commit to address this: 55189db . Please review. Thanks

@github-actions

This comment has been minimized.

@github-actions
Copy link

Diff from mypy_primer, showing the effect of this PR on open source code:

pandas (https://github.com/pandas-dev/pandas)
- ::error file=pandas/core/indexing.py,line=1470,col=9,endLine=1470,endColumn=28,title=Pyrefly bad-override::Class member `_LocIndexer._convert_to_indexer` overrides parent class `_LocationIndexer` in an inconsistent manner%0A  `_LocIndexer._convert_to_indexer` has type `BoundMethod[_LocIndexer, (self: _LocIndexer, key: Unknown, axis: int) -> ndarray[tuple[Any, ...], dtype[signedinteger[_NBitIntP]]] | ndarray[tuple[Any, ...], dtype[Any]] | dict[str, int | integer[Any]] | dict[str, tuple[Unknown, ...]] | dict[str, Unknown] | Unknown]`, which is not assignable to `BoundMethod[_LocIndexer, (self: _LocIndexer, key: Unknown, axis: int) -> Never]`, the type of `_LocationIndexer._convert_to_indexer`
+ ::error file=pandas/core/indexing.py,line=1470,col=9,endLine=1470,endColumn=28,title=Pyrefly bad-override::Class member `_LocIndexer._convert_to_indexer` overrides parent class `_LocationIndexer` in an inconsistent manner%0A  `_LocIndexer._convert_to_indexer` has type `BoundMethod[_LocIndexer, (self: _LocIndexer, key: Unknown, axis: int) -> int | ndarray[tuple[int], dtype[Any]] | ndarray[tuple[Any, ...], dtype[signedinteger[_NBitIntP]]] | ndarray[tuple[Any, ...], dtype[Any]] | slice[int, int, Any] | slice[Any, Any, Any] | dict[str, int | integer[Any]] | dict[str, tuple[Unknown, ...]] | dict[str, Unknown] | Unknown]`, which is not assignable to `BoundMethod[_LocIndexer, (self: _LocIndexer, key: Unknown, axis: int) -> Never]`, the type of `_LocationIndexer._convert_to_indexer`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Pyrefly gets confused if a class has the same name as an overloaded method

2 participants