Skip to content

Hide private fields in Struct.pformat() output#414

Open
goodboy wants to merge 1 commit intomainfrom
struct_field_filtering
Open

Hide private fields in Struct.pformat() output#414
goodboy wants to merge 1 commit intomainfrom
struct_field_filtering

Conversation

@goodboy
Copy link
Owner

@goodboy goodboy commented Feb 20, 2026

Skip fields starting with _ in pretty-printed struct output to
avoid cluttering console with internal/private state (and/or
accessing private properties which raise errors.

Impl 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

Pre-merge todo

  • unit test verifying only non-private fields are rendered in
    repr() output.

Copilot AI review requested due to automatic review settings February 20, 2026 00:37
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR enhances the Struct.pformat() method to hide private fields (those starting with _) from pretty-printed output, making struct representations cleaner and avoiding potential errors when accessing private properties.

Changes:

  • Add filtering to skip private fields (starting with _) in iter_struct_ppfmt_lines()
  • Refactor control flow from nested if to if/elif/else structure for clearer logic
  • Move yield statement inside the else block to ensure it only outputs non-private, non-nested fields

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@goodboy
Copy link
Owner Author

goodboy commented Feb 24, 2026

Hmm question is should we make a (unit) test for this?

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
@goodboy goodboy force-pushed the struct_field_filtering branch from dd86083 to f76e822 Compare March 8, 2026 23:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants