-
-
Notifications
You must be signed in to change notification settings - Fork 3k
[mypyc] Add primitives for isinstance of built-in types #19435
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
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good overall, just a few comments.
name="builtins.isinstance", | ||
arg_types=[object_rprimitive], | ||
return_type=bit_rprimitive, | ||
c_function_name="PyFloat_Check", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should use CPyFloat_Check
, since we always implicitly accept integers as compatible with float
.
|
||
[case testIsInstance] | ||
def test_built_in() -> None: | ||
assert isinstance(True, bool) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Optional nit: It's slightly better to use e.g. something like b: Any = True
followed by isinstance(b, bool)
, since a future version of mypyc might otherwise optimize the whole check away (here and elsewhere). It's not a big deal, but in the future it's often better to use expressions like these instead of bool
/int
/str
/bytes
literals in run tests:
int() + 1
instead of1
str() + "x"
instead of"x"
Container types are generally fine, since we are less likely to optimize them away. It's a loose convention that values with Any
types and no-argument constructors for primitives such as int()
are not optimized much.
@@ -64,6 +64,24 @@ | |||
error_kind=ERR_MAGIC, | |||
) | |||
|
|||
# isinstance(obj, set) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove or be more explicit. Code as comment looks like accidental committed leftovers from a debugging session.
Follow-up to #19416 adding primitives for
isinstance(obj, type)
where type is built-in.