GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Inconsistent MRO error when `__new__` returns a subclass and `--warn-unreachable` is turned on · Issue #13824 · python/mypy

Inconsistent MRO error when __new__ returns a subclass and --warn-unreachable is turned on #13824

New issue
Copy link
New issue
Copy link
Closed
#21441
Closed
Inconsistent MRO error when __new__ returns a subclass and --warn-unreachable is turned on#13824
#21441
Copy link
Labels
bugmypy got something wrong

Description

@tmke8
tmke8
opened on Oct 6, 2022
Issue body actions

Bug Report

The problem appeared in the pandas stubs in this issue: pandas-dev/pandas-stubs#269

There, I was told to report it here.

To Reproduce
I reduced the problem to a standalone example, but it might be possible to reduce it further:

Playground URL: https://mypy-play.net/?mypy=master&python=3.10&flags=warn-unreachable&gist=18e35c8047f69e2418498f85cc8f02d0

from __future__ import annotations
import datetime
from typing import Any, Generic, TypeVar, Union, overload

S1 = TypeVar("S1", int, datetime.datetime)

class Series(Generic[S1]):
    @overload
    def __new__(cls, data: datetime.datetime) -> TimestampSeries: ...

    @overload
    def __new__(cls, data: dict[int, S1]) -> Series[S1]: ...

    def __new__(cls, data: Union[datetime.datetime, dict[int, S1]]) -> Any:
        return

class TimestampSeries(Series[datetime.datetime]): ...

x = Series({0: 0, 1: 1})
reveal_type(x)
assert isinstance(x, Series)

Note that the error only appears with --warn-unreachable.

Expected Behavior

Given that the reveal_type() shows that the type is Series[int], I would expect the subsequent isinstance() call to succeed.

Actual Behavior

main.py:20: note: Revealed type is "__main__.Series[builtins.int]"
main.py:21: error: Subclass of "Series[int]" and "TimestampSeries" cannot exist: would have inconsistent method resolution order  [unreachable]
Found 1 error in 1 file (checked 1 source file)

Your Environment

See the mypy playground link.

Activity

  1. tmke8
    added
    bugmypy got something wrong
    on Oct 6, 2022
  2. ilevkivskyi
    closed this as completedin #21441on May 27, 2026
  3. pull
    added a commit that references this issue on May 27, 2026

    Respect explicit return type of __new__() (python#21441)

    938dbe2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrong

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402775 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.