imprecise types on urllib3.Retry.new
/ urllib3.Retry.increment
#3363
Closed
Description
Subject
when attempting to subclass urllib3.Retry
-- one would want to implement def increment(...) -> Self:
as both increment
and new
preserve the type but label the return value as Retry
(essentially breaking subclassing types):
urllib3/src/urllib3/util/retry.py
Line 243 in 733f638
if the codebase were python 3.11+ I would use from typing import Self
-- it appears elsewhere in the codebase one-off SelfT
TypeVar
s are created -- that pattern could be followed here
alternatively the TYPE_CHECKING
trick could be used and is understood by the current major type checkers:
if TYPE_CHECKING:
from typing_extensions import Self
Environment
N/A -- latest primary branch source, mypy 1.9
Steps to Reproduce
from typing import Any, Self
import urllib3
class MyRetry(urllib3.Retry):
def increment(self, *a: Any, **k: Any) -> Self: # type error on this line!
return super().increment(*a, **k)
$ mypy t.py
t.py:5: error: Incompatible return value type (got "Retry", expected "Self") [return-value]
Found 1 error in 1 file (checked 1 source file)
Expected Behavior
no errors
Actual Behavior
shown above