Skip to content

Commit 6176316

Browse files
authored
Fix return type of classmethod parse (python-semver#396)
So that calling parse on a derived class will show correct type of derived class
1 parent a1604fb commit 6176316

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/semver/version.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
cast,
1515
Callable,
1616
Collection,
17+
Type,
18+
TypeVar,
1719
)
1820

1921
from ._types import (
@@ -28,6 +30,8 @@
2830
Comparable = Union["Version", Dict[str, VersionPart], Collection[VersionPart], str]
2931
Comparator = Callable[["Version", Comparable], bool]
3032

33+
T = TypeVar("T", bound="Version")
34+
3135

3236
def _comparator(operator: Comparator) -> Comparator:
3337
"""Wrap a Version binary op method in a type-check."""
@@ -571,8 +575,8 @@ def match(self, match_expr: str) -> bool:
571575

572576
@classmethod
573577
def parse(
574-
cls, version: String, optional_minor_and_patch: bool = False
575-
) -> "Version":
578+
cls: Type[T], version: String, optional_minor_and_patch: bool = False
579+
) -> T:
576580
"""
577581
Parse version string to a Version instance.
578582

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy