Skip to content
GitLab
  • Menu
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • pypy pypy
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 673
    • Issues 673
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 13
    • Merge requests 13
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages & Registries
    • Packages & Registries
    • Container Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • PyPy
  • pypypypy
  • Issues
  • #3716
Closed
Open
Created Mar 28, 2022 by Shane Harvey@ShaneHarvey

Class with __iter__ = None should raise a more helpful error message

According to the Python documentation:

Setting a special method to None indicates that the corresponding operation is not available. For example, if a class sets iter() to None, the class is not iterable, so calling iter() on its instances will raise a TypeError (without falling back to getitem()). [2]

https://docs.python.org/3/reference/datamodel.html#special-method-names

PyPy follows this behavior but the TypeError it raises is not ideal:

>>>> class A:
....     __iter__ = None
....     
>>>> iter(A())
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'NoneType' object is not callable

Compare this to the more helpful error raised by CPython:

>>> class A:
...     __iter__ = None
... 
>>> iter(A())
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'A' object is not iterable

Edit: I found this while working on https://jira.mongodb.org/browse/PYTHON-3084

Edited Mar 28, 2022 by Shane Harvey
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
Time tracking