-
Notifications
You must be signed in to change notification settings - Fork 96
Deprecate module level functions #229
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 module level functions #229
Conversation
c2a5ce3 to
a32df30
Compare
gsakkis
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.
@tomschr looks good in general; just left a few minor comments and suggestions.
61aeca1 to
ecd7017
Compare
|
conflict with semver.py need to be fixed. |
c8948ba to
9a43790
Compare
|
@scls19fr I fixed the conflicts now. There is still two things we need to clarify:
I will improve the documentation as I think, this still needs a note or some further explanations. |
|
I have no idea about what is the best... deprecating module function in major 3.x.x or in 4.x.x. Anyway documenting is the best we can do currently. |
|
@scls19fr
No problem. In that case, we could deprecate them in 4.x.y to be on the safe side. That may give projects a little bit more time and we could address @ppkt concerns. There is another issue which just came into my mind: should we make the The reason for this is it could help projects which still uses |
|
I'm wondering if |
|
Yep, that's probably a better name. 👍 I will do the change and add also some tests. |
|
or |
|
see in https://pandas.pydata.org/pandas-docs/stable/reference/frame.html |
|
Ok, even better. I'll use |
|
You can find my current implementation of |
|
I wonder if we shouldn't even have
so it will be easier to know using tab completion how to transform a |
|
Actually, I thought of that too. 😄 I think, the However, I'm not sure about the If you really want it, we can implement it as an alias: to_string = __str__ |
|
ok! let's forget |
|
@scls19fr I've updated the documentation, see for details commit c4ac0ec. All changes are in section "Using semver". As the changes are a bit spread, I would recommend to build the documentation with If you are missing some important information, let me know. After your approval, I would squash the commits to have a clean history. |
|
@scls19fr Thanks for the approval. 👍 However, before I can squash and merge it, I found some other issues which I would like to ask. In commit 1d8c415, I've moved the Another question is regarding the warnings. As I've improved the For example, I've tried to display the warnings, however this seems not to work: $ python3 -c "import semver; print(semver.parse_version_info('3.4.5'))"
3.4.5However, when I add the $ python3 -Wd -c "import semver; print(semver.parse_version_info('3.4.5'))"
<string>:1: DeprecationWarning: Function 'semver.parse_version_info' is deprecated. Deprecated since version 2.9.2. Use 'semver.VersionInfo.parse' instead.
3.4.5@ppkt, @scls19fr do you know if this is an expected behaviour? Is the correct? Not sure... Thanks for your help! |
ppkt
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.
LGTM :)
|
@ppkt Thanks for your analysis. Much appreciated. 👍
Yes, that was also my findings, but I wasn't sure.
Hmn, maybe they mean something like this: import semver # not triggered in the library?
if __name__ == "__main__":
# Warning is triggered hereJust a theory. I think, I should mention the |
|
Yes, my suspicion seems to be correct. Here is a short test code: #!/usr/bin/python3
import warnings
import semver
def fourtytwo():
warnings.warn("Oh no, we found the answer!", category=UserWarning)
return 42
if __name__ == "__main__":
print(semver.bump_major('3.4.5'))
print(fourtytwo())When I run this script, I get: $ ./fortytwo.py
4.0.0
./fortytwo.py:7: UserWarning: Oh no, we found the answer!
warnings.warn("Oh no, we found the answer!", category=UserWarning)
42which is exactly the result predicted from the Python documentation. When I change the shebang line and add the $ ./fortytwo.py
./fortytwo.py:11: DeprecationWarning: Function 'semver.bump_major' is deprecated. Deprecated since version 2.9.2. This function will be removed in semver 3. Use the respective 'semver.VersionInfo.None' instead.
print(semver.bump_major('3.4.5'))
4.0.0
./fortytwo.py:7: UserWarning: Oh no, we found the answer!
warnings.warn("Oh no, we found the answer!", category=UserWarning)
42 |
d4348fa to
561384c
Compare
|
@scls19fr @ppkt @gsakkis I've squashed the commits and added all necessary information into the commit message. I'm finished. The documentation is updated, the test cases works and even the coverage report shows 100%! 🎉 Could you have a final look if everything is ok? I will merge it soon. |
334c6c6 to
09ef970
Compare
6069d66 to
4611457
Compare
|
As the changes are a bit big, I will leave you some more time. If nobody objects, I will merge it on Thursday. 😉 |
* Add test cases
- Add additional test case for "check"
- test_should_process_check_iscalled_with_valid_version
- Test also missing finalize_version
- Test the warning more thoroughly with pytest.warns instead
of just pytest.deprecated_call
* In `setup.cfg`, add deprecation warnings filter for pytest
* Implement DeprecationWarning with warnings module and
the new decorator `deprecated`
* Output a DeprecationWarning for the following functions:
- semver.bump_{major,minor,patch,prerelease,build}
- semver.format_version
- semver.finalize_version
- semver.parse
- semver.parse_version_info
- semver.replace
- semver.VersionInfo._asdict
- semver.VersionInfo._astuple
Add also a deprecation notice in the docstrings of these
functions
* Introduce new public functions:
- semver.VersionInfo.to_dict (from former _asdict)
- semver.VersionInfo.to_tuple (from former _astuple)
- Keep _asdict and _astuple as a (deprecated) function for
compatibility reasons
* Update CHANGELOG.rst
* Update usage documentation:
- Move some information to make them more useful for
for the reader
- Add deprecation warning
- Explain how to replace deprecated functions
- Explain how to display deprecation warnings from semver
* Improve documentation of deprecated functions
- List deprecated module level functions
- Make recommendation and show equivalent code
- Mention that deprecated functions will be replaced in
semver 3. That means, all deprecated function will be still
available in semver 2.x.y.
* Move _increment_string into VersionInfo class
- Makes removing deprecating functions easier as, for example,
bump_prerelease is no longer dependant from an "external"
function.
- Move _LAST_NUMBER regex into VersionInfo class
- Implement _increment_string as a staticmethod
Co-authored-by: Karol <[email protected]>
Co-authored-by: scls19fr <[email protected]>
Co-authored-by: George Sakkis
4611457 to
5b8bb16
Compare
This PR fixes #225.
For example, the
VersionInfo.bump_major()method callssemver.parse_version_infoandsemver.bump_majorinstead of having its own implementation. This has several drawbacks:As such, I had to move some implementation into the
VersionInfoclass. With this approach, we can deprecate the module level function without triggering a false positive when calling a method inVersionInfo.This PR contains the following changes:
Add test cases
finalize_versionpytest.warnsinstead of justpytest.deprecated_callIn
setup.cfg, add deprecation warnings filter for pytestImplement DeprecationWarning with warnings module and the new decorator
deprecatedOutput a DeprecationWarning for the following functions:
semver.bump_{major,minor,patch,prerelease,build}semver.finalize_versionsemver.format_versionsemver.parsesemver.parse_version_infosemver.replaceMove module level implementation into
VersionInfoMove implementations:
semver.format_version->semver.VersionInfo.format_versionsemver.VersionInfo.__str___REGEXintoVersionInfoclass_LAST_NUMBERintoVersionInfoclass_increment_stringand implement it as a staticmethodsemver.parse->semver.VersionInfo.parsesemver.bump_*->semver.VersionInfo.bump_*Change implementation by calling VersionInfo methods (and not the other way around):
semver.comparesemver.finalize_versionsemver.replacesemver.parse_version_infoIntroduce new public functions:
semver.VersionInfo.to_dict(from former_asdict)semver.VersionInfo.to_tuple(from former_astuple)_asdictand_astupleas a (deprecated) function for compatibility reasonsUpdate CHANGELOG.rst
Update usage documentation:
- Move some information to make them more useful for the reader
- Add deprecation warning
- Explain how to replace deprecated functions
- Explain how to display deprecation warnings from semver
Improve documentation of deprecated functions
@gsakkis As you were also involved, I'd like to hear your opinion too. 😉