Skip to content

Commit 1cab18f

Browse files
committed
validators: avoid urllib.request at import-time
This change improves jsonschema import time by ~50ms. On my end calling: python -X importtime -c "import jsonschema" * Before: 234ms * After: 173ms
1 parent 278fc0a commit 1cab18f

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

jsonschema/validators.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
from operator import methodcaller
1010
from typing import TYPE_CHECKING
1111
from urllib.parse import unquote, urldefrag, urljoin, urlsplit
12-
from urllib.request import urlopen
1312
from warnings import warn
1413
import contextlib
1514
import json
@@ -1225,6 +1224,7 @@ def resolve_remote(self, uri):
12251224
result = requests.get(uri).json()
12261225
else:
12271226
# Otherwise, pass off to urllib and assume utf-8
1227+
from urllib.request import urlopen
12281228
with urlopen(uri) as url: # noqa: S310
12291229
result = json.loads(url.read().decode("utf-8"))
12301230

0 commit comments

Comments
 (0)