File: typing_err3.py

package info (click to toggle)
sqlalchemy 1.4.46%2Bds1-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 22,444 kB
  • sloc: python: 341,434; ansic: 1,760; makefile: 226; xml: 17; sh: 7
file content (55 lines) | stat: -rw-r--r-- 1,476 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
"""Test that the right-hand expressions we normally "replace" are actually
type checked.

"""
from typing import List

from sqlalchemy import Column
from sqlalchemy import ForeignKey
from sqlalchemy import Integer
from sqlalchemy import String
from sqlalchemy.orm import declarative_base
from sqlalchemy.orm import Mapped
from sqlalchemy.orm import relationship
from sqlalchemy.orm.decl_api import declared_attr


Base = declarative_base()


class User(Base):
    __tablename__ = "user"

    id = Column(Integer, primary_key=True)

    # note this goes away in 2.0 for the moment
    # EXPECTED_MYPY: Unexpected keyword argument "wrong_arg" for "RelationshipProperty" # noqa
    addresses: Mapped[List["Address"]] = relationship(
        "Address", wrong_arg="imwrong"
    )


class SubUser(User):
    __tablename__ = "subuser"

    id: int = Column(Integer, ForeignKey("user.id"), primary_key=True)


class Address(Base):
    __tablename__ = "address"

    id: int = Column(Integer, primary_key=True)

    user_id: int = Column(ForeignKey("user.id"))

    @declared_attr
    def email_address(cls) -> Column[String]:
        # EXPECTED_MYPY: No overload variant of "Column" matches argument type "bool" # noqa
        return Column(True)

    @declared_attr
    # EXPECTED_MYPY: Invalid type comment or annotation
    def thisisweird(cls) -> Column(String):
        # with the bad annotation mypy seems to not go into the
        # function body
        return Column(False)