Hide private fields in `Struct.pformat()` output

Skip fields starting with `_` in pretty-printed struct output
to avoid cluttering displays with internal/private state (and/or accessing
private properties which have errors Bp).

Deats,
- add `if k[0] == '_': continue` check to skip private fields
- change nested `if isinstance(v, Struct)` to `elif` since we
  now have early-continue for private fields
- mv `else:` comment to clarify it handles top-level fields
- fix indentation of `yield` statement to only output
  non-private, non-nested fields

(this commit msg was generated in some part by [`claude-code`][claude-code-gh])
[claude-code-gh]: https://github.com/anthropics/claude-code
CONT_log_sys_testing
Gud Boi 2026-02-09 12:20:17 -05:00
parent fbf7ac76cd
commit 6ab4cffc8d
1 changed files with 10 additions and 6 deletions

View File

@ -126,13 +126,17 @@ def iter_struct_ppfmt_lines(
str(ft) str(ft)
).replace(' ', '') ).replace(' ', '')
if k[0] == '_':
continue
# recurse to get sub-struct's `.pformat()` output Bo # recurse to get sub-struct's `.pformat()` output Bo
if isinstance(v, Struct): elif isinstance(v, Struct):
yield from iter_struct_ppfmt_lines( yield from iter_struct_ppfmt_lines(
struct=v, struct=v,
field_indent=field_indent+field_indent, field_indent=field_indent+field_indent,
) )
else:
else: # top-level field
val_str: str = repr(v) val_str: str = repr(v)
# XXX LOL, below just seems to be f#$%in causing # XXX LOL, below just seems to be f#$%in causing
@ -149,10 +153,10 @@ def iter_struct_ppfmt_lines(
# raise # raise
# return _Struct.__repr__(struct) # return _Struct.__repr__(struct)
yield ( yield (
' '*field_indent, # indented ws prefix ' '*field_indent, # indented ws prefix
f'{k}: {typ_name} = {val_str},', # field's repr line content f'{k}: {typ_name} = {val_str},', # field's repr line content
) )
def pformat( def pformat(