Author paddy3118
Recipients georg.brandl, paddy3118
Date 2008-06-27.05:10:57
SpamBayes Score 0.0167171
Marked as misclassified No
Message-id <1214543459.76.0.157400708153.issue3214@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2008-06-27 05:11:00paddy3118setspambayes_score: 0.0167171 -> 0.0167171
recipients: + paddy3118, georg.brandl
2008-06-27 05:11:00paddy3118setspambayes_score: 0.0167171 -> 0.0167171
messageid: <1214543459.76.0.157400708153.issue3214@psf.upfronthosting.co.za>
2008-06-27 05:10:59paddy3118linkissue3214 messages
2008-06-27 05:10:57paddy3118create