Skip to content

fix: Pyrefly gets confused if a class has the same name as an overloaded method - #1983

Closed
tannguyencse19 wants to merge 3 commits into
facebook:mainfrom
tannguyencse19:fix/issue-1697-final
Closed

tannguyencse19 wants to merge 3 commits into
facebook:mainfrom
tannguyencse19:fix/issue-1697-final

Conversation

@tannguyencse19

Copy link
Copy Markdown
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
Comment thread pyrefly/lib/binding/scope.rs Outdated
&& is_class
&& flow_info
.value()
.is_some_and(|value| matches!(value.style, FlowStyle::FunctionDef(..)))

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown

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`

@rchen152 rchen152 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thank you!

@meta-codesync

meta-codesync Bot commented Jan 14, 2026

Copy link
Copy Markdown
Contributor

@rchen152 has imported this pull request. If you are a Meta employee, you can view this in D90643568.

@stroxler stroxler left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Review automatically exported from Phabricator review in Meta.

@meta-codesync

meta-codesync Bot commented Jan 14, 2026

Copy link
Copy Markdown
Contributor

@rchen152 merged this pull request in d3360dc.

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

4 participants