|
1 | 1 | from __future__ import annotations |
2 | 2 |
|
3 | | -from typing import Any |
| 3 | +from typing import Any, Self |
4 | 4 |
|
5 | 5 |
|
6 | 6 | def period(pstr: str = "") -> Period: |
@@ -31,7 +31,7 @@ def __init__(self, months: int = 0, days: int = 0) -> None: |
31 | 31 | self._days = days |
32 | 32 |
|
33 | 33 | @classmethod |
34 | | - def make(cls, data: Any) -> Period: |
| 34 | + def make(cls, data: Any) -> Self: |
35 | 35 | if isinstance(data, cls): |
36 | 36 | return data |
37 | 37 | elif isinstance(data, str): |
@@ -110,7 +110,7 @@ def simple(self) -> str: |
110 | 110 | else: |
111 | 111 | return "" |
112 | 112 |
|
113 | | - def add_tenure(self, pstr: str) -> Period: |
| 113 | + def add_tenure(self, pstr: str) -> Self: |
114 | 114 | if isinstance(pstr, self.__class__): |
115 | 115 | self._months += pstr._months |
116 | 116 | self._days += pstr._days |
@@ -141,18 +141,18 @@ def add_tenure(self, pstr: str) -> Period: |
141 | 141 | st = st[ip:] |
142 | 142 | return self |
143 | 143 |
|
144 | | - def __add__(self, other: Any) -> Period: |
| 144 | + def __add__(self, other: Any) -> Self: |
145 | 145 | p = self.make(other) |
146 | 146 | return self.__class__(self._months + p._months, self._days + p._days) |
147 | 147 |
|
148 | | - def __radd__(self, other: Any) -> Period: |
| 148 | + def __radd__(self, other: Any) -> Self: |
149 | 149 | return self + other |
150 | 150 |
|
151 | | - def __sub__(self, other: Any) -> Period: |
| 151 | + def __sub__(self, other: Any) -> Self: |
152 | 152 | p = self.make(other) |
153 | 153 | return self.__class__(self._months - p._months, self._days - p._days) |
154 | 154 |
|
155 | | - def __rsub__(self, other: Any) -> Period: |
| 155 | + def __rsub__(self, other: Any) -> Self: |
156 | 156 | return self.make(other) - self |
157 | 157 |
|
158 | 158 | def __gt__(self, other: Any) -> bool: |
|
0 commit comments