Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Iterator and Generator annotations are not processed correctly #72

Open
jolaf opened this issue Aug 27, 2019 · 0 comments
Open

Iterator and Generator annotations are not processed correctly #72

jolaf opened this issue Aug 27, 2019 · 0 comments

Comments

@jolaf
Copy link

jolaf commented Aug 27, 2019

The following code:

from typing import Iterator

from pytypes import TypeChecker

def f() -> Iterator[str]:
    yield 'abc'

with TypeChecker():
    x = tuple(c for c in f())
    print("OK")

fails as follows:

$ python3 Test.py
Traceback (most recent call last):
  File "Test.py", line 9, in <module>
    x = tuple(c for c in f())
  File "Test.py", line 9, in <genexpr>
    x = tuple(c for c in f())
  File "Test.py", line 6, in f
    yield 'abc'
pytypes.exceptions.ReturnTypeError: 
  __main__.f
  returned incompatible type:
Expected: Iterator[str]
Received: str

Also a simple call to f(), not wrapped in generator expression and tuple, fails in a slightly different manner:

$ python3 Test.py
Exception ignored in: <generator object f at 0x7fe74e4b7db0>
Traceback (most recent call last):
  File "Test.py", line 5, in f
    def f() -> Iterator[str]:
  File "/usr/local/lib/python3.6/dist-packages/pytypes-1.0b5.post23-py3.6.egg/pytypes/type_util.py", line 2580, in __call__
    _check_caller_type(True, None, arg, caller_level=self._caller_level_shift+1)
  File "/usr/local/lib/python3.6/dist-packages/pytypes-1.0b5.post23-py3.6.egg/pytypes/type_util.py", line 2431, in _check_caller_type
    prop_getter, force_exception=True)
  File "/usr/local/lib/python3.6/dist-packages/pytypes-1.0b5.post23-py3.6.egg/pytypes/typechecker.py", line 718, in _checkfuncresult
    _raise_typecheck_error(msg, True, check_val, tpch, resSig, func)
  File "/usr/local/lib/python3.6/dist-packages/pytypes-1.0b5.post23-py3.6.egg/pytypes/type_util.py", line 2336, in _raise_typecheck_error
    raise pytypes.ReturnTypeError(msg)
pytypes.exceptions.ReturnTypeError: 
  __main__.f
  returned incompatible type:
Expected: Iterator[str]
Received: NoneType
OK

Similar stacks occur if Iterator[str] is replaced with Generator[str, None, None].

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant