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: Refactor typing._SpecialForm
Type: enhancement Stage: resolved
Components: Library (Lib) Versions: Python 3.9
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: gvanrossum, levkivskyi, serhiy.storchaka
Priority: normal Keywords: patch

Created on 2020-04-20 11:27 by serhiy.storchaka, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 19620 merged serhiy.storchaka, 2020-04-20 11:29
Messages (2)
msg366817 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2020-04-20 11:27
The proposed PR refactors the implementation of typing._SpecialForm.

Different special forms are different by name, docstring, and the behavior of __getitem__. Instead of special casing by name in __getitem__, instances are now parametrized by the implementation of __getitem__. _SpecialForm is now used as a decorator and takes the name and the docstring from the decorated function. It looks nicer to me now.

Also removed implementations of some methods:

* Inheriting from _Immutable no longer needed because __reduce__ makes instance atomic for copying.

* __new__ was only needed when _SpecialForm was a subclass of type. It prevented using it as a metaclass. Now it is no longer needed.

* Docstring is now assigned directly to the __doc__ slot. Previously it conflicted with the class docstring, but now the class docstring was converted into the class comment. _SpecialForm is not a public class, and pydoc shows the class comment if there is no a class docstring.

* __eq__ and __hash__ are no longer needed. Instances are singletons, and comparing by identity works as well as comparing by name. They could be needed before implementing __reduce__().

* __call__ no longer needed. Instances are not callable, and the error message is good enough. The bonus -- callable() now returns False.
msg367138 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2020-04-23 18:26
New changeset 40ded947f82683f0ed08144599a83d3a1ce719eb by Serhiy Storchaka in branch 'master':
bpo-40336: Refactor typing._SpecialForm (GH-19620)
https://github.com/python/cpython/commit/40ded947f82683f0ed08144599a83d3a1ce719eb
History
Date User Action Args
2022-04-11 14:59:29adminsetgithub: 84516
2020-04-23 18:28:05serhiy.storchakasetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2020-04-23 18:26:54serhiy.storchakasetmessages: + msg367138
2020-04-20 11:29:32serhiy.storchakasetkeywords: + patch
stage: patch review
pull_requests: + pull_request18950
2020-04-20 11:27:57serhiy.storchakacreate