Skip to content

contextlib.contextmanager allows Iterator[T] -- should probably be Generator[T, None, None]? #2772

Description

@asottile

For instance, this script passes mypy:

importcontextlibfromtypingimportIterator@contextlib.contextmanagerdeff() ->Iterator[int]:
returniter([1])
withf():
passwithf():
raiseTypeError('wat')

but fails at runtime (and not in the expected way):

$ python t.py Traceback (most recent call last): File "t.py", line 14, in <module> raise TypeError('wat')TypeError: watDuring handling of the above exception, another exception occurred:Traceback (most recent call last): File "t.py", line 14, in <module> raise TypeError('wat') File "/usr/lib/python3.6/contextlib.py", line 99, in __exit__ self.gen.throw(type, value, traceback)AttributeError: 'list_iterator' object has no attribute 'throw'

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: deferredIssue or PR deferred until some precondition is fixedstubs: false negativeType checkers do not report an error, but should

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions