[Python-ideas] Type Hinting Kick-off
brett at python.org
Sun Dec 21 21:11:23 CET 2014
You're workflow won't necessarily break. You need to use a tool which
expects type hints for function annotations to cause you any problems. If
you simply don't use such a tool then you will have no problems.
On Sun, Dec 21, 2014, 11:55 Andrew Svetlov <andrew.svetlov at gmail.com> wrote:
> The silly question.
> I use python 3 annotations for argument checking.
> My assumption is very simple, for
> def f(arg: checker): pass
> the checker will raise ValueError or TypeError if arg is not correct.
> I do it by `checker(arg)` call.
> I use this in aiozmq rpc
> for example and checkers from trafaret
> (https://github.com/Deepwalker/trafaret) works fine.
> Will proposed change break my workflow?
> On Sun, Dec 21, 2014 at 6:53 PM, Guido van Rossum <guido at python.org>
> > On Sat, Dec 20, 2014 at 2:00 PM, Dennis Brakhane <
> brakhane at googlemail.com>
> > wrote:
> >> Maybe I'm missing something, but wouldn't type hinting as it's defined
> >> now break "virtual subclassing" of ABC?
> >> For example, given the following code:
> >> from collections import Sequence
> >> class MySequence:
> >> ...
> >> Sequence.register(MySequence)
> >> it seems to me like the following would work:
> >> def foo(bar):
> >> if not isinstance(bar, Sequence):
> >> raise RuntimeError("Foo can only work with sequences")
> >> ...
> >> but when rewritten for static type checking
> >> def foo(bar: Sequence):
> >> ....
> >> it would cease to work. At least I don't see a way a static type checker
> >> could handle this relaiably (the register call might occur anywhere,
> >> after all)
> >> Is this intentional?
> >> Even if this might be more a mypy/implementation question, it should be
> >> clear to users of typing.py if they should expect ABCs to break or not
> > Well, the program will still run fine with CPython, assuming you keep the
> > isinstance() check in your program. The argument declaration does not
> > calls with non-Sequence arguments to be rejected, it just guides the
> > checker (which is a program that you must run separately, in a similar
> > as a linter -- it is not built into CPython).
> > The static checker may request the call foo(MySequence()) if it cannot
> > that MySequence is a Sequence. You have two options there: if you can
> > the code of MySequence, you should just inherit from Sequence rather than
> > using the register() call; if you cannot change the code of MySequence,
> > should use a *stub* module which declares that MySequence is a Sequence.
> > can read up on stub modules in the mypy docs:
> > http://mypy.readthedocs.org/en/latest/basics.html#library-stubs
> > --
> > --Guido van Rossum (python.org/~guido)
> > _______________________________________________
> > Python-ideas mailing list
> > Python-ideas at python.org
> > https://mail.python.org/mailman/listinfo/python-ideas
> > Code of Conduct: http://python.org/psf/codeofconduct/
> Andrew Svetlov
> Python-ideas mailing list
> Python-ideas at python.org
> Code of Conduct: http://python.org/psf/codeofconduct/
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-ideas