Thanks to visit codestin.com
Credit goes to github.com

Skip to content

sqlalchemy.ext.mypy.plugin causes internal error #19014

Closed as not planned
Closed as not planned
@ZhymabekRoman

Description

@ZhymabekRoman

Crash Report

sqlalchemy.ext.mypy.plugin causes internal error

Traceback

/home/olge/.cache/pypoetry/virtualenvs/iswim-chat-bot-VvmrzMoq-py3.13/lib/python3.13/site-packages/advanced_alchemy/mixins/slug.py:-1: error: INTERNAL ERROR -- Please try using mypy master on GitHub:
https://mypy.readthedocs.io/en/stable/common_issues.html#using-a-development-mypy-build
Please report a bug at https://github.com/python/mypy/issues
version: 1.15.0
Traceback (most recent call last):
  File "mypy/checkexpr.py", line 5903, in accept
  File "mypy/nodes.py", line 2274, in accept
  File "mypy/checkexpr.py", line 5360, in visit_lambda_expr
  File "mypy/nodes.py", line 2267, in expr
IndexError: list index out of range
/home/olge/.cache/pypoetry/virtualenvs/iswim-chat-bot-VvmrzMoq-py3.13/lib/python3.13/site-packages/advanced_alchemy/mixins/slug.py:-1: : note: use --pdb to drop into pdb

To Reproduce
slug.py

from __future__ import annotations

from typing import TYPE_CHECKING, Any

from sqlalchemy import Index, String, UniqueConstraint
from sqlalchemy.orm import Mapped, declarative_mixin, declared_attr, mapped_column

if TYPE_CHECKING:
    from sqlalchemy.orm.decl_base import _TableArgsType as TableArgsType  # pyright: ignore[reportPrivateUsage]


@declarative_mixin
class SlugKey:
    """Slug unique Field Model Mixin."""

    @declared_attr
    def slug(cls) -> Mapped[str]:
        """Slug field."""
        return mapped_column(
            String(length=100),
            nullable=False,
        )

    @staticmethod
    def _create_unique_slug_index(*_: Any, **kwargs: Any) -> bool:
        return bool(kwargs["dialect"].name.startswith("spanner"))

    @staticmethod
    def _create_unique_slug_constraint(*_: Any, **kwargs: Any) -> bool:
        return not kwargs["dialect"].name.startswith("spanner")

    @declared_attr.directive
    @classmethod
    def __table_args__(cls) -> TableArgsType:
        return (
            UniqueConstraint(
                cls.slug,
                name=f"uq_{cls.__tablename__}_slug",  # type: ignore[attr-defined]
            ).ddl_if(callable_=cls._create_unique_slug_constraint),
            Index(
                f"ix_{cls.__tablename__}_slug_unique",  # type: ignore[attr-defined]
                cls.slug,
                unique=True,
            ).ddl_if(callable_=cls._create_unique_slug_index),
        )

Your Environment

  • Mypy version used: 1.15.0
  • Mypy command-line flags: mypy code/
  • Mypy configuration options from mypy.ini (and other config files):
[mypy]
plugins = sqlalchemy.ext.mypy.plugin
  • Python version used: 3.13.3
  • Operating system and version: Arch Linux, 6.14.3-zen1-1-zen

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions