fix assert_type with metaclasses #3228#3243
Open
asukaminato0721 wants to merge 1 commit intofacebook:mainfrom
Open
fix assert_type with metaclasses #3228#3243asukaminato0721 wants to merge 1 commit intofacebook:mainfrom
asukaminato0721 wants to merge 1 commit intofacebook:mainfrom
Conversation
|
According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅ |
There was a problem hiding this comment.
Pull request overview
Fixes typing.assert_type behavior for classes with custom metaclasses so that asserting a class object against its metaclass (e.g., assert_type(A, Meta)) correctly fails, aligning with the typing spec and other type checkers.
Changes:
- Updated
call_assert_typeto explicitly treat “class object is an instance of a non-typemetaclass” as a mismatch forassert_typeequivalence. - Added a regression test covering
assert_typewith a custom metaclass.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| pyrefly/lib/test/simple.rs | Adds a regression testcase ensuring assert_type(A, Meta) produces an error for metaclass instances. |
| pyrefly/lib/alt/special_calls.rs | Adjusts assert_type checking logic to reject metaclass-instance matches (except for builtin type) even if prior equivalence logic allowed them. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Contributor
|
@kinto0 has imported this pull request. If you are a Meta employee, you can view this in D103049155. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #3228
assert_type no longer accepts a class object as exactly equal to its non-type metaclass.
Test Plan
add test