On Fri, Jun 2, 2017 at 1:07 PM, Koos Zevenhoven <k7ho...@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
>
> @call
> def number():
>     return 42
>

Well mypy actually gives an error for that, "Name 'number' already defined".


>
> But for functions one could have (
> ​using
>  the context manager example):
>
>
> def session(url: str) -> ContextManager[DatabaseSession]: ...
>
> @predeclared
> @contextmanager
> def session(url: str) -> Iterator[DatabaseSession]:
>     s = DatabaseSession(url)
>     try:
>         yield s
>     finally:
>         s.close()
>
>
> 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)
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to