tvalentyn commented on code in PR #25795:
URL: https://github.com/apache/beam/pull/25795#discussion_r1134730567
##########
sdks/python/apache_beam/typehints/opcodes.py:
##########
@@ -428,10 +432,16 @@ def gen_start(state, arg):
def load_closure(state, arg):
+ # The arg is no longer offset by len(covar_names) as of 3.11
Review Comment:
nit: it may be use useful to add references to CPython docs such as
announcements or bpa- issues.
##########
sdks/python/apache_beam/typehints/opcodes.py:
##########
@@ -440,18 +450,30 @@ def make_function(state, arg):
"""
# TODO(luke-zhu): Handle default argument types
globals = state.f.__globals__ # Inherits globals from the current frame
- func_name = state.stack[-1].value
- func_code = state.stack[-2].value
- pop_count = 2
+ tos = state.stack[-1].value
+ if isinstance(tos, types.CodeType):
+ func_name = None
Review Comment:
for my education, do we ever go in this branch for versions less than 3.11 ?
If not, why? if yes: do we have changes in the inference behavior?
##########
sdks/python/apache_beam/typehints/trivial_inference.py:
##########
@@ -498,6 +518,39 @@ def infer_return_type_func(f, input_types, debug=False,
depth=0):
else:
return_type = typehints.Any
state.stack[-pop_count:] = [return_type]
+ elif opname == 'CALL':
+ pop_count = 1 + arg
+ # Keyword Args case
+ if state.kw_names is not None:
+ if isinstance(state.stack[-pop_count], Const):
+ from apache_beam.pvalue import Row
+ if state.stack[-pop_count].value == Row:
Review Comment:
does it make sense to move this code into a helper and reuse in
CALL_FUNCTION_KW processing?
##########
sdks/python/apache_beam/typehints/trivial_inference.py:
##########
@@ -498,6 +518,39 @@ def infer_return_type_func(f, input_types, debug=False,
depth=0):
else:
return_type = typehints.Any
state.stack[-pop_count:] = [return_type]
+ elif opname == 'CALL':
+ pop_count = 1 + arg
+ # Keyword Args case
+ if state.kw_names is not None:
+ if isinstance(state.stack[-pop_count], Const):
+ from apache_beam.pvalue import Row
+ if state.stack[-pop_count].value == Row:
+ fields = state.kw_names
+ return_type = row_type.RowTypeConstraint.from_fields(
+ list(
+ zip(fields,
+ Const.unwrap_all(state.stack[-pop_count + 1:]))))
+ else:
+ return_type = Any
+ state.kw_names = None
+ else:
+ # Catch lambdas not passing in arg values properly
Review Comment:
do we already have tests for this?
For my education, what does not passing properly mean in this context?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]