-
Notifications
You must be signed in to change notification settings - Fork 96
Deprecate min_ver/max_ver and use builtin max()/min() functions #160
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
Comments
@tomschr it's a quite interesting idea. I like it :) EDIT: |
Thank you. :)
Ahh, right, you probably mean the one from functool.singledispatch, right? Yes, that could also be a solution. Not sure if testing would make it a bit more complicated (which wouldn't be an argument against it). |
Yes, you're right. I found it too when I scrolled down a bit. Argh. I've looked into the implementation and it doesn't look trivial. |
@tomschr Sorry, I wasn't clear - I was talking about your "Suggested solution" - i.e. adding I also think that it would be great to have an ability to provide a iterable instead of list of versions and I thought that it could be possible with feature called "singledispatch" but, unfortunately, as long as we support Python 2.7 it's not possible without an external package |
@ppkt No problem. :-)
Yes, that's unfortunate. Theoretically, if we don't want to rely on an external package, we could copy the missing feature and apply it for Python 2.7 only. I know, it would be an ugly solution and only for such a small function would be probably "mad". 😆 By the way, do we have any plans when we are "sunsetting" the support for Python 2.7? Next year, when it's officially not supported anymore? I know, it's a different issue, but I haven't found any information about how we want to deal with that. Maybe we should open a new issue and document that somewhere (in the README, our documentation etc.)? |
@tomschr I would prefer to avoid including external library in our code ;) Regarding sunsetting Py2.7 - I have no idea. Since semver is quite simple library I think we should keep support for older Python versions as long as it's possible but we should definitely think about moving forward. Maybe releasing version 3.x with dropped support for older versions and refactored to use modern features used in language but keep support for bugfixes in 2.x branch? |
@ppkt By the way, I maybe found a workaround for this "singledispatch". As we can't use The Here is a short demonstration: from __future__ import print_function
from pkgutil import simplegeneric
@simplegeneric
def max_ver(v1, v2):
print("> Comparing v1=%d and v2=%d" % (v1, v2))
return max(v1, v2)
@max_ver.register(list)
@max_ver.register(tuple)
def _(iterable):
print("> iterable:", iterable)
return max(iterable)
print(max_ver(2, 5))
print(max_ver((3, 5, 10, 2, 1, 0)))
# Output is:
# > Comparing v1=2 and v2=5
# 5
# > iterable: (3, 5, 10, 2, 1, 0)
# 10 Would that be an option? Once we remove support for Python 2.7, we can change it to |
@tomschr neat :) It seems that it's some kind of backport of |
After reading the issue again, I believe we should (if at all) implement the changes in 3.0.0. That makes it easier for us and we can use the Could we mark this feature for 3.0.0? Maybe with a GH milestone? |
What about tagging? |
I must admit I have never use GH milestone previously. What are the pros and cons compared to tagging issues? |
@scls19fr
Good question! 👍 After thinking about again, we have three options:
I've sorted them from easy to more advanced. Labels are the easiest way, projects the most advanced, and milestones are in the middle. You can continue to use labels (as you already did that). If we find out this is not enough, we can try milestones. 😉 |
Have you tried just using the builtin
|
Ahh, thanks for the hint, Thomas! 👍 Even better! I haven't looked at this issue for some time. You are right, with the help of the |
Actually, I was about to open a PR to deprecate these functions, but as I was editing the docs to reflect this, I realised that if we do that we will lose a use case: when you want to compare two strings (or dict, tuple) directly without having to call |
@tomschr maybe we could simply change these functions to use the builtins behind the scenes? I don't want to go about deprecating things and then someone comes up and says that the new workflow is unacceptable and that we need to change it back. |
Do you mean to use
Sure. 👍 Maybe we should combine it with documentation? |
I think using map like you suggested with |
Sorry, it was probably too late and I was too tired when I wrote my last comment. My bad, sorry. After rethinking it a bit, I need to correct and amend my comment. Maybe we need to clarify what we want to do with the If I'm not mistaken, we have the following options:
Solution 1 would be obviously the least destructive and most compatible. It would also mean we could focus more on documentation. Solution 2 is something in the middle. On the other hand, why should we change a deprecated function and add functionality before we remove it? As we don't change the function signature, we have only two arguments. Changing the implementation doesn't add much value. Solution 3 is also similar to solution 2, but changes the function signature. I'm a bit concerned about adding functionality to an already deprecated function. So all in all, After thinking about all the options above, weight the pros and cons... I'm leaning towards the first solution. Maybe we should leave the function "as is", but focus more on improving the documentation. As we declared both functions as deprecated, we shouldn't add additional functionality to it. Especially when we favor the builtins So to summarize it, my idea would be:
What do you think? Would that be a meaningful approach? |
Actually the PR (#264 ) to deprecate these functions hasn't been merged yet, so these functions aren't deprecated yet 😉. As such, the current state of these functions makes them not very useful. Improving could have potential to make them more useful, but if we want to stick to the bare essentials and keep the fluff at a minimum, then maybe the best way to go is to deprecate these functions and make the documentation super clear about how you can use the If I am feeling the vibe of this project right, I think we want to keep it simple, yet powerful.
Definitely 😃 |
Haha, yes, that's true. But almost. 😉
That's also my feeling. Or maybe someone else comes up that it indeed fulfill a certain need.
I agree with you. Probably having a good and powerful VersionInfo class does make things easier. A lot of of these comparisons cannot be done with pure version strings, for example. There was some concern in another issue that some shortcuts (like
👍 |
Uh oh!
There was an error while loading. Please reload this page.
Situation
Themin_ver
andmax_ver
functions have currently this signature:In other words, these functions allow to compare exactly two versions. However, there may be situations, where you have a list of versions. This use case could not be done with the current implementation and needs a cumbersome for-loop.As we have comparison operators, there is no need for this functions anymore. Of course, this works only for VersionInfo types, not strings. If someone still wants to compare strings, we could document a replacement.
Action Items:
max(map(semver.VersionInfo.parse, ['1.1.0', '1.2.0', '2.1.0', '0.5.10', '0.4.99']))
Old issue:
Suggested Solution
To allow to compare more than two versions, it would be useful to change the above signature like this:
This would resemble the builtin functions
min
andmax
. The above functions could be used like this:Benefits:
Alternative Solution
The proposed solution may has some drawbacks:
min
andmax
).If you don't like the proposed solution, we could:
min_ver
andmax_ver
untouched, or,min_ver
andmax_ver
(would introduce incompatible API changes),_iter
which allows to optimize for iterables. The signature could be:Questions
*others
tuple contains an invalid version?raise_if_invalid
) which can be set?The text was updated successfully, but these errors were encountered: