[
https://issues.apache.org/jira/browse/BEAM-12914?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17488255#comment-17488255
]
Valentyn Tymofieiev commented on BEAM-12914:
--------------------------------------------
Took a look at these tests.
Python 3.9 added new opcodes, which we don't yet handle in
https://github.com/apache/beam/blob/master/sdks/python/apache_beam/typehints/opcodes.py
https://www.diffchecker.com/kX5h3Cli
The LIST_TO_TUPLE and LIST_EXTEND opcodes are likely directly responsible for
these test failures and also for BEAM-12920.
We will likely need to add support for
SET_UPDATE
DICT_MERGE
DICT_UPDATE
to properly support https://www.python.org/dev/peps/pep-0584/, filed BEAM-13843
for that issue.
Not sure about other opcodes.
> Trivial Type Inference Fails On Lambda Functions in Python 3.9
> --------------------------------------------------------------
>
> Key: BEAM-12914
> URL: https://issues.apache.org/jira/browse/BEAM-12914
> Project: Beam
> Issue Type: Bug
> Components: sdk-py-core
> Affects Versions: 2.32.0
> Environment: Python 3.9.7
> Linux Mint 20.2, Kernel: 5.4.0-84-generic
> Reporter: Jonathan Hourany
> Assignee: Robert Bradshaw
> Priority: P3
>
> The order and/or type of opcodes used to build lambda functions have changed
> in Python 3.9 (see example below). This causes the any test that relies on
> `trivial_inference.infer_return_type` to fail because the function returns a
> default of `Any` in cases where the type should normally be inferable. Tests
> cases that fail include:
> *
> [testBuildListUnpack|https://github.com/apache/beam/blob/8072cc0bcfd4eee08a95902e13b9bf1dc2338693/sdks/python/apache_beam/typehints/trivial_inference_test.py#L39]
>
> *
> [testBuildTupleUnpack|https://github.com/apache/beam/blob/8072cc0bcfd4eee08a95902e13b9bf1dc2338693/sdks/python/apache_beam/typehints/trivial_inference_test.py#L45]
> *
> [testBuildTupleUnpackWithCall|https://github.com/apache/beam/blob/8072cc0bcfd4eee08a95902e13b9bf1dc2338693/sdks/python/apache_beam/typehints/trivial_inference_test.py#L305]
> *
> [test_pardo_type_inference|https://github.com/apache/beam/blob/8072cc0bcfd4eee08a95902e13b9bf1dc2338693/sdks/python/apache_beam/transforms/ptransform_test.py#L2540]
> Test failure messages are all variations of:
> {noformat}
> ./sdks/python/apache_beam/transforms/ptransform_test.py::PTransformTypeCheckTestCase::test_pardo_type_inference
> Failed: [undefined]AssertionError: <class 'int'> != Any
> ./sdks/python/apache_beam/typehints/trivial_inference_test.py::TrivialInferenceTest::testBuildListUnpack
> Failed: [undefined]AssertionError: List[int] != Any
> {noformat}
> etc
> h3. Example
> {code:python}
> # Python3.7
> In [1]: from dis import dis
> In [2]: from apache_beam.typehints import typehints
> In [3]: beam_type_hints = [typehints.List[int]]
> In [4]: dis(lambda _list: [*_list, *_list, *_list](beam_type_hints))
> 1 0 LOAD_FAST 0 (_list)
> 2 LOAD_FAST 0 (_list)
> 4 LOAD_FAST 0 (_list)
> 6 BUILD_LIST_UNPACK 3
> 8 LOAD_GLOBAL 0 (beam_type_hints)
> 10 CALL_FUNCTION 1
> 12 RETURN_VALUE
> {code}
> ----
> Whereas in Python 3.9
> {code:python}
> # Python 3.9
> In [1]: from dis import dis
> In [2]: from apache_beam.typehints import typehints
> In [3]: beam_type_hints = [typehints.List[int]]
> In [4]: dis(lambda _list: [*_list, *_list, *_list](beam_type_hints))
> <>:1: SyntaxWarning: 'list' object is not callable; perhaps you missed a
> comma?
> <ipython-input-4-6499114c3d61>:1: SyntaxWarning: 'list' object is not
> callable; perhaps you missed a comma?
> dis(lambda _list: [*_list, *_list, *_list](beam_type_hints))
> 1 0 BUILD_LIST 0
> 2 LOAD_FAST 0 (_list)
> 4 LIST_EXTEND 1
> 6 LOAD_FAST 0 (_list)
> 8 LIST_EXTEND 1
> 10 LOAD_FAST 0 (_list)
> 12 LIST_EXTEND 1
> 14 LOAD_GLOBAL 0 (beam_type_hints)
> 16 CALL_FUNCTION 1
> 18 RETURN_VALUE
> {code}
> The `SyntaxWarning` is most likely raising because enhancment in
> [bpo-15248|https://bugs.python.org/issue15248] misses the fact that the
> lambda expression is a function, not a list we're calling, and isn't relevant
> to the issue.
>
--
This message was sent by Atlassian Jira
(v8.20.1#820001)