mirror of
https://github.com/python/cpython.git
synced 2025-07-07 19:35:27 +00:00
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`.
This commit is contained in:
parent
d3adf02c90
commit
d5e9aa690a
2 changed files with 4 additions and 1 deletions
|
@ -63,7 +63,6 @@ SETTINGS:
|
||||||
written as two quotes
|
written as two quotes
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import re
|
|
||||||
import types
|
import types
|
||||||
from _csv import Error, writer, reader, register_dialect, \
|
from _csv import Error, writer, reader, register_dialect, \
|
||||||
unregister_dialect, get_dialect, list_dialects, \
|
unregister_dialect, get_dialect, list_dialects, \
|
||||||
|
@ -281,6 +280,7 @@ class Sniffer:
|
||||||
If there is no quotechar the delimiter can't be determined
|
If there is no quotechar the delimiter can't be determined
|
||||||
this way.
|
this way.
|
||||||
"""
|
"""
|
||||||
|
import re
|
||||||
|
|
||||||
matches = []
|
matches = []
|
||||||
for restr in (r'(?P<delim>[^\w\n"\'])(?P<space> ?)(?P<quote>["\']).*?(?P=quote)(?P=delim)', # ,".*?",
|
for restr in (r'(?P<delim>[^\w\n"\'])(?P<space> ?)(?P<quote>["\']).*?(?P=quote)(?P=delim)', # ,".*?",
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
Reduce the import time of :mod:`csv` by up to five times, by importing
|
||||||
|
:mod:`re` on demand. In particular, ``re`` is no more implicitly exposed
|
||||||
|
as ``csv.re``. Patch by Bénédikt Tran.
|
Loading…
Add table
Add a link
Reference in a new issue