News for hackers. Stuff that matters.
Re:Static types in Python by benhoyt on Thursday October 13, 2016 @09:42PM (#12705630)
Interestingly, I think that's what isinstance() actually does when it's called on abstract base classes like collections.abc.Iterable -- it looks to see whether the type supports __iter__ and whatnot. See the abc module and it's implementation here:

* https://docs.python.org/3.4/library/collections.abc.html * https://hg.python.org/cpython/file/3.4/Lib/_collections_abc....

Re:Static types in Python by clusmore on Thursday October 13, 2016 @09:47PM (#12705648)
Pasting the relevant snippet from your link:

  def __subclasshook__(cls, C):
      if cls is Iterable:
          if any("__iter__" in B.__dict__ for B in C.__mro__):
              return True
      return NotImplemented
Wow, hadn't seen this before. That's exactly what I mean. If I can define my own, e.g. Addable, which does a similar check for the presence of __add__ (and __radd__) and MyPy uses the subclasshook, then that'd be perfect.
Re:Static types in Python by dbcurtis on Thursday October 13, 2016 @11:09PM (#12705910)
Get _Fluent_Python_ by Ramalho and read chapter 11.