mirror of
https://github.com/python/cpython.git
synced 2025-08-04 17:08:35 +00:00
Added a note that objects which emulate built-in types should only
implement as many of the relevant methods as make sense for the particular information being modelled.
This commit is contained in:
parent
16942f2224
commit
0c47559352
1 changed files with 7 additions and 0 deletions
|
@ -841,6 +841,13 @@ a list object, \code{x.__getitem__(i)} is not equivalent to
|
|||
operation raise an exception when no appropriate method is defined.
|
||||
\withsubitem{(mapping object method)}{\ttindex{__getitem__()}}
|
||||
|
||||
When implementing a class that emulates any built-in type, it is
|
||||
important that the emulation only be implemented to the degree that it
|
||||
makes sense for the object being modelled. For example, some
|
||||
sequences may work well with retrieval of individual elements, but
|
||||
extracting a slice may not make sense. (One example of this is the
|
||||
\class{NodeList} interface in the W3C's Document Object Model.)
|
||||
|
||||
|
||||
\subsection{Basic customization\label{customization}}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue