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

Add __repr__ methods #382

Merged
merged 1 commit into from Oct 20, 2017
Merged

Add __repr__ methods #382

merged 1 commit into from Oct 20, 2017

Conversation

blueyed
Copy link
Contributor

@blueyed blueyed commented Oct 5, 2017

This is only done for Plan, Customer and Subscription for now, and open
for discussion.

It helps a lot when debugging and/or looking at locals in tracebacks.

TODO:

  • tests

@paltman
Copy link
Member

paltman commented Oct 5, 2017

I’m generally in favor of this.

Any objection to using format() instead of %?

Also style wise I prefer skipping the multi line string, then making the argument list one argument per line as it’s easier to scan.

@blueyed
Copy link
Contributor Author

blueyed commented Oct 5, 2017

You mean like

     def __repr__(self):
-        return ('Plan(pk=%r, name=%r, amount=%r, currency=%r, interval=%r, '
-                'interval_count=%r, trial_period_days=%r, stripe_id=%r)' % (
-                    self.pk, self.name, self.amount, self.currency,
-                    self.interval, self.interval_count,
-                    self.trial_period_days, self.stripe_id))
+        return ('Plan(pk={!r}, name={!r}, amount={!r}, currency={!r}, interval={!r}, '
+                'interval_count={!r}, trial_period_days={!r}, stripe_id={!r})'.format(
+                    self.pk,
+                    self.name,
+                    self.amount,
+                    self.currency,
+                    self.interval,
+                    self.interval_count,
+                    self.trial_period_days,
+                    self.stripe_id))

?

IMHO it makes the whole file harder to scan (by adding more lines).

@blueyed
Copy link
Contributor Author

blueyed commented Oct 9, 2017

@paltman
ping

@paltman
Copy link
Member

paltman commented Oct 9, 2017

No, more like:

    def __repr__(self):
        return "Plan(pk={!r}, name={!r}, amount={!r}, currency={!r}, interval={!r}, interval_count={!r}, trial_period_days={!r}, stripe_id={!r})".format(
            self.pk,
            self.name,
            self.amount,
            self.currency,
            self.interval,
            self.interval_count,
            self.trial_period_days,
            self.stripe_id
        )

@blueyed blueyed force-pushed the repr branch 2 times, most recently from fa34aec to 3431bfc Compare Oct 10, 2017
@blueyed
Copy link
Contributor Author

blueyed commented Oct 10, 2017

Amended and added basic tests.

@paltman
Copy link
Member

paltman commented Oct 10, 2017

Hit by string string differences in py2 and py3 on the tests.

@blueyed
Copy link
Contributor Author

blueyed commented Oct 10, 2017

How to handle this best?

AssertionError: "Plan(pk=None, name=u'My Plan', amount=Decimal('5'), currency=u'', interval=u'monthly', interval_count=1, trial_period_days=None, stripe_id=u'')" !=
               u"Plan(pk=None, name='My Plan', amount=Decimal('5'), currency='', interval='monthly', interval_count=1, trial_period_days=None, stripe_id='')"

@codecov
Copy link

codecov bot commented Oct 17, 2017

Codecov Report

Merging #382 into master will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #382      +/-   ##
==========================================
+ Coverage   99.39%   99.39%   +<.01%     
==========================================
  Files          34       34              
  Lines        1651     1662      +11     
  Branches      134      135       +1     
==========================================
+ Hits         1641     1652      +11     
  Misses          5        5              
  Partials        5        5
Flag Coverage Δ
#py27dj110 99.39% <100%> (ø) ⬆️
#py27dj111 99.39% <100%> (ø) ⬆️
#py27dj18 99.39% <100%> (ø) ⬆️
#py33dj18 99.39% <100%> (ø) ⬆️
#py34dj110 99.39% <100%> (ø) ⬆️
#py34dj111 99.39% <100%> (ø) ⬆️
#py34dj18 99.39% <100%> (ø) ⬆️
#py35dj110 99.39% <100%> (ø) ⬆️
#py35dj111 99.39% <100%> (ø) ⬆️
#py35dj18 99.39% <100%> (ø) ⬆️
#py35djmaster 99.39% <100%> (ø) ⬆️
#py36dj111 99.39% <100%> (ø) ⬆️
#py36djmaster 99.39% <100%> (ø) ⬆️
Impacted Files Coverage Δ
pinax/stripe/models.py 100% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update fda68d4...0e922b9. Read the comment docs.

blueyed added a commit to blueyed/pinax-stripe that referenced this pull request Oct 17, 2017
This applies the python_2_unicode_compatible decorator to all models
through the base StripeObject.

Helps with pinax#382.
blueyed added a commit to blueyed/pinax-stripe that referenced this pull request Oct 17, 2017
This applies the python_2_unicode_compatible decorator to all models
through the base StripeObject.

Helps with pinax#382.
This is only done for Plan, Customer and Subscription for now, and open
for discussion.

It helps a lot when debugging and/or looking at locals in tracebacks.
@blueyed
Copy link
Contributor Author

blueyed commented Oct 17, 2017

This is really helpul while debugging btw!

@paltman paltman added this to the Samwise milestone Oct 20, 2017
@paltman paltman merged commit 081dba7 into pinax:master Oct 20, 2017
@blueyed blueyed deleted the repr branch Oct 20, 2017
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.

None yet

2 participants