<p dir="ltr">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.</p>
<br><div class="gmail_quote">On Sun, Dec 21, 2014, 11:55 Andrew Svetlov <<a href="mailto:andrew.svetlov@gmail.com">andrew.svetlov@gmail.com</a>> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">The silly question.<br>
<br>
I use python 3 annotations for argument checking.<br>
<br>
My assumption is very simple, for<br>
<br>
def f(arg: checker): pass<br>
<br>
the checker will raise ValueError or TypeError if arg is not correct.<br>
I do it by `checker(arg)` call.<br>
<br>
I use this in aiozmq rpc<br>
(<a href="http://aiozmq.readthedocs.org/en/0.5/rpc.html#signature-validation" target="_blank">http://aiozmq.readthedocs.<u></u>org/en/0.5/rpc.html#signature-<u></u>validation</a>)<br>
for example and checkers from trafaret<br>
(<a href="https://github.com/Deepwalker/trafaret" target="_blank">https://github.com/<u></u>Deepwalker/trafaret</a>) works fine.<br>
<br>
Will proposed change break my workflow?<br>
<br>
On Sun, Dec 21, 2014 at 6:53 PM, Guido van Rossum <<a href="mailto:guido@python.org" target="_blank">guido@python.org</a>> wrote:<br>
> On Sat, Dec 20, 2014 at 2:00 PM, Dennis Brakhane <<a href="mailto:brakhane@googlemail.com" target="_blank">brakhane@googlemail.com</a>><br>
> wrote:<br>
>><br>
>> Maybe I'm missing something, but wouldn't type hinting as it's defined<br>
>> now break "virtual subclassing" of ABC?<br>
>><br>
>> For example, given the following code:<br>
>><br>
>>   from collections import Sequence<br>
>><br>
>>   class MySequence:<br>
>>     ...<br>
>><br>
>>   Sequence.register(MySequence)<br>
>><br>
>> it seems to me like the following would work:<br>
>><br>
>>   def foo(bar):<br>
>>       if not isinstance(bar, Sequence):<br>
>>           raise RuntimeError("Foo can only work with sequences")<br>
>>       ...<br>
>><br>
>> but when rewritten for static type checking<br>
>><br>
>>     def foo(bar: Sequence):<br>
>>         ....<br>
>><br>
>> it would cease to work. At least I don't see a way a static type checker<br>
>> could handle this relaiably (the register call might occur anywhere,<br>
>> after all)<br>
>><br>
>> Is this intentional?<br>
>><br>
>> Even if this might be more a mypy/implementation question, it should be<br>
>> clear to users of typing.py if they should expect ABCs to break or not<br>
><br>
><br>
> Well, the program will still run fine with CPython, assuming you keep the<br>
> isinstance() check in your program. The argument declaration does not cause<br>
> calls with non-Sequence arguments to be rejected, it just guides the static<br>
> checker (which is a program that you must run separately, in a similar way<br>
> as a linter -- it is not built into CPython).<br>
><br>
> The static checker may request the call foo(MySequence()) if it cannot see<br>
> that MySequence is a Sequence. You have two options there: if you can change<br>
> the code of MySequence, you should just inherit from Sequence rather than<br>
> using the register() call; if you cannot change the code of MySequence, you<br>
> should use a *stub* module which declares that MySequence is a Sequence. You<br>
> can read up on stub modules in the mypy docs:<br>
> <a href="http://mypy.readthedocs.org/en/latest/basics.html#library-stubs" target="_blank">http://mypy.readthedocs.org/<u></u>en/latest/basics.html#library-<u></u>stubs</a><br>
><br>
> --<br>
> --Guido van Rossum (<a href="http://python.org/~guido" target="_blank">python.org/~guido</a>)<br>
><br>
> ______________________________<u></u>_________________<br>
> Python-ideas mailing list<br>
> <a href="mailto:Python-ideas@python.org" target="_blank">Python-ideas@python.org</a><br>
> <a href="https://mail.python.org/mailman/listinfo/python-ideas" target="_blank">https://mail.python.org/<u></u>mailman/listinfo/python-ideas</a><br>
> Code of Conduct: <a href="http://python.org/psf/codeofconduct/" target="_blank">http://python.org/psf/<u></u>codeofconduct/</a><br>
<br>
<br>
<br>
--<br>
Thanks,<br>
Andrew Svetlov<br>
______________________________<u></u>_________________<br>
Python-ideas mailing list<br>
<a href="mailto:Python-ideas@python.org" target="_blank">Python-ideas@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/python-ideas" target="_blank">https://mail.python.org/<u></u>mailman/listinfo/python-ideas</a><br>
Code of Conduct: <a href="http://python.org/psf/codeofconduct/" target="_blank">http://python.org/psf/<u></u>codeofconduct/</a><br>
</blockquote></div>