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

Signature incompatible with supertype when using overload since updating from 1.1.1 to 1.2.0 #15041

Closed
Labels
bugmypy got something wrongtopic-inheritanceInheritance and incompatible overrides
@erzoe

Description

@erzoe

Bug Report

Since updating from 1.1.1 to 1.2.0 the following code does not pass anymore.

Reading thechange log I am assuming this might be related to#14882.

To Reproduce

#!/usr/bin/env python3importtypingiftyping.TYPE_CHECKING:fromtyping_extensionsimportSelfT_co=typing.TypeVar('T_co',covariant=True)classConfig(typing.Generic[T_co]):def__init__(self,value:T_co)->None:self.value=value@typing.overloaddef__get__(self,instance:None,owner:typing.Any=None)->'Self':pass@typing.overloaddef__get__(self,instance:typing.Any,owner:typing.Any=None)->T_co:passdef__get__(self,instance:typing.Any,owner:typing.Any=None)->'T_co|Self':ifinstanceisNone:returnselfreturnself.valueclassMultiConfig(Config[T_co]):def__init__(self,val:T_co)->None:super().__init__(val)self.values:'dict[object, T_co]'= {}@typing.overloaddef__get__(self,instance:None,owner:typing.Any=None)->'Self':pass@typing.overloaddef__get__(self,instance:typing.Any,owner:typing.Any=None)->T_co:passdef__get__(self,instance:typing.Any,owner:typing.Any=None)->'T_co|Self':ifinstanceisNone:returnselfreturnself.values.get(instance.config_id,self.value)

Expected Behavior

This code should pass, as it did in 1.1.1.

Actual Behavior

$ mypy --strict mwe.pymwe.py:35: error: Signature of "__get__" incompatible with supertype "Config"  [override]mwe.py:35: note:      Superclass:mwe.py:35: note:          @overloadmwe.py:35: note:          def __get__(self, instance: Any, owner: Any = ...) -> T_comwe.py:35: note:      Subclass:mwe.py:35: note:          @overloadmwe.py:35: note:          def __get__(self, instance: None, owner: Any = ...) -> MultiConfig[T_co]mwe.py:35: note:          @overloadmwe.py:35: note:          def __get__(self, instance: Any, owner: Any = ...) -> T_coFound 1 error in 1 file (checked 1 source file)

Your Environment

  • Mypy version used: 1.2.0
  • Mypy command-line flags:--strict (but it does not make a difference)
  • Mypy configuration options frommypy.ini (and other config files): none
  • Python version used: Python 3.10.10

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrongtopic-inheritanceInheritance and incompatible overrides

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp