Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 18 additions & 12 deletions poetry/core/version/pep440/segments.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import dataclasses

from typing import Iterable
from typing import Optional
from typing import Tuple
from typing import Union
Expand Down Expand Up @@ -30,20 +31,17 @@ class Release:
minor: Optional[int] = dataclasses.field(default=None, compare=False)
patch: Optional[int] = dataclasses.field(default=None, compare=False)
# some projects use non-semver versioning schemes, eg: 1.2.3.4
extra: Optional[Union[int, Tuple[int, ...]]] = dataclasses.field(
default=None, compare=False
# (this appears to trigger a mypy false positive)
extra: Union[int, Tuple[int, ...]] = dataclasses.field( # type: ignore
default_factory=tuple, compare=False
Comment on lines +34 to +36
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can i get a quick sanity check here @neersighted?

)
precision: int = dataclasses.field(default=None, init=False, compare=False)
text: str = dataclasses.field(default=None, init=False, compare=False)
precision: int = dataclasses.field(default=0, init=False, compare=False)
_compare_key: Tuple[int, ...] = dataclasses.field(
default=None, init=False, compare=True
default_factory=tuple, init=False, compare=True
)
text: str = ""

def __post_init__(self):
if self.extra is None:
object.__setattr__(self, "extra", tuple())
elif not isinstance(self.extra, tuple):
object.__setattr__(self, "extra", (self.extra,))

parts = list(
map(
Expand Down Expand Up @@ -74,6 +72,14 @@ def from_parts(cls, *parts: int) -> "Release":
extra=parts[3:] if len(parts) > 3 else tuple(),
)

def _extras(self) -> Iterable[int]:
"""Return an 'Iterable' over the 'extra' segments"""

if isinstance(self.extra, int):
return (self.extra,)
else:
return self.extra

def to_string(self) -> str:
return self.text

Expand All @@ -83,7 +89,7 @@ def next_major(self) -> "Release":
major=self.major + 1,
minor=0 if self.minor is not None else None,
patch=0 if self.patch is not None else None,
extra=tuple(0 for _ in self.extra),
extra=tuple(0 for _ in self._extras()),
)

def next_minor(self) -> "Release":
Expand All @@ -92,7 +98,7 @@ def next_minor(self) -> "Release":
major=self.major,
minor=self.minor + 1 if self.minor is not None else 1,
patch=0 if self.patch is not None else None,
extra=tuple(0 for _ in self.extra),
extra=tuple(0 for _ in self._extras()),
)

def next_patch(self) -> "Release":
Expand All @@ -101,7 +107,7 @@ def next_patch(self) -> "Release":
major=self.major,
minor=self.minor if self.minor is not None else 0,
patch=self.patch + 1 if self.patch is not None else 1,
extra=tuple(0 for _ in self.extra),
extra=tuple(0 for _ in self._extras()),
)


Expand Down
5 changes: 3 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ known_first_party = "poetry.core"
known_third_party = ["poetry.core._vendor"]

[tool.mypy]
python_version = "3.6"
follow_imports = "silent"
ignore_missing_imports = true
files = "poetry"
Expand All @@ -107,7 +106,9 @@ module = [
'poetry.core.semver.*',
'poetry.core.spdx.*',
'poetry.core.vcs.*',
'poetry.core.version.*',
'poetry.core.version.markers.*',
'poetry.core.version.pep440.parser.*',
'poetry.core.version.pep440.version.*',
]
ignore_errors = true

Expand Down