[Python-ideas] Type Hinting Kick-off

Dennis Brakhane brakhane at googlemail.com
Sat Dec 20 23:00:51 CET 2014


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 realiably (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


More information about the Python-ideas mailing list