Text class: changed __str__ method and added __repr__ method #6068

Merged
merged 2 commits into from Feb 28, 2016

Conversation

Projects
None yet
4 participants
Contributor

jonchar commented Feb 27, 2016

This should address #6042

According to the Python docs for __repr__ and __str__: print() will output what is returned by __str__, while __repr__ should return a string that looks like a valid python expression. The text class currently has a __str__ but no __repr__. This changes the existing __str__ method into __repr__ (which returns Text(x_coord, y_coord, "string")) and adds a new __str__ method that returns self._text, which achieves the behavior requested in #6042 .

This would result in the following behavior:

>>> text
Text(x_coord,y_coord,"String in self._text")
>>> print(text)
String in self._text

Thoughts?

@jonchar jonchar Text class: changed __str__ method to return self._text and added __r…
…epr__ method.
44604ce

mdboom added the needs_review label Feb 27, 2016

Owner

tacaswell commented Feb 27, 2016

👍 on the change __repr__, 50/50 on __str__ just returning the text. What is the use case for wanting to print a Text instance and have the fact that it is a Text instance hidden?

Contributor

jonchar commented Feb 27, 2016

I was going on what was requested in #6042, however I can't think of when it would be useful for print to hide the fact that it's a Text instance and not a string. Maybe just keep __repr__ and leave out __str__? If there's no __str__ defined __repr__ will be used instead.

Owner

tacaswell commented Feb 27, 2016

I like the option of just dropping __str__.

@jonchar jonchar Text class: removed __str__ method in favor of __repr__.
472d3cb
Contributor

jonchar commented Feb 28, 2016

__str__ method has been dropped in favor of __repr__

@tacaswell tacaswell added a commit that referenced this pull request Feb 28, 2016

@tacaswell tacaswell Merge pull request #6068 from jonchar/text-repr-str-patch
MNT: remane __str__ to __repr__ for Text
90a6984

@tacaswell tacaswell merged commit 90a6984 into matplotlib:master Feb 28, 2016

2 checks passed

continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details

tacaswell removed the needs_review label Feb 28, 2016

Owner

tacaswell commented Feb 28, 2016

Thanks!

On Sun, Feb 28, 2016, 10:35 Jon Charest notifications@github.com wrote:

str method has been dropped in favor of repr


Reply to this email directly or view it on GitHub
#6068 (comment)
.

QuLogic added this to the 2.1 (next point release) milestone Feb 28, 2016

QuLogic added the text label Feb 28, 2016

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