summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authormike bayer <mike_mp@zzzcomputing.com>2021-11-18 16:13:16 +0000
committerGerrit Code Review <gerrit@ci3.zzzcomputing.com>2021-11-18 16:13:16 +0000
commitd6199ae445ed0c21716b58f8f9f4f96ef9ee34a6 (patch)
treeaba6eb2255683cd532e4fd7b680cb337d4660f88 /test
parentc0b0bf8ab81ac966a8c5a428a45cddbafaaf6e18 (diff)
parent836902bc8438a800d2c9cf1452da31d3ca967f3b (diff)
downloadsqlalchemy-d6199ae445ed0c21716b58f8f9f4f96ef9ee34a6.tar.gz
Merge "handle dunder names in @declared_attr separately" into main
Diffstat (limited to 'test')
-rw-r--r--test/ext/mypy/files/issue_7321.py21
-rw-r--r--test/ext/mypy/files/issue_7321_part2.py27
2 files changed, 48 insertions, 0 deletions
diff --git a/test/ext/mypy/files/issue_7321.py b/test/ext/mypy/files/issue_7321.py
new file mode 100644
index 000000000..6a40b9dda
--- /dev/null
+++ b/test/ext/mypy/files/issue_7321.py
@@ -0,0 +1,21 @@
+from typing import Any
+
+from sqlalchemy.orm import declarative_base
+from sqlalchemy.orm import declared_attr
+
+
+Base = declarative_base()
+
+
+class Foo(Base):
+ @declared_attr
+ def __tablename__(cls) -> str:
+ return "name"
+
+ @declared_attr
+ def __mapper_args__(cls) -> dict[Any, Any]:
+ return {}
+
+ @declared_attr
+ def __table_args__(cls) -> dict[Any, Any]:
+ return {}
diff --git a/test/ext/mypy/files/issue_7321_part2.py b/test/ext/mypy/files/issue_7321_part2.py
new file mode 100644
index 000000000..f53add1da
--- /dev/null
+++ b/test/ext/mypy/files/issue_7321_part2.py
@@ -0,0 +1,27 @@
+from typing import Any
+from typing import Type
+
+from sqlalchemy.orm import declarative_base
+from sqlalchemy.orm import declared_attr
+
+
+Base = declarative_base()
+
+
+class Foo(Base):
+ # no mypy error emitted regarding the
+ # Type[Foo] part
+ @declared_attr
+ def __tablename__(cls: Type["Foo"]) -> str:
+ return "name"
+
+ @declared_attr
+ def __mapper_args__(cls: Type["Foo"]) -> dict[Any, Any]:
+ return {}
+
+ # this was a workaround that works if there's no plugin present, make
+ # sure that doesn't crash anything
+ @classmethod
+ @declared_attr
+ def __table_args__(cls: Type["Foo"]) -> dict[Any, Any]:
+ return {}