]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-118761: Improve import time for `pstats` and `zipfile` (#128981)
authorBénédikt Tran <10796600+picnixz@users.noreply.github.com>
Thu, 23 Jan 2025 14:49:36 +0000 (15:49 +0100)
committerGitHub <noreply@github.com>
Thu, 23 Jan 2025 14:49:36 +0000 (14:49 +0000)
Importing `pstats` or `zipfile` is now roughly 20% faster.

This is achieved by removing type annotations depending on `typing`.

Lib/pstats.py
Lib/zipfile/__init__.py
Misc/NEWS.d/next/Library/2025-01-18-11-24-02.gh-issue-118761.G8MmxY.rst [new file with mode: 0644]

index 46e18fb7592a77eead74121ef9a9d6e006df0c5e..becaf35580eaee439b37c21e6538af4ecc888745 100644 (file)
@@ -29,7 +29,6 @@ import re
 from enum import StrEnum, _simple_enum
 from functools import cmp_to_key
 from dataclasses import dataclass
-from typing import Dict
 
 __all__ = ["Stats", "SortKey", "FunctionProfile", "StatsProfile"]
 
@@ -69,7 +68,7 @@ class FunctionProfile:
 class StatsProfile:
     '''Class for keeping track of an item in inventory.'''
     total_tt: float
-    func_profiles: Dict[str, FunctionProfile]
+    func_profiles: dict[str, FunctionProfile]
 
 class Stats:
     """This class is used for creating reports from data generated by the
index 49c40032d848f1a085728daff467ccc9786f9ba9..b8b496ad9471f4afa8214b91f2aecdf4d5b5308e 100644 (file)
@@ -13,7 +13,6 @@ import struct
 import sys
 import threading
 import time
-from typing import Self
 
 try:
     import zlib # We may need its compression method
@@ -606,7 +605,7 @@ class ZipInfo:
 
         return zinfo
 
-    def _for_archive(self, archive: ZipFile) -> Self:
+    def _for_archive(self, archive):
         """Resolve suitable defaults from the archive.
 
         Resolve the date_time, compression attributes, and external attributes
diff --git a/Misc/NEWS.d/next/Library/2025-01-18-11-24-02.gh-issue-118761.G8MmxY.rst b/Misc/NEWS.d/next/Library/2025-01-18-11-24-02.gh-issue-118761.G8MmxY.rst
new file mode 100644 (file)
index 0000000..3b3f3f7
--- /dev/null
@@ -0,0 +1,2 @@
+Reduce import time of :mod:`pstats` and :mod:`zipfile` by up to 20%, by
+removing unnecessary imports to :mod:`typing`. Patch by Bénédikt Tran.