Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Develop cleanup 2 #82

Open
wants to merge 12 commits into
base: develop
Choose a base branch
from
Open

Conversation

maresb
Copy link
Contributor

@maresb maresb commented Sep 29, 2024

Following up from #66

class LabelMarginsPx(NamedTuple):
horizontal: int
vertical: int

Copy link
Contributor

Choose a reason for hiding this comment

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

According to Python docs, NamedTuple type hint is a "Typed version of collections.namedtuple()". See https://docs.python.org/3/library/typing.html#typing.NamedTuple

Don't you prefer to use collections.namedtuple, instead of a regular Python class?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good question. Some benefits:

  1. Types. With collections.namedtuple you just have names, without the types, so you wouldn't get type checking.
  2. Syntax. This behaves and looks like a normal Python class, but the init and string representation are managed for you. This also makes it easy to switch out with similar data containers, like pydantic.BaseModel in case you need input validation.

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