Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Added __repr__ implementation on all locators and formators#25767

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
Daniil-Aleshechkin wants to merge33 commits intomatplotlib:main
base:main
Choose a base branch
Loading
fromDaniil-Aleshechkin:added-repr-implementation-on-all-locators-and-formators

Conversation

Daniil-Aleshechkin
Copy link

  • PR Summary

Added aninit_subclass implementation on the TickerHelper class that creates a wrapper over all the subclass'init methods. I'm assuming the following:

  1. All parameters will haverepr implemented now and in the future. Basically they will be restricted to base types like ints, strs... etc
  2. The initialized paramters will not change. Essentially therepr function will be how the class was inited.

Thiscloses#21898

PR Checklist

Linked Issue

  • Added "closes #0000" in the PR description to link it to the original issue.

Documentation and Tests

  • Has pytest style unit tests (andpytest passes)
  • Documentation is sphinx and numpydoc compliant (the docs shouldbuild without error).
  • New plotting related features are documented with examples.

Release Notes

  • New features are marked with a.. versionadded:: directive in the docstring and documented indoc/users/next_whats_new/
  • [N/A] API changes are marked with a.. versionchanged:: directive in the docstring and documented indoc/api/next_api_changes/
  • Release notes conform with instructions innext_whats_new/README.rst ornext_api_changes/README.rst

@Daniil-Aleshechkin
Copy link
Author

For unit testing because of the nature of the feature, any parameters that get added/ changed in anyway will be coupled to the test, can someone recommend some safe classes that I can use?

Copy link

@github-actionsgithub-actionsbot left a comment

Choose a reason for hiding this comment

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

Thank you for opening your first PR into Matplotlib!

If you have not heard from us in a while, please feel free to ping@matplotlib/developers or anyone who has commented on the PR. Most of our reviewers are volunteers and sometimes things fall through the cracks.

You can also join uson gitter for real-time discussion.

For details on testing, writing docs, and our review process, please seethe developer guide

We strive to be a welcoming and open project. Please follow ourCode of Conduct.

@story645
Copy link
Member

I think an easy test is seeing if you can reproduce the locator and formatter examples (e.g.https://matplotlib.org/devdocs/gallery/ticks/tick-locators.html), but replace the titles with the reprs.

@ksunden
Copy link
Member

This is modifying the reported runtime signature of all Formatters to haveFormatter.__init__(*args, **kwargs) as the only signature reported, rather than having a more informative runtime inspectable signature.

Comment on lines 2944 to 2946
tmin = ((vmin - t0) // minorstep + 1) * minorstep
tmax = ((vmax - t0) // minorstep + 1) * minorstep
locs = np.arange(tmin, tmax, minorstep) + t0
Copy link
Member

Choose a reason for hiding this comment

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

This change seems unreleated, though I think it was included in a different recent PR

Choose a reason for hiding this comment

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

Must have been an artifact when I set the branch up. I'll remove it

@Daniil-Aleshechkin
Copy link
Author

This is modifying the reported runtime signature of all Formatters to haveFormatter.__init__(*args, **kwargs) as the only signature reported, rather than having a more informative runtime inspectable signature.

Yea I think I need to rebind the signature to my wrappers. Would doing something like.

wrapper = _init_repr_wrapperwrapper.__signature__ = inspect.signature(originalInit)

work?

@ksunden
Copy link
Member

That may work, but the more standard/complete way of doing it is to usefunctools.wraps, as the code fromthe original issue does.

@Daniil-Aleshechkin
Copy link
Author

That may work, but the more standard/complete way of doing it is to usefunctools.wraps, as the code fromthe original issue does.

Gotcha I'll give that a shot

@Daniil-Aleshechkin
Copy link
Author

That may work, but the more standard/complete way of doing it is to usefunctools.wraps, as the code fromthe original issue does.

Seems like it fixed the wrapping issue, but now I have the problem where args is added to the signature when I think I'm creating an init method for classes that don't have one defined. Not sure exactly what's going on, because I still get the same issue when I don't add anything from this commit:d3aef45

@Daniil-Aleshechkin
Copy link
Author

That may work, but the more standard/complete way of doing it is to usefunctools.wraps, as the code fromthe original issue does.

Seems like it fixed the wrapping issue, but now I have the problem where args is added to the signature when I think I'm creating an init method for classes that don't have one defined. Not sure exactly what's going on, because I still get the same issue when I don't add anything from this commit:d3aef45

I figured it out after my morning run today :)

Basically checking for null doesn't account for the case when we inherit aninit method. My solution is I added a marker property and checked for it. I don't want to add it to the stubs though because it's only used for this. Is there a better / standard way of adding an arbitrary marker to the function?

@story645story645 self-assigned thisApr 30, 2023
@QuLogic
Copy link
Member

Basically checking for null doesn't account for the case when we inherit aninit method. My solution is I added a marker property and checked for it. I don't want to add it to the stubs though because it's only used for this. Is there a better / standard way of adding an arbitrary marker to the function?

I think you'll want to be checkingif '__init__' in cls.__dict__.

@tacaswell
Copy link
Member

This is very nice technical work, however the__repr__ should represent what the current state of the objects are not what what it was initialized with! A user that is looking at a (nice looking) repr of an object is going to have the expectation that that repr represents the current state of that object, not the state of the object at some point in the past!

Unfortunately I think the solution here is much less sophisticated and much more rote: write__repr__ methods for each class. If we also add__eq__ methods we can test thateval(repr(obj)) == obj and I agree with the suggestion that in the locator / formatter example being able to use the title ofrepr(obj) is a good manual visualization that it still looks good.

This does bring up the issue that there are attributes on these objects that influence how they render (and thus knowing the repr of two objects is the same is not enough to be sure that they are functionally the same), but I think that it is fair to say that is (well) out of scope.

@Daniil-Aleshechkin I'm sorry we led you down this path and asked you to do a bunch of work that is not going to land in its current state 😞

@story645
Copy link
Member

story645 commentedMay 4, 2023
edited
Loading

@tacaswell, just a heads up that needing to be current state was discussed in the issue and@Daniil-Aleshechkin already prototyped something there#21898 (comment)

@Daniil-AleshechkinDaniil-Aleshechkinforce-pushed theadded-repr-implementation-on-all-locators-and-formators branch frome8f2a0a to23d9ba9CompareMay 8, 2023 16:12
@Daniil-Aleshechkin
Copy link
Author

Not sure exactly what's going on but is the test agent in a bad state? Only the python 3.10 agent is throwing an exception: "Traceback (most recent call last):\n File "", line 1, in \n File "/Users/runner/work/1/s/lib/matplo...ion (%s) doesn't match libtk.a version (%s)"\nRuntimeError: tk.h version (8.5) doesn't match libtk.a version (8.6)\n"

@QuLogic
Copy link
Member

That's a known issue, but the other test failures are for the new tests here.

@Daniil-Aleshechkin
Copy link
Author

That's a known issue, but the other test failures are for the new tests here.

Managed to fix those. Do we know how to fix this issue?

@QuLogic
Copy link
Member

That's up to Microsoft.

@@ -287,6 +287,9 @@ class ThetaLocator(mticker.Locator):
locations of every 45 degrees are returned.
"""

def __repr__(self):
return f"{self.__class__.__name__}(base={self.base.__repr__()})"
Copy link
Member

Choose a reason for hiding this comment

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

These__repr__ should all be:

Suggested change
returnf"{self.__class__.__name__}(base={self.base.__repr__()})"
returnf"{self.__class__.__name__}(base={self.base!r})"

@story645
Copy link
Member

ping@Daniil-Aleshechkin any bandwidth for continuing with this?

@Daniil-Aleshechkin
Copy link
Author

Daniil-Aleshechkin commentedJun 27, 2023
edited
Loading

ping@Daniil-Aleshechkin any bandwidth for continuing with this?

Ah completely forgot about this. I stopped working on it cause I was blocked on that issue with the python 3.10 test runner. Did that get resolved? If so, I can resume working :)

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

@QuLogicQuLogicQuLogic left review comments

@github-actionsgithub-actions[bot]github-actions[bot] left review comments

@tacaswelltacaswellAwaiting requested review from tacaswell

@ksundenksundenAwaiting requested review from ksunden

Requested changes must be addressed to merge this pull request.

Assignees

@story645story645

Projects
Status: Waiting for author
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

Reprs on formatters and locaters
6 participants
@Daniil-Aleshechkin@story645@ksunden@QuLogic@tacaswell@Daniil-Aleshechkin-IQ

[8]ページ先頭

©2009-2025 Movatter.jp