[Python-Dev] PEP 484 update proposal: annotating decorated declarations
Guido van Rossum
guido at python.org
Fri Jun 2 18:16:10 EDT 2017
On Fri, Jun 2, 2017 at 1:07 PM, Koos Zevenhoven <k7hoven at gmail.com> wrote:
> I suppose it is, especially because there seems to be nothing that
> prevents you from getting runtime annotations in the enclosing class/module
> number: int
> def number():
> return 42
Well mypy actually gives an error for that, "Name 'number' already defined".
> But for functions one could have (
> the context manager example):
> def session(url: str) -> ContextManager[DatabaseSession]: ...
> def session(url: str) -> Iterator[DatabaseSession]:
> s = DatabaseSession(url)
> yield s
> This makes it clear that the function is declared elsewhere. But the
> `predeclared` decorator would need tricks like sys._getframe(1) to set
> session.__annotations__ according to the predeclaration.
I'm not excited about that.
--Guido van Rossum (python.org/~guido)
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-Dev