This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: next method assignment is ignored in new-style classes
Type: Stage:
Components: Interpreter Core Versions: Python 2.5
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: nnorwitz Nosy List: albert2611, georg.brandl, nnorwitz
Priority: normal Keywords:

Created on 2007-03-17 15:06 by albert2611, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
iterator_classes.py albert2611, 2007-03-17 15:06 iterator assignment - code example
Messages (5)
msg31560 - (view) Author: Albert Weichselbraun (albert2611) Date: 2007-03-17 15:06
in old-style classes the next method of an iterator-superclass can be "overwritten" using

self.next = self.new_next_method

when new-style classes are used the assignment is ignored and instead of new_next_method the next method of the superclass is called when the class is used as iterator (tested for python2.3-2.5 under debian/linux).
- if the next() method is called directly, the assigned
  method is used (see attached code example).
msg31561 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2007-03-17 15:52
This is another incarnation of __methods__ being looked up on the type, not the instance, except that next() is not a __method__ yet.

For new-style classes, this behavior is considered correct. Neal?
msg31562 - (view) Author: Albert Weichselbraun (albert2611) Date: 2007-03-17 16:27
i only experienced this behavior for the next method in iterator classes.
overwriting methods with other names using an assignment works as expected.
msg31563 - (view) Author: Neal Norwitz (nnorwitz) * (Python committer) Date: 2007-03-21 07:02
Yup, based on mail thread this behaviour seems correct.  Unfortunately, I don't think it's properly documented or consistent either. :-(
msg31564 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2007-03-21 08:54
Closing this then, I have opened a new bug (#1684991) for the documentation issue.
History
Date User Action Args
2022-04-11 14:56:23adminsetgithub: 44735
2007-03-17 15:06:52albert2611create