Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mypyc AssertionError: Self`0 #17793

Open
CoolCat467 opened this issue Sep 20, 2024 · 0 comments
Open

Mypyc AssertionError: Self`0 #17793

CoolCat467 opened this issue Sep 20, 2024 · 0 comments
Labels

Comments

@CoolCat467
Copy link

Bug Report

Mypyc raises AssertionError: Self`0 in NamedTuple subclass

To Reproduce

vector.py

from __future__ import annotations

from typing import TYPE_CHECKING, NamedTuple

from typing_extensions import Self

if TYPE_CHECKING:  # pragma: nocover
    from collections.abc import Iterable


class Vector2(NamedTuple):
    """Vector2 Object. Takes an x and a y coordinate."""

    x: float
    y: float

    @classmethod
    def from_iter(cls, iterable: Iterable[float]) -> Self:
        """Return new vector from iterable."""
        return cls(*iter(iterable))

    def __neg__(self) -> Self:
        """Return result of negating self components."""
        return self.from_iter(-c for c in self)
mypyc vector.py

Expected Behavior

Expected no issues

Actual Behavior

Traceback (most recent call last):
vector.py:24: AssertionError: Self`0

Changing the erroring line in question to be

def __neg__(self) -> Vector2:

instead results in

Traceback (most recent call last):
vector.py:24: AssertionError: tuple[builtins.float, builtins.float, fallback=vector.Vector2]

Your Environment

  • Mypy version used: mypy 1.11.2 (compiled: yes)
  • Mypy command-line flags: None
  • Mypy configuration options from mypy.ini (and other config files): None
  • Python version used: Python 3.12.3 (main, Sep 11 2024, 14:17:37) [GCC 13.2.0] on linux
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants