You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
From the above discussion, I thought it would be worth to decouple the compare discussion from the initializer discussion. Both are somewhat related, but can live independently.
With a more "advanced" initializer/constructor we get the following benefits:
more "pythonic": it's one, obvious way to get an instance.
avoids the longer function call Version.parse(...).
more readable
With such an (overloaded?) initializer, we could cover the following use cases:
Is not possible with an __init__ method. The singledispatch works only for functions(!), not methods. For methods we would need functools.singledispatchmethod which is only available from Python >= 3.8.
Another idea goes into a completely different direction. Maybe we shouldn't change the Version class much, but offer a much shorter variant: semver.v.
One drawback could be that v is quite short. Maybe too short? Especially if you import it with from semver import v it could be easily overwritten by other, local variables.
That could be a bit avoided to use capital V or ver. Or we use the much longer name semver.version.
Thoughts? Any other ideas? Would that be worth the effort?
Situation
Originally posted by @tomschr in #258 (comment)
From the above discussion, I thought it would be worth to decouple the
comparediscussion from the initializer discussion. Both are somewhat related, but can live independently.With a more "advanced" initializer/constructor we get the following benefits:
Version.parse(...).With such an (overloaded?) initializer, we could cover the following use cases:
Discussions and Possible Solutions
To implement a somewhat more advanced constructor/initializer, we have these options:
isinstanceand if...else constructstyping.overloadfunction (suggested by @tlaferriere)functools.singledispatchHowever, all three comes at a cost or an issue:
@overloaddecorator is purely for type hints, you can only specify one function body and it has to distinguish the different types using isinstance.` (Originally posted by @tlaferriere in Consider keepingcomparemodule level function #258 (comment))__init__method. Thesingledispatchworks only for functions(!), not methods. For methods we would needfunctools.singledispatchmethodwhich is only available from Python >= 3.8.Another idea goes into a completely different direction. Maybe we shouldn't change the
Versionclass much, but offer a much shorter variant:semver.v.Which means, we could just use
semver.vas a much shorter variant:One drawback could be that
vis quite short. Maybe too short? Especially if you import it withfrom semver import vit could be easily overwritten by other, local variables.That could be a bit avoided to use capital
Vorver. Or we use the much longer namesemver.version.Thoughts? Any other ideas? Would that be worth the effort?
@tlaferriere @gsakkis @ppkt