[ 
https://issues.apache.org/jira/browse/BEAM-13272?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Valentyn Tymofieiev updated BEAM-13272:
---------------------------------------
    Status: Resolved  (was: Resolved)

> Support type inference on Python 3.9
> ------------------------------------
>
>                 Key: BEAM-13272
>                 URL: https://issues.apache.org/jira/browse/BEAM-13272
>             Project: Beam
>          Issue Type: Sub-task
>          Components: sdk-py-core
>            Reporter: Valentyn Tymofieiev
>            Priority: P2
>             Fix For: Not applicable
>
>
> Several type inference-releated tests fail on Py 3.9:
> Test Result (6 failures / +6)
> apache_beam.pipeline_test.DoFnTest.test_incomparable_default
> apache_beam.transforms.ptransform_test.PTransformTypeCheckTestCase.test_pardo_type_inference
> apache_beam.typehints.native_type_compatibility_test.NativeTypeCompatibilityTest.test_convert_bare_types
> apache_beam.typehints.trivial_inference_test.TrivialInferenceTest.testBuildListUnpack
> apache_beam.typehints.trivial_inference_test.TrivialInferenceTest.testBuildTupleUnpack
> apache_beam.typehints.trivial_inference_test.TrivialInferenceTest.testBuildTupleUnpackWithCall
> Sample errors:
> {noformat}
> Error Message
> RuntimeError
> Stacktrace
> self = <apache_beam.pipeline_test.DoFnTest 
> testMethod=test_incomparable_default>
>     def test_incomparable_default(self):
>       class IncomparableType(object):
>         def __eq__(self, other):
>           raise RuntimeError()
>     
>         def __ne__(self, other):
>           raise RuntimeError()
>     
>         def __hash__(self):
>           raise RuntimeError()
>     
>       # Ensure that we don't use default values in a context where they must 
> be
>       # comparable (see BEAM-8301).
>       with TestPipeline() as pipeline:
>         pcoll = (
>             pipeline
>             | beam.Create([None])
>             | Map(lambda e, x=IncomparableType(): (e, type(x).__name__)))
> >       assert_that(pcoll, equal_to([(None, 'IncomparableType')]))
> apache_beam/pipeline_test.py:816: 
> _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
> _ 
> apache_beam/pipeline.py:596: in __exit__
>     self.result = self.run()
> apache_beam/testing/test_pipeline.py:112: in run
>     result = super().run(
> apache_beam/pipeline.py:546: in run
>     return Pipeline.from_runner_api(
> apache_beam/pipeline.py:573: in run
>     return self.runner.run_pipeline(self, self._options)
> apache_beam/runners/direct/direct_runner.py:131: in run_pipeline
>     return runner.run_pipeline(pipeline, options)
> apache_beam/runners/portability/fn_api_runner/fn_runner.py:195: in 
> run_pipeline
>     self._latest_run_result = self.run_via_runner_api(
> apache_beam/runners/portability/fn_api_runner/fn_runner.py:206: in 
> run_via_runner_api
>     return self.run_stages(stage_context, stages)
> apache_beam/runners/portability/fn_api_runner/fn_runner.py:384: in run_stages
>     stage_results = self._run_stage(
> apache_beam/runners/portability/fn_api_runner/fn_runner.py:646: in _run_stage
>     self._run_bundle(
> apache_beam/runners/portability/fn_api_runner/fn_runner.py:769: in _run_bundle
>     result, splits = bundle_manager.process_bundle(
> apache_beam/runners/portability/fn_api_runner/fn_runner.py:1080: in 
> process_bundle
>     result_future = self._worker_handler.control_conn.push(process_bundle_req)
> apache_beam/runners/portability/fn_api_runner/worker_handlers.py:378: in push
>     response = self.worker.do_instruction(request)
> apache_beam/runners/worker/sdk_worker.py:580: in do_instruction
>     return getattr(self, request_type)(
> apache_beam/runners/worker/sdk_worker.py:611: in process_bundle
>     bundle_processor = self.bundle_processor_cache.get(
> apache_beam/runners/worker/sdk_worker.py:441: in get
>     processor = bundle_processor.BundleProcessor(
> apache_beam/runners/worker/bundle_processor.py:865: in __init__
>     op.setup()
> apache_beam/runners/worker/operations.py:686: in setup
>     self.dofn_runner = common.DoFnRunner(
> apache_beam/runners/common.py:1185: in __init__
>     self.do_fn_invoker = DoFnInvoker.create_invoker(
> apache_beam/runners/common.py:423: in create_invoker
>     return PerWindowInvoker(
> apache_beam/runners/common.py:561: in __init__
>     (core.DoFn.WindowParam in default_arg_values) or
> _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
> _ 
> self = <apache_beam.pipeline_test.IncomparableType object at 0x7f64877aaaf0>
> other = WindowParam
>     def __eq__(self, other):
> >     raise RuntimeError()
> E     RuntimeError
> apache_beam/pipeline_test.py:801: RuntimeError
> {noformat}
> {noformat}
> Error Message
> AssertionError: Tuple[int, str, str] != Any
> Stacktrace
> self = <apache_beam.typehints.trivial_inference_test.TrivialInferenceTest 
> testMethod=testBuildTupleUnpack>
>     def testBuildTupleUnpack(self):
>       # Lambda uses BUILD_TUPLE_UNPACK opcode in Python 3.
>       # yapf: disable
> >     self.assertReturnType(
>           typehints.Tuple[int, str, str],
>           lambda _list1, _list2: (*_list1, *_list2, *_list2),
>           [typehints.List[int], typehints.List[str]])
> apache_beam/typehints/trivial_inference_test.py:48: 
> _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
> _ 
> apache_beam/typehints/trivial_inference_test.py:35: in assertReturnType
>     self.assertEqual(
> E   AssertionError: Tuple[int, str, str] != Any
> Standard Output
> <function TrivialInferenceTest.testBuildTupleUnpack.<locals>.<lambda> at 
> 0x7f8961e728b0> 140228029786288 [List[int], List[str]]
>  50           0 BUILD_LIST               0
>               2 LOAD_FAST                0 (_list1)
>               4 LIST_EXTEND              1
>               6 LOAD_FAST                1 (_list2)
>               8 LIST_EXTEND              1
>              10 LOAD_FAST                1 (_list2)
>              12 LIST_EXTEND              1
>              14 LIST_TO_TUPLE
>              16 RETURN_VALUE
>         0 BUILD_LIST               0 Executing simple op BUILD_LIST
> Stack: [List[Union[]]] Vars: [List[int], List[str]]
> {}
>         2 LOAD_FAST                0 (_list1) Executing simple op LOAD_FAST
> Stack: [List[Union[]], List[int]] Vars: [List[int], List[str]]
> {}
>         4 LIST_EXTEND              1 
> Standard Error
> Traceback (most recent call last):
>   File 
> "/home/jenkins/jenkins-slave/workspace/beam_PreCommit_Python_Commit/src/sdks/python/test-suites/tox/py39/build/srcs/sdks/python/apache_beam/typehints/trivial_inference.py",
>  line 289, in infer_return_type
>     return infer_return_type_func(c, input_types, debug, depth)
>   File 
> "/home/jenkins/jenkins-slave/workspace/beam_PreCommit_Python_Commit/src/sdks/python/test-suites/tox/py39/build/srcs/sdks/python/apache_beam/typehints/trivial_inference.py",
>  line 507, in infer_return_type_func
>     raise TypeInferenceError('unable to handle %s' % opname)
> apache_beam.typehints.trivial_inference.TypeInferenceError: unable to handle 
> LIST_EXTEND
> {noformat}



--
This message was sent by Atlassian Jira
(v8.20.1#820001)

Reply via email to