Skip to content

[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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

p-sawicki
Copy link
Collaborator

Follow-up to #19416 adding primitives for isinstance(obj, type) where type is built-in.

Copy link
Collaborator

@JukkaL JukkaL left a 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",
Copy link
Collaborator

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)
Copy link
Collaborator

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 of 1
  • 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)
Copy link

@peturingi peturingi Jul 14, 2025

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy