You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Replace type(literal) with corresponding builtin types #88878
There are several occurrences of type(literal) in the code of the stdlib where literal is a literal of built-in type: '', 1, [], {}, etc. I suppose it is a remnants of very old code written when str, int, list, dict, etc were functions and not classes.
The proposed PR replaces type(literal) with corresponding builtin types. It makes the code cleaner.
I consider also idea of replacing identity or equality checks ("is" or "==") with isinstance(). I suppose that that code was written when built-in types were not subclassable. But now there is a reason to use isinstance().
All cases was manually checked several times (with months passes between checks). Several cases were preserved: when the name of built-in type conflicted with the name of function parameter (in weakref.py), when the code was used for testing type() and when the test code looks clearer with type(literal).
Activity
serhiy-storchaka commentedon Jul 22, 2021
There are several occurrences of type(literal) in the code of the stdlib where literal is a literal of built-in type: '', 1, [], {}, etc. I suppose it is a remnants of very old code written when str, int, list, dict, etc were functions and not classes.
The proposed PR replaces
type(literal)with corresponding builtin types. It makes the code cleaner.I consider also idea of replacing identity or equality checks ("is" or "==") with isinstance(). I suppose that that code was written when built-in types were not subclassable. But now there is a reason to use isinstance().
See also bpo-44711.
serhiy-storchaka commentedon Jul 22, 2021
All cases was manually checked several times (with months passes between checks). Several cases were preserved: when the name of built-in type conflicted with the name of function parameter (in weakref.py), when the code was used for testing type() and when the test code looks clearer with type(literal).
[3.11] pythongh-88878: IDLE - replace type('') with str
[3.11] gh-88878: IDLE - replace type('') with str (#95792)
[3.11] pythongh-88878: IDLE - replace type('') with str (pythonGH-95792)
[3.11] gh-88878: IDLE - replace type('') with str (GH-95792)