Skip to content

Commit 6722272

Browse files
committed
Defer urllib.parse in core/magics/code.py
`urlencode` has one caller, `%pastebin`, in the same function that already defers `urllib.request`. Importing it at module level cost 2.5 ms on every startup (6.7 ms and 30 modules in a cold interpreter, since `urllib.parse` pulls `ipaddress`). In a clean interpreter `import IPython.terminal.ipapp` goes from 485 to 482 modules; `urllib.parse` and `ipaddress` no longer appear at startup.
1 parent 4015f9d commit 6722272

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

IPython/core/magics/code.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import sys
2121
import ast
2222
from itertools import chain
23-
from urllib.parse import urlencode
2423
from pathlib import Path
2524

2625
# Our own packages
@@ -278,6 +277,7 @@ def pastebin(self, parameter_s=''):
278277
-e: Pass number of days for the link to be expired.
279278
The default will be 7 days.
280279
"""
280+
from urllib.parse import urlencode
281281
from urllib.request import Request
282282

283283
opts, args = self.parse_options(parameter_s, "d:e:")

0 commit comments

Comments
 (0)