Skip to content

special-case NotImplementedType in binop signatures to match runtime semantics #1129

Closed

Description

@KotlinIsland

Describe the Bug

from types import NotImplementedType

class A:
    def __add__(self, i: object) -> NotImplementedType: ...


class B:
    def __radd__(self, i: A) -> int: ...

_ = A() + B() # _NotImplementedType

binops can Never return NotImplementedType by cause of runtime semantics, i would expect this to result in Never or int

Sandbox Link

No response

(Only applicable for extension issues) IDE Information

No response

Activity

  1. added theissue type on Sep 23, 2025
  2. stroxler commented on Sep 23, 2025

    @stroxler
    Contributor

    Thanks for the issue!

    I think we may have partial support for not implemented, but this seems like a gap in our support

  3. yangdanny97 commented on Jul 13, 2026

    @yangdanny97
    Collaborator

    For future implementors: one tricky thing to consider

    If we have an argument A | B, and A returns something for __add__ while B returns NotImplemented, we should only call __radd__ with B

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

Metadata

Metadata

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions