bpo-46417: Cleanup typeobject.c code by vstinner · Pull Request #30795 · python/cpython · GitHub
Skip to content

bpo-46417: Cleanup typeobject.c code - #30795

Merged
vstinner merged 1 commit into
python:mainfrom
vstinner:cleanup_typeobject
Jan 22, 2022
Merged

vstinner merged 1 commit into
python:mainfrom
vstinner:cleanup_typeobject

Conversation

@vstinner

@vstinner vstinner commented Jan 22, 2022

Copy link
Copy Markdown
Member
  • Add comment to recurse_down_subclasses() explaining why it's safe
    to use a borrowed reference to tp_subclasses.
  • remove_all_subclasses() no longer accept NULL cases
  • type_set_bases() now relies on the fact that new_bases is not NULL.
  • type_dealloc_common() avoids PyErr_Fetch/PyErr_Restore if tp_bases
    is NULL.
  • remove_all_subclasses() makes sure that no exception is raised.
  • Don't test at runtime if tp_mro only contains types: rely on
    _PyType_CAST() assertion for that.
  • _PyStaticType_Dealloc() no longer clears tp_subclasses which is
    already NULL.
  • mro_hierarchy() avoids calling _PyType_GetSubclasses() if
    tp_subclasses is NULL.

Coding style:

  • Use Py_NewRef().
  • Add braces and move variable declarations to the first variable
    assignement.
  • Rename a few variables and parameters to use better names.

https://bugs.python.org/issue46417

* Add comment to recurse_down_subclasses() explaining why it's safe
  to use a borrowed reference to tp_subclasses.
* remove_all_subclasses() no longer accept NULL cases
* type_set_bases() now relies on the fact that new_bases is not NULL.
* type_dealloc_common() avoids PyErr_Fetch/PyErr_Restore if tp_bases
  is NULL.
* remove_all_subclasses() makes sure that no exception is raised.
* Don't test at runtime if tp_mro only contains types: rely on
  _PyType_CAST() assertion for that.
* _PyStaticType_Dealloc() no longer clears tp_subclasses which is
  already NULL.
* mro_hierarchy() avoids calling _PyType_GetSubclasses() if
  tp_subclasses is NULL.

Coding style:

* Use Py_NewRef().
* Add braces and move variable declarations to the first variable
  assignement.
* Rename a few variables and parameters to use better names.
@vstinner

Copy link
Copy Markdown
Member Author

@vstinner
vstinner merged commit 3a4c15b into python:main Jan 22, 2022
@vstinner
vstinner deleted the cleanup_typeobject branch January 22, 2022 17:56
@encukou

encukou commented Apr 8, 2024

Copy link
Copy Markdown
Member

In PyType_GetModuleByDef, the comment & assert is now out of date:

    // mro_invoke() ensures that the type MRO cannot be empty, so we don't have
    // to check i < PyTuple_GET_SIZE(mro) at the first loop iteration.
    assert(PyTuple_GET_SIZE(mro) >= 1);

With a for loop, the i < PyTuple_GET_SIZE(mro) check is done before each iteration.

@vstinner

vstinner commented Apr 8, 2024

Copy link
Copy Markdown
Member Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants