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

Deprecate changereason #655

Merged
merged 2 commits into from
Apr 26, 2020
Merged

Deprecate changereason #655

merged 2 commits into from
Apr 26, 2020

Conversation

rossmechanic
Copy link
Collaborator

Doesn't make sense for changeReason to be camelCase. Replacing it with _change_reason and deprecating it. Will remove it completely in 3.0

@codecov-io
Copy link

codecov-io commented Apr 26, 2020

Codecov Report

Merging #655 into master will decrease coverage by 0.39%.
The diff coverage is 66.66%.

Impacted file tree graph

@@            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     
Impacted Files Coverage Δ
simple_history/utils.py 90.32% <55.55%> (-5.91%) ⬇️
simple_history/manager.py 97.33% <100.00%> (+0.03%) ⬆️
simple_history/models.py 98.44% <100.00%> (+<0.01%) ⬆️

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 155e852...8ce6dc0. Read the comment docs.

@rossmechanic rossmechanic merged commit 4bd742e into master Apr 26, 2020
@rossmechanic rossmechanic deleted the deprecate-changereason branch April 26, 2020 23:00

def get_change_reason_from_object(obj):
if hasattr(obj, "_change_reason"):
return getattr(obj, "_change_reason")
Copy link

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)

Copy link
Collaborator Author

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

Copy link

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

Copy link
Collaborator Author

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

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.

Copy link
Collaborator Author

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

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.

4 participants