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.

Title: Replace `type(literal)` with corresponding builtin types
Type: Stage: patch review
Components: Library (Lib) Versions: Python 3.11
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: serhiy.storchaka
Priority: normal Keywords: patch

Created on 2021-07-22 20:41 by serhiy.storchaka, last changed 2022-04-11 14:59 by admin.

Pull Requests
URL Status Linked Edit
PR 27294 open serhiy.storchaka, 2021-07-22 20:42
Messages (2)
msg398002 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2021-07-22 20:41
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 issue44711.
msg398003 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2021-07-22 20:54
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, when the code was used for testing type() and when the test code looks clearer with type(literal).
Date User Action Args
2022-04-11 14:59:47adminsetgithub: 88878
2021-07-22 20:54:43serhiy.storchakasetmessages: + msg398003
2021-07-22 20:42:31serhiy.storchakasetkeywords: + patch
stage: patch review
pull_requests: + pull_request25837
2021-07-22 20:41:11serhiy.storchakacreate