-
Notifications
You must be signed in to change notification settings - Fork 23
Deprecated: Fitcontribution camel case methods
#139
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
base: main
Are you sure you want to change the base?
Conversation
|
@sbillinge ready for review |
|
@sbillinge jk... we need a release of utils first. |
sbillinge
left a comment
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 looks fantastic. Please see my comments though. These are important to get right before we farm this out to workers.
I suggest that we duplicate at least one of the tests for the old filename. We don't have to duplicate all the tests with the old name. This just tests that our deprecation hasn't broken the use of the old name. If one one test passes with the old name, and all the tests pass with the new name, we should be ok (preferrably it would be a test that uses all the available arguments though, so don't pick a trivial test but a rich one.
news/fitcontribution-dep.rst
Outdated
|
|
||
| **Deprecated:** | ||
|
|
||
| * Deprecate camel case method formatting in ``FitContribution``. |
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.
please can you list all hte public facing methods that were depracated as a matter of policy. This is user facing so it is more useful to them than which module from a dev point of view that you worked on.
| matplotlib-base | ||
| numpy | ||
| scipy | ||
| diffpy.utils |
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.
Let's make sure we have an issue to remove this from conda.txt and pip.txt when the old API is removed.
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.
done
| def _dep_msg_fitcontrib(old_name, new_name, version=removal_version): | ||
| msg = ( | ||
| f"'diffpy.srfit.fitbase.fitcontribution.FitContribution.{old_name}' " | ||
| f"is deprecated and will be removed in version {version}. Please use " |
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.
For greater readability lets make version to be removal_version. Also, I don't see any default behavior, so let's make it required and not optional.
But this could get a bit messy. I had a quick convo with chatgpt about this. It is slightly messy as I am sure you have found out, but defining this message in a central place can work We have to have the function here also, but it is more lightweight. Here is a summary:
Yes — in this case you can use __name__, but only if you evaluate it in the module where the message is constructed, not inside the imported helper function.
The key distinction is:
__name__is resolved lexically, at function definition time, not at import time or call time.- Therefore, if you place
_dep_msg_fitcontribin a shared helper module, the value of__name__inside that function will always be the helper module’s name, not the name of the module that imported it.
So you cannot simply write:
# shared_helpers.py
def _dep_msg_fitcontrib(...):
print(__name__) # always "shared_helpers", never "diffpy.srfit.fitbase..."The part that is easy
If what you really want is to avoid repeating the long module path in the string:
diffpy.srfit.fitbase.fitcontribution.FitContribution
and make each module auto-insert its own module path, the simplest and correct approach is to construct the prefix in the calling module, not inside the helper.
Example: Best pattern using __name__
# in shared_helpers.py
def make_deprecation_message(prefix, old_name, new_name, version):
return (
f"'{prefix}.{old_name}' is deprecated and will be removed"
f" in version {version}. Please use '{prefix}.{new_name}' instead."
)Then in each module:
# diffpy/srfit/fitbase/fitcontribution.py
from shared_helpers import make_deprecation_message
_PREFIX = __name__ + ".FitContribution"
_REMOVAL_VERSION = 4.0.0
def _dep_msg_fitcontrib(old_name, new_name):
return make_deprecation_message(_PREFIX, old_name, new_name, _REMOVAL_VERSION)However, I would also centralize the definition of removal_version (though make it reusable so we can reuse this in future updates.
|
@sbillinge okay i changed some things a bit. First off (as recommended) I changed one test for Secondly, I added the deprecation message to diffpy.utils in this PR diffpy/diffpy.utils#367. The process for deprecation is now,
Once again, I tested this with |
|
@cadenmyers13 this is great. It is failing tests but I will merge when it gets going again. |
|
also, just to check, hopefully you didn't change one test from the new name to the old name, but duplicated one of the tests with the old name, so when we delete it we are not losing a test. Please confirm, I wasn't sure from your comment. |
|
@sbillinge awesome, its failing tests on CI because we're importing something from utils that isn't released yet. All tests pass locally. Once we do a release of utils it should pass |
@sbillinge Oops I did not duplicate. I'll duplicate it |
|
@sbillinge okay, i duplicated it. Both versions passed locally |
|
@cadenmyers13 We need a new release of Alternatively we can work to get the next minor release ( |
@sbillinge Looks like its all aesthetic stuff (docs and such) with one thing that needs to be refactored diffpy/diffpy.utils#358. Shouldn't be too difficult, maybe more tedious than anything |


6 methods of
FitContributionare deprecated here. See commit messages for which. I pytest passed locally and fitbulkNi works (and throws Deprecation message).