[ 
https://issues.apache.org/jira/browse/BEAM-12914?focusedWorklogId=723164&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-723164
 ]

ASF GitHub Bot logged work on BEAM-12914:
-----------------------------------------

                Author: ASF GitHub Bot
            Created on: 08/Feb/22 20:59
            Start Date: 08/Feb/22 20:59
    Worklog Time Spent: 10m 
      Work Description: tvalentyn merged pull request #16761:
URL: https://github.com/apache/beam/pull/16761


   


-- 
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]


Issue Time Tracking
-------------------

    Worklog Id:     (was: 723164)
    Time Spent: 4.5h  (was: 4h 20m)

> Support LIST_EXTEND and LIST_TO_TUPLE opcodes in type inference on Python 3.9
> -----------------------------------------------------------------------------
>
>                 Key: BEAM-12914
>                 URL: https://issues.apache.org/jira/browse/BEAM-12914
>             Project: Beam
>          Issue Type: Sub-task
>          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
>          Time Spent: 4.5h
>  Remaining Estimate: 0h
>
> 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)

Reply via email to