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

Appearance settings

gh-94343: Ease initialization of reprlib.Repr attributes #94581

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

Merged
merged 7 commits into from
Jul 7, 2022

Conversation

finefoot
Copy link
Contributor

@finefoot finefoot commented Jul 5, 2022

finefoot added 5 commits July 5, 2022 20:40
Since the keyword arguments now show up in the docs, the order should reflect their usage frequency to some degree
@finefoot finefoot marked this pull request as ready for review July 6, 2022 01:22
attributes of the :class:`Repr` instance. Which means that the following
initialization::

aRepr = reprlib.Repr(maxlevel=3)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the example can be omitted because it's both fairly obvious and consistent with many other classes in standard lib.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for taking a look! :) I fully agree that it is "fairly obvious". However, regarding "consistent with many other classes in standard"... I actually couldn't find or come up with any but one object in the stdlib were you can set an object's attribute via keyword argument during initialization. That's why I included the example code. Maybe I just didn't search well enough? Which stdlib objects did you have in mind?

Copy link
Contributor

Choose a reason for hiding this comment

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

You are welcome; for example datetime.timedelta(days=1) ...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's a different case, though, isn't it? You must write that as datetime.timedelta(days=1) because:

dt = datetime.timedelta()
dt.days = 1  # AttributeError: readonly attribute

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok, then look at calendar.Calendar(firstweekday=1)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's a very interesting example, thank you. :) I definitely looked at the docs for calendar, when I was researching how other stdlib classes describe attributes set by keyword arguments. But I must have missed this one because looking at https://docs.python.org/3/library/calendar.html, it seems like the firstweekday property is not listed as an attribute at all? It is mentioned in the description for the iterweekdays method, but otherwise doesn't show up. The constructor only describes it as a keyword argument and further above it says to use calendar.setfirstweekday to set the default for calendar.c but the setter method calendar.Calendar.setfirstweekday for the Calendar class is not described anywhere. Classes TextCalendar and HTMLCalendar don't mention that they're subclasses of Calendar. To be honest, I think the docs for calendar could use a few fixes themselves and in their current form, I wouldn't want to use them as a guide how to write the docs for this reprlib extension.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

To be clear: I don't feel strongly about leaving the example in. It's a valid point you're raising. However, I still haven't found any stdlib class that uses attributes and keyword arguments in the same way that reprlib.Repr does. Therefore, a precedent on how the docs should handle such a case is missing, too. If it's okay with you, I'd not remove the lines with the example code for now, keep this conversation thread marked "unresolved" and just leave the final decision up to the core dev review.

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.

4 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.