New submission from Paddy McCarthy <[EMAIL PROTECTED]>: The official glossary entry here: http://docs.python.org/tut/node18.html#l2h-46 says: " duck-typing Pythonic programming style that determines an object's type by inspection of its method or attribute signature rather than by explicit relationship to some type object ("If it looks like a duck and quacks like a duck, it must be a duck.") By emphasizing interfaces rather than specific types, well-designed code improves its flexibility by allowing polymorphic substitution. Duck-typing avoids tests using type() or isinstance(). Instead, it typically employs hasattr() tests or EAFP programming. "
I think it is should be changed to delete the use of hasattr and just rely on EAFP as in the second example here: http://en.wikipedia.org/wiki/Python_syntax_and_semantics#Exceptions The text would then read: " duck-typing Pythonic programming style that determines an object's type by inspection of its method or attribute signature rather than by explicit relationship to some type object ("If it looks like a duck and quacks like a duck, it must be a duck.") By emphasizing interfaces rather than specific types, well-designed code improves its flexibility by allowing polymorphic substitution. Duck-typing avoids tests using type(), hasattr() or isinstance(). Instead, it typically employs an EAFP style of programming. " The reason is that a hasattr test only tests for an attribute name. If it is present and say the method signature is wrong, then its the excecution of the code using the attribute that will find that out so it is redundant. Best to use EAFP for Duck typing as we trust you know what it is you are doing. - Paddy. ---------- assignee: georg.brandl components: Documentation messages: 68815 nosy: georg.brandl, paddy3118 severity: normal status: open title: Suggest change to glossary explanation: "Duck Typing" type: feature request versions: Python 2.5, Python 2.6, Python 3.0 _______________________________________ Python tracker <[EMAIL PROTECTED]> <http://bugs.python.org/issue3214> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com