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

Conversation

Projects
None yet
2 participants
@blueyed
Contributor

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

This comment has been minimized.

Show comment
Hide comment
@paltman

paltman Oct 5, 2017

Member

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.

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

This comment has been minimized.

Show comment
Hide comment
@blueyed

blueyed Oct 5, 2017

Contributor

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).

Contributor

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

This comment has been minimized.

Show comment
Hide comment
@blueyed

blueyed Oct 9, 2017

Contributor

@paltman
ping

Contributor

blueyed commented Oct 9, 2017

@paltman
ping

@paltman

This comment has been minimized.

Show comment
Hide comment
@paltman

paltman Oct 9, 2017

Member

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
        )
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

This comment has been minimized.

Show comment
Hide comment
@blueyed

blueyed Oct 10, 2017

Contributor

Amended and added basic tests.

Contributor

blueyed commented Oct 10, 2017

Amended and added basic tests.

@paltman

This comment has been minimized.

Show comment
Hide comment
@paltman

paltman Oct 10, 2017

Member

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

Member

paltman commented Oct 10, 2017

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

@blueyed

This comment has been minimized.

Show comment
Hide comment
@blueyed

blueyed Oct 10, 2017

Contributor

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='')"
Contributor

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

This comment has been minimized.

Show comment
Hide comment
@codecov

codecov bot 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.

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

models: use python_2_unicode_compatible decorator with all
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

models: use python_2_unicode_compatible decorator with all
This applies the python_2_unicode_compatible decorator to all models
through the base StripeObject.

Helps with pinax#382.
Add __repr__ methods
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

This comment has been minimized.

Show comment
Hide comment
@blueyed

blueyed Oct 17, 2017

Contributor

This is really helpul while debugging btw!

Contributor

blueyed commented Oct 17, 2017

This is really helpul while debugging btw!

@paltman paltman added this to the Samwise milestone Oct 20, 2017

@blueyed blueyed referenced this pull request Oct 20, 2017

Merged

Add discount objects #19

@paltman paltman merged commit 081dba7 into pinax:master Oct 20, 2017

16 checks passed

ci/circleci: lint Your tests passed on CircleCI!
Details
ci/circleci: py27dj110 Your tests passed on CircleCI!
Details
ci/circleci: py27dj111 Your tests passed on CircleCI!
Details
ci/circleci: py27dj18 Your tests passed on CircleCI!
Details
ci/circleci: py33dj18 Your tests passed on CircleCI!
Details
ci/circleci: py34dj110 Your tests passed on CircleCI!
Details
ci/circleci: py34dj111 Your tests passed on CircleCI!
Details
ci/circleci: py34dj18 Your tests passed on CircleCI!
Details
ci/circleci: py35dj110 Your tests passed on CircleCI!
Details
ci/circleci: py35dj111 Your tests passed on CircleCI!
Details
ci/circleci: py35dj18 Your tests passed on CircleCI!
Details
ci/circleci: py35djmaster Your tests passed on CircleCI!
Details
ci/circleci: py36dj111 Your tests passed on CircleCI!
Details
ci/circleci: py36djmaster Your tests passed on CircleCI!
Details
codecov/patch 100% of diff hit (target 99.39%)
Details
codecov/project 99.39% (+<.01%) compared to fda68d4
Details

@blueyed blueyed deleted the blueyed:repr branch Oct 20, 2017

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