Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gh-118761: Improve import time for pstats and zipfile by removing imports to typing #128981

Merged
merged 4 commits into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions Lib/pstats.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
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"]

Expand Down Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions Lib/zipfile/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import sys
import threading
import time
from typing import Self

try:
import zlib # We may need its compression method
Expand Down Expand Up @@ -606,7 +605,7 @@ def from_file(cls, filename, arcname=None, *, strict_timestamps=True):

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
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Loading