> Practically speaking, one issue I have is how easy it is to write > isinstance or issubclass checks. It has historically been much more > difficult to write and maintain a check that something looks like a duck. > > `if hasattr(foo, 'close') and hasattr(foo, 'seek') and hasattr(foo, > 'read'):` > > Just does not roll off the figurative tongue and that is a relatively > simple example of what is required for a duck check. > > To prevent isinstance use when a duck check would be better, >
I'm going to chime in briefly then return to lurking on this topic, trying to figure out all the changes to typing while I wasn't paying attention. Back in ancient times I recall "look before you leap" as the description of either of the above styles of checks, no matter which was easier to type. At the time, I thought the general recommendation was to document what attributes you expected objects to provide and just make the relevant unguarded references. I no longer recall what the tongue-in-cheek description of that style was (just "leap"?) Is that more simple usage more akin to classic "duck typing" than always guarding accesses? I assume that will still have a place in the pantheon of Python type variants. Skip
_______________________________________________ Python-Dev mailing list -- [email protected] To unsubscribe send an email to [email protected] https://mail.python.org/mailman3/lists/python-dev.python.org/ Message archived at https://mail.python.org/archives/list/[email protected]/message/QW7NQ5KTOQLV27MKZO5B3TMSTXIR5MC5/ Code of Conduct: http://python.org/psf/codeofconduct/
