Skip to content

Show only non-defaults when omit_defaults is set #309

Closed

Description

@rsmb7z

Description

Hi,
When omit_defaults=True is set, it works for the encoding however repr shows all the types. It would be good to show only non-default values in repr when this flag is set.

Activity

  1. jcrist commented on Feb 10, 2023

    @jcrist
    Member

    Can you say more about why you'd want that behavior? What's your use case?

    I'm not sure coupling a simpler repr to omit_defaults makes sense (omit_defaults is about encoding, not repr-ing). I'd thought about omitting default values from the repr for all structs, but nixed it since neither dataclasses, attrs, nor pydantic do this.

  2. rsmb7z commented on Feb 10, 2023

    @rsmb7z
    Author

    Hi @jcrist
    Yes I understand that omit_defaults is specific to encoding originally however having different flag will be okay too.
    Similar to performance improvment with omit_defaults during encoding, I would prefer to view only arguments which are non-defaults. Expected behavior you will find here for Contract class.
    https://github.com/erdewit/ib_insync/blob/master/ib_insync/contract.py

  3. jcrist commented on Feb 16, 2023

    @jcrist
    Member

    I've added a new repr_omit_defaults option in #322 that should do what you want.

  4. ml31415 commented on Mar 30, 2024

    @ml31415

    This new option should probably be mentioned in the docs on the website as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions