Currently, the clear
method has to be used:
>>> Version.parse('1.3.post0').replace(post=None)
<Version '1.3.post'>
>>> Version.parse('1.3.post0').clear(post=True)
<Version '1.3'>
There are a few possible solutions below. They would also apply to Version
's constructor
IMPLICIT
constant
✅Explicit
❎Name isn't very clear. "What other parameters can I pass this to?"
>>> from parver import IMPLICIT
>>> Version.parse('1.3.post0').replace(post=None)
<Version '1.3'>
>>> Version.parse('1.3.post0').replace(post=IMPLICIT)
<Version '1.3.post'>
IMPLICIT_ZERO
constant
✅Explicit
✅It's clear that this is a stand in for zero.
❎It's long, but I don't think that's much of a problem.
>>> from parver import IMPLICIT_ZERO
>>> Version.parse('1.3.post0').replace(post=None)
<Version '1.3'>
>>> Version.parse('1.3.post0').replace(post=IMPLICIT_ZERO)
<Version '1.3.post'>
String constant
✅No separate import required when using from parver import Version
.
❎Magic string seems odd. "What other strings can I pass here?"
>>> Version.parse('1.3.post0').replace(post=None)
<Version '1.3'>
>>> Version.parse('1.3.post0').replace(post='implicit')
<Version '1.3.post'>
Empty string
✅No separate import required when using from parver import Version
.
✅Matches the visual output.
❎Slightly less magic than a string constant, but could be confusing?
>>> Version.parse('1.3.post0').replace(post=None)
<Version '1.3'>
>>> Version.parse('1.3.post0').replace(post='')
<Version '1.3.post'>
Use False
to clear.
✅No separate import required when using from parver import Version
.
❎User has to be careful with None
vs False
.
>>> Version.parse('1.3.post0').replace(post=False)
<Version '1.3'>
>>> Version.parse('1.3.post0').replace(post=None)
<Version '1.3.post'>
I think I prefer IMPLICIT_ZERO
constant or Empty string.