-
-
Notifications
You must be signed in to change notification settings - Fork 3k
[mypyc] Don't coerce types checked with isinstance (#811) #10245
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
0b420f6
[mypyc] Don't coerce types checked with isinstance (#811)
sinback 9731732
[mypyc] fix control flow bug in creation of isinstance IR
sinback 423f739
[mypyc] simplify IRs in irbuild-isinstance.test
sinback dded3e2
[mypyc] add runtime test-case for isinstance IR
sinback a72bdd3
[mypyc] fix typo in comment
sinback 1d01abc
[mypyc] fix isinstance test
sinback 385bd6a
[mypyc] update comment in isinstance tests
sinback File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
[case testIsinstanceInt] | ||
def is_int(value: object) -> bool: | ||
return isinstance(value, int) | ||
|
||
[out] | ||
def is_int(value): | ||
value, r0 :: object | ||
r1 :: int32 | ||
r2 :: bit | ||
r3 :: bool | ||
L0: | ||
r0 = load_address PyLong_Type | ||
r1 = PyObject_IsInstance(value, r0) | ||
r2 = r1 >= 0 :: signed | ||
r3 = truncate r1: int32 to builtins.bool | ||
return r3 | ||
|
||
[case testIsinstanceNotBool1] | ||
def is_not_bool(value: object) -> bool: | ||
return not isinstance(value, bool) | ||
JukkaL marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
[out] | ||
def is_not_bool(value): | ||
value, r0 :: object | ||
r1 :: str | ||
r2 :: object | ||
r3 :: int32 | ||
r4 :: bit | ||
r5, r6 :: bool | ||
L0: | ||
r0 = builtins :: module | ||
r1 = 'bool' | ||
r2 = CPyObject_GetAttr(r0, r1) | ||
r3 = PyObject_IsInstance(value, r2) | ||
r4 = r3 >= 0 :: signed | ||
r5 = truncate r3: int32 to builtins.bool | ||
r6 = r5 ^ 1 | ||
return r6 | ||
|
||
[case testIsinstanceIntAndNotBool] | ||
# This test is to ensure that 'value' doesn't get coerced to int when we are | ||
# checking if it's a bool, since an int can never be an instance of a bool | ||
def is_not_bool_and_is_int(value: object) -> bool: | ||
return isinstance(value, int) and not isinstance(value, bool) | ||
|
||
[out] | ||
def is_not_bool_and_is_int(value): | ||
value, r0 :: object | ||
r1 :: int32 | ||
r2 :: bit | ||
r3, r4 :: bool | ||
r5 :: object | ||
r6 :: str | ||
r7 :: object | ||
r8 :: int32 | ||
r9 :: bit | ||
r10, r11 :: bool | ||
L0: | ||
r0 = load_address PyLong_Type | ||
r1 = PyObject_IsInstance(value, r0) | ||
r2 = r1 >= 0 :: signed | ||
r3 = truncate r1: int32 to builtins.bool | ||
if r3 goto L2 else goto L1 :: bool | ||
L1: | ||
r4 = r3 | ||
goto L3 | ||
L2: | ||
r5 = builtins :: module | ||
r6 = 'bool' | ||
r7 = CPyObject_GetAttr(r5, r6) | ||
r8 = PyObject_IsInstance(value, r7) | ||
r9 = r8 >= 0 :: signed | ||
r10 = truncate r8: int32 to builtins.bool | ||
r11 = r10 ^ 1 | ||
r4 = r11 | ||
L3: | ||
return r4 |
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
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
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.
Uh oh!
There was an error while loading. Please reload this page.