Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork1.2k
Closed
Labels
Description
Subject
when attempting to subclassurllib3.Retry
-- one would want to implementdef increment(...) -> Self:
as bothincrement
andnew
preserve the type but label the return value asRetry
(essentially breaking subclassing types):
urllib3/src/urllib3/util/retry.py
Line 243 in733f638
defnew(self,**kw:typing.Any)->Retry: |
if the codebase were python 3.11+ I would usefrom typing import Self
-- it appears elsewhere in the codebase one-offSelfT
TypeVar
s are created -- that pattern could be followed here
alternatively theTYPE_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
fromtypingimportAny,Selfimporturllib3classMyRetry(urllib3.Retry):defincrement(self,*a:Any,**k:Any)->Self:# type error on this line!returnsuper().increment(*a,**k)
$mypy t.pyt.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