8000 gh-118761: Improve import time for `csv` (#128858) · python/cpython@d5e9aa6 · GitHub
[go: up one dir, main page]

Skip to content

Commit d5e9aa6

Browse files
authored
gh-118761: Improve import time for csv (#128858)
This reduces the import time of the `csv` module by up to five times, by importing `re` on demand. In particular, the `re` module is no more implicitly exposed as `csv.re`.
1 parent d3adf02 commit d5e9aa6

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

Lib/csv.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ class excel:
6363
written as two quotes
6464
"""
6565

66-
import re
6766
import types
6867
from _csv import Error, writer, reader, register_dialect, \
6968
unregister_dialect, get_dialect, list_dialects, \
@@ -281,6 +280,7 @@ def _guess_quote_and_delimiter(self, data, delimiters):
281280
If there is no quotechar the delimiter can't be determined
282281
this way.
283282
"""
283+
import re
284284

285285
matches = []
286286
for restr in (r'(?P<delim>[^\w\n"\'])(?P<space> ?)(?P<quote>["\']).*?(?P=quote)(?P=delim)', # ,".*?",
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Reduce the import time of :mod:`csv` by up to five times, by importing
2+
:mod:`re` on demand. In particular, ``re`` is no more implicitly exposed
3+
as ``csv.re``. Patch by Bénédikt Tran.

0 commit comments

Comments
 (0)
0