-
-
Notifications
You must be signed in to change notification settings - Fork 483
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
Deprecate changereason #655
Conversation
Codecov Report
@@ Coverage Diff @@
## master #655 +/- ##
==========================================
- Coverage 97.51% 97.11% -0.40%
==========================================
Files 17 17
Lines 925 936 +11
Branches 138 140 +2
==========================================
+ Hits 902 909 +7
- Misses 10 13 +3
- Partials 13 14 +1
Continue to review full report at Codecov.
|
|
||
def get_change_reason_from_object(obj): | ||
if hasattr(obj, "_change_reason"): | ||
return getattr(obj, "_change_reason") |
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.
This could be return obj._change_reason
!
(or if this is called many times in loops, even more efficient would be try: return obj.change_reason except AttributeError: pass
)
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.
Agree on the latter - though this will be removed in next version anyway. How could this be return obj._change_reason
though? If that doesn't exist, it needs to check changeReason
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.
I was saying two things at once!
1: not reason to use getattr + string after you’ve already tested that the attribute exists
if hasattr(obj, "_change_reason"):
return obj._change_reason
2: if performance matters, you can avoid getting the attribute multiple times (hasattr under the covers tries to get the attr and catches AttributeError):
try:
return object._change_reason
except AttributeError:
pass
# rest of the code that tries changeReason
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.
Ah yes, good points.
" deprecated in 2.10.0 and will be removed in 3.0.0. Use " | ||
"_change_reason instead. " | ||
) | ||
warnings.warn(warning_msg, DeprecationWarning) |
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.
warnings most of the time need a stacklevel
parameter (usually with value 2, but depends on the calling pattern) so that the message shows the calling code rather that the line with warnings.warn.
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.
didn't know that. thanks for the feedback
Doesn't make sense for
changeReason
to be camelCase. Replacing it with_change_reason
and deprecating it. Will remove it completely in 3.0