mirror of
https://github.com/python/cpython.git
synced 2025-07-07 19:35:27 +00:00
GH-90117: Check for list and tuple before MappingView in pprint (GH-135779)
Some checks are pending
Tests / Change detection (push) Waiting to run
Tests / Docs (push) Blocked by required conditions
Tests / Check if Autoconf files are up to date (push) Blocked by required conditions
Tests / Windows MSI (push) Blocked by required conditions
Tests / Check if generated files are up to date (push) Blocked by required conditions
Tests / (push) Blocked by required conditions
Tests / Ubuntu SSL tests with OpenSSL (push) Blocked by required conditions
Tests / WASI (push) Blocked by required conditions
Tests / Hypothesis tests on Ubuntu (push) Blocked by required conditions
Tests / Address sanitizer (push) Blocked by required conditions
Tests / Undefined behavior sanitizer (push) Blocked by required conditions
Tests / Cross build Linux (push) Blocked by required conditions
Tests / CIFuzz (push) Blocked by required conditions
Tests / All required checks pass (push) Blocked by required conditions
Lint / lint (push) Waiting to run
mypy / Run mypy on Lib/_pyrepl (push) Waiting to run
mypy / Run mypy on Lib/test/libregrtest (push) Waiting to run
mypy / Run mypy on Lib/tomllib (push) Waiting to run
mypy / Run mypy on Tools/build (push) Waiting to run
mypy / Run mypy on Tools/cases_generator (push) Waiting to run
mypy / Run mypy on Tools/clinic (push) Waiting to run
mypy / Run mypy on Tools/jit (push) Waiting to run
mypy / Run mypy on Tools/peg_generator (push) Waiting to run
Some checks are pending
Tests / Change detection (push) Waiting to run
Tests / Docs (push) Blocked by required conditions
Tests / Check if Autoconf files are up to date (push) Blocked by required conditions
Tests / Windows MSI (push) Blocked by required conditions
Tests / Check if generated files are up to date (push) Blocked by required conditions
Tests / (push) Blocked by required conditions
Tests / Ubuntu SSL tests with OpenSSL (push) Blocked by required conditions
Tests / WASI (push) Blocked by required conditions
Tests / Hypothesis tests on Ubuntu (push) Blocked by required conditions
Tests / Address sanitizer (push) Blocked by required conditions
Tests / Undefined behavior sanitizer (push) Blocked by required conditions
Tests / Cross build Linux (push) Blocked by required conditions
Tests / CIFuzz (push) Blocked by required conditions
Tests / All required checks pass (push) Blocked by required conditions
Lint / lint (push) Waiting to run
mypy / Run mypy on Lib/_pyrepl (push) Waiting to run
mypy / Run mypy on Lib/test/libregrtest (push) Waiting to run
mypy / Run mypy on Lib/tomllib (push) Waiting to run
mypy / Run mypy on Tools/build (push) Waiting to run
mypy / Run mypy on Tools/cases_generator (push) Waiting to run
mypy / Run mypy on Tools/clinic (push) Waiting to run
mypy / Run mypy on Tools/jit (push) Waiting to run
mypy / Run mypy on Tools/peg_generator (push) Waiting to run
This commit is contained in:
parent
4e6f0d116e
commit
ee0e22c088
2 changed files with 35 additions and 34 deletions
|
@ -653,6 +653,40 @@ class PrettyPrinter:
|
||||||
del context[objid]
|
del context[objid]
|
||||||
return "{%s}" % ", ".join(components), readable, recursive
|
return "{%s}" % ", ".join(components), readable, recursive
|
||||||
|
|
||||||
|
if (issubclass(typ, list) and r is list.__repr__) or \
|
||||||
|
(issubclass(typ, tuple) and r is tuple.__repr__):
|
||||||
|
if issubclass(typ, list):
|
||||||
|
if not object:
|
||||||
|
return "[]", True, False
|
||||||
|
format = "[%s]"
|
||||||
|
elif len(object) == 1:
|
||||||
|
format = "(%s,)"
|
||||||
|
else:
|
||||||
|
if not object:
|
||||||
|
return "()", True, False
|
||||||
|
format = "(%s)"
|
||||||
|
objid = id(object)
|
||||||
|
if maxlevels and level >= maxlevels:
|
||||||
|
return format % "...", False, objid in context
|
||||||
|
if objid in context:
|
||||||
|
return _recursion(object), False, True
|
||||||
|
context[objid] = 1
|
||||||
|
readable = True
|
||||||
|
recursive = False
|
||||||
|
components = []
|
||||||
|
append = components.append
|
||||||
|
level += 1
|
||||||
|
for o in object:
|
||||||
|
orepr, oreadable, orecur = self.format(
|
||||||
|
o, context, maxlevels, level)
|
||||||
|
append(orepr)
|
||||||
|
if not oreadable:
|
||||||
|
readable = False
|
||||||
|
if orecur:
|
||||||
|
recursive = True
|
||||||
|
del context[objid]
|
||||||
|
return format % ", ".join(components), readable, recursive
|
||||||
|
|
||||||
if issubclass(typ, _collections.abc.MappingView) and r in self._view_reprs:
|
if issubclass(typ, _collections.abc.MappingView) and r in self._view_reprs:
|
||||||
objid = id(object)
|
objid = id(object)
|
||||||
if maxlevels and level >= maxlevels:
|
if maxlevels and level >= maxlevels:
|
||||||
|
@ -689,40 +723,6 @@ class PrettyPrinter:
|
||||||
del context[objid]
|
del context[objid]
|
||||||
return typ.__name__ + '([%s])' % ", ".join(components), readable, recursive
|
return typ.__name__ + '([%s])' % ", ".join(components), readable, recursive
|
||||||
|
|
||||||
if (issubclass(typ, list) and r is list.__repr__) or \
|
|
||||||
(issubclass(typ, tuple) and r is tuple.__repr__):
|
|
||||||
if issubclass(typ, list):
|
|
||||||
if not object:
|
|
||||||
return "[]", True, False
|
|
||||||
format = "[%s]"
|
|
||||||
elif len(object) == 1:
|
|
||||||
format = "(%s,)"
|
|
||||||
else:
|
|
||||||
if not object:
|
|
||||||
return "()", True, False
|
|
||||||
format = "(%s)"
|
|
||||||
objid = id(object)
|
|
||||||
if maxlevels and level >= maxlevels:
|
|
||||||
return format % "...", False, objid in context
|
|
||||||
if objid in context:
|
|
||||||
return _recursion(object), False, True
|
|
||||||
context[objid] = 1
|
|
||||||
readable = True
|
|
||||||
recursive = False
|
|
||||||
components = []
|
|
||||||
append = components.append
|
|
||||||
level += 1
|
|
||||||
for o in object:
|
|
||||||
orepr, oreadable, orecur = self.format(
|
|
||||||
o, context, maxlevels, level)
|
|
||||||
append(orepr)
|
|
||||||
if not oreadable:
|
|
||||||
readable = False
|
|
||||||
if orecur:
|
|
||||||
recursive = True
|
|
||||||
del context[objid]
|
|
||||||
return format % ", ".join(components), readable, recursive
|
|
||||||
|
|
||||||
rep = repr(object)
|
rep = repr(object)
|
||||||
return rep, (rep and not rep.startswith('<')), False
|
return rep, (rep and not rep.startswith('<')), False
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Speed up :mod:`pprint` for :class:`list` and :class:`tuple`.
|
Loading…
Add table
Add a link
Reference in a new issue