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

Defer import of json and platform #503

Merged
merged 6 commits into from
Sep 11, 2024
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
8 changes: 5 additions & 3 deletions importlib_metadata/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import email
import functools
import itertools
import json
import operator
import os
import pathlib
Expand All @@ -29,8 +28,6 @@
from itertools import starmap
from typing import Any, Iterable, List, Mapping, Match, Optional, Set, cast

from zipp.compat.overlay import zipfile

from . import _meta
from ._collections import FreezableDefaultDict, Pair
from ._compat import (
Expand Down Expand Up @@ -675,6 +672,9 @@ def origin(self):
return self._load_json('direct_url.json')

def _load_json(self, filename):
# Deferred for performance (python/importlib_metadata#503)
import json

return pass_none(json.loads)(
self.read_text(filename),
object_hook=lambda data: types.SimpleNamespace(**data),
Expand Down Expand Up @@ -777,6 +777,8 @@ def children(self):
return []

def zip_children(self):
from zipp.compat.overlay import zipfile

zip_path = zipfile.Path(self.root)
names = zip_path.root.namelist()
self.joinpath = zip_path.joinpath
Expand Down
1 change: 1 addition & 0 deletions newsfragments/503.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Deferred import of json
Loading