Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

imprecise types onurllib3.Retry.new /urllib3.Retry.increment #3363

Closed
@asottile-sentry

Description

@asottile-sentry

Subject

when attempting to subclassurllib3.Retry -- one would want to implementdef increment(...) -> Self: as bothincrement andnewpreserve the type but label the return value asRetry (essentially breaking subclassing types):

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-offSelfTTypeVars 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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp