Skip to content
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

Bug in type inference for Python 3.10 #21671

Closed
damccorm opened this issue Jun 5, 2022 · 6 comments · Fixed by #23587
Closed

Bug in type inference for Python 3.10 #21671

damccorm opened this issue Jun 5, 2022 · 6 comments · Fixed by #23587
Assignees
Labels
bug core done & done Issue has been reviewed after it was closed for verification, followups, etc. P2 python

Comments

@damccorm
Copy link
Contributor

damccorm commented Jun 5, 2022

After debugging, the issue arises here

The method above is not able to infer outputs properly in Python 3.10 and results in an outputting wrong output type. 


# Python <= 3.9 

from apache_beam.typehints.trivial_inference import infer_return_type_func  

fn = lambda x: False
wrapper = lambda x, *args, **kwargs: [x] if fn(x, *args, **kwargs) else []
output_type = infer_return_type_func(wrapper, [int])
# output_type would be List[int]

# Python == 3.10

output_type = infer_return_type_func(wrapper, [int]) 
# fails with error beam/sdks/python/apache_beam/typehints/opcodes.py", line # 322, in dict_update base = state.stack[-arg]
# IndexError: list index out of range

# in python
3.9
from dis import dis
print(dis(wrapper))

'''
 0 LOAD_GLOBAL              0 (fn)
 2 LOAD_FAST                0 (x)
 4 BUILD_LIST               1         
 6 LOAD_FAST                1 (args)
 8 LIST_EXTEND              1
10 LIST_TO_TUPLE
12 BUILD_MAP                0
14 LOAD_FAST               2 (kwargs)
16 DICT_MERGE               1
18 CALL_FUNCTION_EX         1  
20 POP_JUMP_IF_FALSE       28
22 LOAD_FAST                0 (x)          
24 BUILD_LIST               1
26 RETURN_VALUE
28 BUILD_LIST              0
30 RETURN_VALUE
'''

# in python 3.10 

print(dis(wrapper))
'''
 0 LOAD_GLOBAL              0 (fn)
 2 LOAD_FAST                0 (x)
 4 BUILD_LIST               1
 6 LOAD_FAST                1 (args)
 8 LIST_EXTEND            1
10 LIST_TO_TUPLE
12 BUILD_MAP                0          
14 LOAD_FAST                2 (kwargs)
16 DICT_MERGE               1
18 CALL_FUNCTION_EX         1
20 POP_JUMP_IF_FALSE       14 (to 28)
22 LOAD_FAST               0 (x)
24 BUILD_LIST               1
26 RETURN_VALUE     
28 BUILD_LIST               0
30 RETURN_VALUE
'''



Imported from Jira BEAM-14547. Original Jira may contain additional context.
Reported by: Anand Inguva.

@damccorm
Copy link
Contributor Author

damccorm commented Jun 5, 2022

Unable to assign user @AnandInguva. If able, self-assign, otherwise tag @damccorm so that he can assign you. Because of GitHub's spam prevention system, your activity is required to enable assignment in this repo.

@AnandInguva
Copy link
Contributor

.take-issue

@AnandInguva
Copy link
Contributor

@yeandy this is one of the bug related to Python 3.10 type inference. Can you assign this to yourself?

@AnandInguva
Copy link
Contributor

AnandInguva commented Jul 27, 2022

Failed tests for Python 3.10 on inference can be found at https://ci-beam.apache.org/job/beam_PreCommit_Python_Commit/24196/ or in github actions as well

@yeandy
Copy link
Contributor

yeandy commented Jul 28, 2022

.take-issue

@yeandy
Copy link
Contributor

yeandy commented Jul 28, 2022

Not sure if I can override the assignee by commenting .take-issue. Edit: It assigned to me now.

@AnandInguva AnandInguva mentioned this issue Oct 12, 2022
4 tasks
@github-actions github-actions bot added this to the 2.43.0 Release milestone Oct 18, 2022
@tvalentyn tvalentyn added the done & done Issue has been reviewed after it was closed for verification, followups, etc. label Oct 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug core done & done Issue has been reviewed after it was closed for verification, followups, etc. P2 python
Projects
None yet
4 participants