]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Add duck-typing to the glossary.
authorRaymond Hettinger <python@rcn.com>
Tue, 11 Jan 2005 16:14:55 +0000 (16:14 +0000)
committerRaymond Hettinger <python@rcn.com>
Tue, 11 Jan 2005 16:14:55 +0000 (16:14 +0000)
Doc/tut/glossary.tex

index b0ac97f552d6df1fc86a6a2778917b0eea79fe77..7f04a79c34b918bec005083c284dd161cba7da40 100644 (file)
@@ -85,6 +85,17 @@ use of \class{dict} much resembles that for \class{list}, but the keys
 can be any object with a \method{__hash__()} function, not just
 integers starting from zero.  Called a hash in Perl.
 
+\index{duck-typing}
+\item{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 \function{type()} or
+\function{isinstance()}. Instead, it typically employs
+\function{hasattr()} tests or {}\emph{EAFP} programming.
+
 \index{EAFP}
 \item[EAFP]
 Easier to ask for forgiveness than permission.  This common Python