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 — `overload`s resolved as a conflict with `Any` · Issue #4055 · astral-sh/ty

overloads resolved as a conflict with Any #4055

New issue
Copy link
New issue
Copy link
Closed
astral-sh/ruff
#29342
astral-sh/ruff#29342
Closed
overloads resolved as a conflict with Any#4055
astral-sh/ruff
#29342
Copy link
Assignees
carljm
Labels
needs-decisionAwaiting a decision from a maintaineroverloadstyping semanticstyping-module features, spec compliance, etc

Description

@cmp0xff
cmp0xff
opened on Jul 21, 2026
Issue body actions

Summary

In the following example, ty gives Unknown, whereas other type checkers give Series[Timestamp].

I think the first overload should take over.

  • https://play.ty.dev/6ee96176-9801-4851-a1dd-8647702d6600
  • https://pyrefly.org/sandbox/?project=N4IgZglgNgpgziAXKOBDAdgEwEYHsAeAdAA4CeS4ATrgLYAEALqcROgOZ0Q3G6UN0AqADroRmGGEbwGACnyJO6BgEpEIuhrqUYDAK6V0dfHQDUdAIwiR2gG4xUUAPpNiMGQ2kyALACZlykRAAGhAybTAoUkIGWigKAGI6AAVScMi6NCw8YwBjXHRINn1UBgh8whFEgGUYGDoACwYGYjhEAHo2sIlIwl42Nph0NsxcHLg2vIKIIsoSsqG6MF46VBtUaFRsWDpJwuLS-LpcYgP0OAr0MgZ6-IBaO0o4eboAXjohEABmQnMfD5EANowSjUR4AXREunQXB4fBgmFumAg2hypTsrzoAHJpuheDBMSJcQxbtoAI66ZHw24AaxgpFuqByOXgcAxmIA7qgDAT0MEQJkcAQSKQIBQwNR6C5WBwYbx%2BABBdCkIJ0ADig2BEByKoAKswYAA1Lkq3APKC4VCYFW2exOFwwISUKxO9A6jF61xGygyD46j4BF2OkQ5KCoOCsnVcaSobgKQjxoOiF0hsMRqPiKAMVBxhOB5Oh8N0GqUCDwGTq9CanIAnVg1SJzR0AACpuB5stDc04kkjkccF02F7MjgMCgYAUxdLcBrUbgWe4YJN12BCkjNHho6zyjotwAfEXNfAZ%2Bu5zHiGCcxUXY2W2aLZhOxpu3Re-3B45h6PxweS0e1xvM1QRcjmXShV3TTdUG3PcfynY8AKzC86HjK9nWsGA7AcZx9RkScj0VUgwRkaC6H-DMs2IgNAgAXxCRk0RgAAxaAYAoAVsmFUVqKAA
  • https://mypy-play.net/?gist=5d90cf55e67b091d89d80a80bdb559ab
from typing import Any, Generic, TypeVar, overload, reveal_type

T = TypeVar("T")

class Timestamp: ...

class Timedelta: ...

class Series(Generic[T]):
    @overload
    def __sub__(self: Series[Timestamp], other: Timedelta) -> Series[Timestamp]: ...
    @overload
    def __sub__(self: Series[Timedelta], other: Timedelta) -> Series[Timedelta]: ...

reveal_type(Series[Any]() - Timedelta())

Version

5e698d5e4

Activity

Next
  1. cmp0xff
    added 2 commits that reference this issue on Jul 21, 2026

    astral-sh/ty#4055

    70370f0

    astral-sh/ty#4055

    b3b64de
  2. carljm commented on Jul 21, 2026

    @carljm
    carljm
    on Jul 21, 2026
    Contributor
    More actions

    This is a case where ty is doing what the typing spec actually says to do (and the strictly correct thing to do), whereas all other type checkers have decided to implement some heuristic to favor the first overload and depart from what the spec actually says.

    Specifically, mypy and pyrefly both exclude self arguments (bound method receiver) from step 5 of the overload algorithm. (I don't see any principled reason why these arguments should be excluded). Pyright goes further than this and often prefers the first overload rather than applying step 5 of the specified algorithm at all.

    It seems to me that ty's inference here is more correct than any other type checker. If you have a Series[Any] and call __sub__ on it, there's no reason to assume it must be a Series[Timestamp] just because that overload happens to come first. The ideal return type here would be AnyOf[Timestamp, Timedelta] -- Any or Unknown is the best available option short of having an AnyOf type.

    That said, we could easily implement the same approach as mypy/pyrefly for compatibility's sake.

    Reacted by Yi-Fan Wang
  3. carljm
    added
    needs-decisionAwaiting a decision from a maintainer
    on Jul 21, 2026
  4. carljm
    added this to the This milestone has been deleted milestone on Jul 21, 2026
  5. carljm commented on Jul 21, 2026

    @carljm
    carljm
    on Jul 21, 2026
    Contributor
    More actions

    astral-sh/ruff#27054 implements the same approach as mypy/pyrefly, for evaluation purposes.

  6. cmp0xff
    added 2 commits that reference this issue on Jul 27, 2026

    astral-sh/ty#4055

    1488e75

    astral-sh/ty#4055

    e7839a8
  7. loicdiridollou
    added a commit that references this issue on Jul 29, 2026

    TST: #1799 enable `ty` in `tests/test_timefuncs.py ` (#1833)

    247e187
  8. cmp0xff
    added a commit that references this issue on Jul 30, 2026

    astral-sh/ty#4055 astral-sh/ty#4135 astral-sh/ty#3199

    7d29620
  9. loicdiridollou
    added a commit that references this issue on Jul 31, 2026

    TST: #1799 enable `ty` in `tests/frame/*/**` except for `tests/frame/…

    c98990e
  10. cmp0xff
    added 2 commits that reference this issue on Aug 1, 2026

    astral-sh/ty#4055

    1fc0962

    astral-sh/ty#4055

    d6f584b
  11. loicdiridollou
    added a commit that references this issue on Aug 2, 2026

    TST: #1799 enable `ty` in `tests/scalars/*/**` (#1860)

    42f5459
  12. sharkdp
    marked Don't prefer inferred function-like callable over annotated Callable #4135 as a duplicate of this issue on Aug 3, 2026
  13. 4 remaining items

  14. cmp0xff
    added a commit that references this issue on Aug 23, 2026

    TYP: ignore ty type-assertion-failure for astral-sh/ty#4055

    460cc5e
  15. carljm
    marked ty gives Unknown with overloads #4360 as a duplicate of this issue on Aug 25, 2026
  16. cmp0xff
    added 7 commits that reference this issue on Aug 25, 2026

    TYP: ignore ty type-assertion-failure for astral-sh/ty#4055

    21fc868

    TYP: ignore ty type-assertion-failure for astral-sh/ty#4055

    03670ee

    TYP: ignore ty type-assertion-failure for astral-sh/ty#4055

    25a4d10

    TYP: ignore ty type-assertion-failure for astral-sh/ty#4055

    eafd20e

    TST: pandas-dev#1799 enable `ty` in `tests/test_timefuncs.py ` (panda…

    02dc003

    TST: pandas-dev#1799 enable `ty` in `tests/frame/*/**` except for `te…

    d1038d2

    TST: pandas-dev#1799 enable `ty` in `tests/scalars/*/**` (pandas-dev#…

    e8ccebb
  17. loicdiridollou
    added a commit that references this issue on Aug 28, 2026

    TST: ignore ty assert_type failure in Series.quantile (#1925)

    a1a0980
  18. carljm
    self-assigned this
    on Sep 23, 2026
  19. cmp0xff commented on Oct 12, 2026

    @cmp0xff
    cmp0xff
    on Oct 12, 2026
    Author
    More actions

    Following python/mypy#22011, nightly mypy now also recognises the gradual receiver ambiguity. Rather than restoring first-match selection, could ty preserve the shared outer container where possible? This would give pandas-stubs a migration path.

  20. carljm commented on Oct 13, 2026

    @carljm
    carljm
    on Oct 13, 2026
    Contributor
    More actions

    astral-sh/ruff#29342 should fix this and preserve Series[Unknown] rather than Unknown as the result of an ambiguous call.

    Reacted by Yi-Fan Wang
  21. carljm
    added a commit that references this issue on Oct 14, 2026

    [ty] Preserve shared structure in ambiguous overload return types (#2…

    This issue will close once commit ef02d60 is merged into the 'main' branch.
    ef02d60
  22. carljm
    closed this as completedin ruff#29342on Oct 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @carljm
    carljm

Labels

needs-decisionAwaiting a decision from a maintaineroverloadstyping semanticstyping-module features, spec compliance, etc

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402792 — 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.