-
Notifications
You must be signed in to change notification settings - Fork 172
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
Behavior of immutable attributes #237
Behavior of immutable attributes #237
Conversation
6c788c1
to
5bb2378
Compare
Codecov Report
@@ Coverage Diff @@
## master #237 +/- ##
==========================================
+ Coverage 88.77% 88.79% +0.02%
==========================================
Files 6 6
Lines 490 491 +1
Branches 54 54
==========================================
+ Hits 435 436 +1
Misses 40 40
Partials 15 15
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, looks like a good idea. @jonashaag are you good to merge?
Is there something similar or identical in Django? Is copying a common approach in the Django codebase? |
When mutable class level attributes are returned by instance methods they are generally copied, e.g. see This commit differs from Django in that it is using |
Thank you! Shouldn’t we use |
Yes, I think you're right! I like how asking the right question gets the right answer :-) @CleitonDeLima would you re-write this to use |
Hi @sdolemelipone , a = (1, 2, 3)
id(a) == id(a[:]) # is True |
Thanks! LGTM. Just as a side discussion, as tuples are immutable, does the |
Of course! I'm getting in my way on basic concepts, treat the problem with |
Even better! 😄 Thanks, I hadn't thought about what happens when you call |
I'd have preferred the explicit |
Interesting! Why, because explicit is better than implicit? For me from copy import copy
a = (1, 2, 3)
id(a) == id(copy(a)) # is True |
Yes, and because it’s done that way in the Django codebase. Needlessly doing things differently in one place than in the other increases chances of creating bugs, adds to the mental load of readers, etc. |
When using
get_inlines
andget_inlines_names
, a new copy of the object is returned, avoiding changing the class attribute.