Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-90117: handle dict and mapping views in pprint#30135

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
gpshead merged 45 commits intopython:mainfromdevdanzin:pprint_dict_view
May 20, 2025
Merged
Changes from1 commit
Commits
Show all changes
45 commits
Select commitHold shift + click to select a range
f7835ca
Teach pprint about dict views with PrettyPrinter._pprint_dict_view an…
devdanzinDec 16, 2021
1eda2d5
Merge branch 'main' of https://github.com/python/cpython into pprint_…
devdanzinDec 17, 2021
9500a74
Use _private names for _dict_*_view attributes of PrettyPrinter.
devdanzinDec 17, 2021
653cdea
Use explicit 'items' keyword when calling _pprint_dict_view from _ppr…
devdanzinDec 18, 2021
884f224
📜🤖 Added by blurb_it.
blurb-it[bot]Dec 18, 2021
48be1e9
Properly indent code.
devdanzinJan 19, 2022
9745491
WIP: Improve tests and make short views sortable.
devdanzinJan 19, 2022
7edb29d
fix typo
merwokApr 24, 2022
7d2fa0f
Merge branch 'main' into pprint_dict_view
merwokApr 24, 2022
32773ce
Merge branch 'main' into pprint_dict_view
arhadthedevMar 4, 2023
15dd266
Address the failing Docs check
arhadthedevMar 4, 2023
6898bc4
Merge branch 'python:main' into pprint_dict_view
devdanzinApr 6, 2024
67e3f14
Add tests for collections.abc.[Keys|Items|Mapping|Values]View support…
devdanzinApr 7, 2024
65e0be2
Add support for collections.abc.[Keys|Items|Mapping|Values]View in pp…
devdanzinApr 7, 2024
c91af09
Split _pprint_dict_view into _pprint_abc_view, so pretty-printing nor…
devdanzinApr 7, 2024
5b2341c
Simplify redundant code.
devdanzinApr 7, 2024
a9ff3df
Add collections.abc views to some existing pprint tests.
devdanzinApr 7, 2024
4c67166
Remove TODO.
devdanzinApr 7, 2024
bfa9868
Test that views from collection.UserDict are correctly formatted by p…
devdanzinApr 7, 2024
148b469
Handle recursive dict and ABC views.
devdanzinApr 7, 2024
34abce7
Test that subclasses of ABC views work in pprint.
devdanzinApr 7, 2024
09839a6
Test dict views coming from collections.Counter.
devdanzinApr 7, 2024
091c3bb
Test ABC views coming from collections.ChainMap.
devdanzinApr 7, 2024
29655a0
Test odict views coming from collections.OrderedDict.
devdanzinApr 7, 2024
7ecb456
Merge branch 'main' into pprint_dict_view
devdanzinApr 8, 2024
646816a
Rename _pprint_abc_view to _pprint_mapping_abc_view.
devdanzinApr 8, 2024
7537a52
Add pprint test for mapping ABC views where ._mapping has a custom __…
devdanzinApr 9, 2024
7a6769d
When a mapping ABC view has a ._mapping that defines a custom __repr_…
devdanzinApr 9, 2024
7dcb9cf
Merge branch 'python:main' into pprint_dict_view
devdanzinApr 9, 2024
06babe4
Merge remote-tracking branch 'refs/remotes/origin/pprint_dict_view' i…
devdanzinApr 9, 2024
58692d2
Add tests for ABC mapping views subclasses that don't replace __repr_…
devdanzinApr 21, 2024
8e605c1
Simplify the pretty printing of ABC mapping views.
devdanzinApr 21, 2024
7e27e02
Merge branch 'python:main' into pprint_dict_view
devdanzinApr 21, 2024
eb66934
Merge remote-tracking branch 'refs/remotes/origin/pprint_dict_view' i…
devdanzinApr 21, 2024
1dc4ab2
Add a test for depth handling when pretty printing dict views.
devdanzinApr 21, 2024
f267452
Fix checking whether the view type is a subclass of an items view, ad…
devdanzinApr 22, 2024
3867338
Move construction of the views __repr__ set out of _safe_repr.
devdanzinApr 26, 2024
1a609d0
Merge branch 'main' into pprint_dict_view
devdanzinApr 26, 2024
bca6f6f
Merge remote-tracking branch 'refs/remotes/origin/pprint_dict_view' i…
devdanzinApr 26, 2024
d020f86
Merge branch 'python:main' into pprint_dict_view
devdanzinMay 21, 2024
ee7b521
Merge branch 'python:main' into pprint_dict_view
devdanzinMay 30, 2024
7009887
Merge branch 'python:main' into pprint_dict_view
devdanzinJul 1, 2024
9499115
Merge branch 'main' into pprint_dict_view
devdanzinOct 29, 2024
692c0cd
Merge branch 'main' into pprint_dict_view
AA-TurnerApr 20, 2025
90e069c
Merge branch 'main' into pprint_dict_view
gpsheadMay 20, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
PrevPrevious commit
NextNext commit
When a mapping ABC view has a ._mapping that defines a custom __repr_…
…_, dispatch pretty-printing it by that __repr__.
  • Loading branch information
@devdanzin
devdanzin committedApr 9, 2024
commit7a6769d41f78a7f94e9bac095d4324fa2153dce4
11 changes: 11 additions & 0 deletionsLib/pprint.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -262,6 +262,12 @@ def _pprint_dict_view(self, object, stream, indent, allowance, context, level):
def _pprint_mapping_abc_view(self, object, stream, indent, allowance, context, level):
"""Pretty print views from collections.abc."""
write = stream.write
# Dispatch formatting to the view's _mapping if it has a different __repr__
if object._mapping.__class__.__repr__ is not _collections.abc.MappingView.__repr__:
write(object.__class__.__name__ + '(')
self._format(object._mapping, stream, indent, allowance, context, level)
write(')')
return
write(object.__class__.__name__ + '({')
if self._indent_per_level > 1:
write((self._indent_per_level - 1) * ' ')
Expand DownExpand Up@@ -659,6 +665,11 @@ def _safe_repr(self, object, context, maxlevels, level):
key = _safe_tuple
format = typ.__name__ + '([%s])'
if typ in ABC_VIEW_TYPES:
# Dispatch formatting to the view's _mapping if it has a different __repr__
if object._mapping.__class__.__repr__ is not _collections.abc.MappingView.__repr__:
mapping_repr, readable, recursive = self.format(
object._mapping, context, maxlevels, level)
return (typ.__name__ + '(%s)' % mapping_repr), readable, recursive
format = typ.__name__ + '({%s})'
object = object._mapping.items()
if self._sort_dicts:
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp