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

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

                Author: ASF GitHub Bot
            Created on: 15/May/19 02:18
            Start Date: 15/May/19 02:18
    Worklog Time Spent: 10m 
      Work Description: udim commented on issue #8530: [BEAM-6988] solved 
problem related to updates of the str object
URL: https://github.com/apache/beam/pull/8530#issuecomment-492477990
 
 
   In 
`apache_beam.typehints.typed_pipeline_test:MainInputTest.test_non_function`, 
`getcallargs_forhints` is called twice:
   
https://github.com/apache/beam/blob/ef4b2ef7e5fa2fb87e1491df82d2797947f51be9/sdks/python/apache_beam/transforms/ptransform.py#L761-L762
   
   The second time fails, since type_hints is equals to `((<class 'str'>,), 
{})`, but inspect.getcallargs fails because it thinks str.strip has 2 required 
positional args (self and chars). I opened a bug for this 
(https://bugs.python.org/issue36920), but I believe we can use 
inspect.Signature instead in Python 3.
   
   The code generating the type hint is I believe:
   
https://github.com/apache/beam/blob/5c7ee600ba8560102f61622c894633955d208f87/sdks/python/apache_beam/typehints/decorators.py#L330-L331
   
   So this brings up some questions (cc: @robertwb)
   1. Are partial type hints okay?
   1. Is the type hints heuristic from decorators.py above useful? Should it 
stay?
   
   To summarize: the type hints generated for str.strip are partial and 
inspect.getcallargs is buggy and believes that str.strip has 2 required 
positional args instead of 1.
   I think that if we decide to not guess type hints for builtin functions in 
Python 3 (the code in decorators.py), then this will solve the issue.
   Another option is to replace inspect.getcallargs with 
inspect.signature(fn).bind(...), which seems to be less buggy, but only works 
for builtins in 3.7.
 
----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[email protected]


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

    Worklog Id:     (was: 242192)
    Time Spent: 2h 50m  (was: 2h 40m)

> TypeHints Py3 Error: test_non_function 
> (apache_beam.typehints.typed_pipeline_test.MainInputTest) Fails on Python 3.7+
> ---------------------------------------------------------------------------------------------------------------------
>
>                 Key: BEAM-6988
>                 URL: https://issues.apache.org/jira/browse/BEAM-6988
>             Project: Beam
>          Issue Type: Sub-task
>          Components: sdk-py-core
>            Reporter: Robbe
>            Assignee: niklas Hansson
>            Priority: Major
>          Time Spent: 2h 50m
>  Remaining Estimate: 0h
>
> {noformat}
> Traceback (most recent call last):
>  File 
> "/home/jenkins/jenkins-slave/workspace/beam_PreCommit_Python_Commit/src/sdks/python/test-suites/tox/py37/build/srcs/sdks/python/apache_beam/typehints/typed_pipeline_test.py",
>  line 53, in test_non_function
>  result = ['xa', 'bbx', 'xcx'] | beam.Map(str.strip, 'x')
>  File 
> "/home/jenkins/jenkins-slave/workspace/beam_PreCommit_Python_Commit/src/sdks/python/test-suites/tox/py37/build/srcs/sdks/python/apache_beam/transforms/ptransform.py",
>  line 510, in _ror_
>  result = p.apply(self, pvalueish, label)
>  File 
> "/home/jenkins/jenkins-slave/workspace/beam_PreCommit_Python_Commit/src/sdks/python/test-suites/tox/py37/build/srcs/sdks/python/apache_beam/pipeline.py",
>  line 514, in apply
>  transform.type_check_inputs(pvalueish)
>  File 
> "/home/jenkins/jenkins-slave/workspace/beam_PreCommit_Python_Commit/src/sdks/python/test-suites/tox/py37/build/srcs/sdks/python/apache_beam/transforms/ptransform.py",
>  line 753, in type_check_inputs
>  hints = getcallargs_forhints(argspec_fn, *type_hints[0], **type_hints[1])
>  File 
> "/home/jenkins/jenkins-slave/workspace/beam_PreCommit_Python_Commit/src/sdks/python/test-suites/tox/py37/build/srcs/sdks/python/apache_beam/typehints/decorators.py",
>  line 283, in getcallargs_forhints
>  raise TypeCheckError(e)
>  apache_beam.typehints.decorators.TypeCheckError: strip() missing 1 required 
> positional argument: 'chars'{noformat}



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to