]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commit
handle dunder names in @declared_attr separately
authorMike Bayer <mike_mp@zzzcomputing.com>
Mon, 15 Nov 2021 01:02:10 +0000 (20:02 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Wed, 17 Nov 2021 22:49:51 +0000 (17:49 -0500)
commit4da3e5333868d5ae0b50f40f9540041ff6f6e678
tree7772c3b393ebef6e6322876df5422fa77989eb4f
parent24a53fd8fce2cdfb0154caa687ef893bcff120a7
handle dunder names in @declared_attr separately

Fixed Mypy crash which would occur when using Mypy plugin against code
which made use of :class:`_orm.declared_attr` methods for non-mapped names
like ``__mapper_args__``, ``__table_args__``, or other dunder names, as the
plugin would try to interpret these as mapped attributes which would then
be later mis-handled. As part of this change, the decorated function is
still converted by the plugin into a generic assignment statement (e.g.
``__mapper_args__: Any``) so that the argument signature can continue to be
annotated in the same way one would for any other ``@classmethod`` without
Mypy complaining about the wrong argument type for a method that isn't
explicitly ``@classmethod``.

Fixes: #7321
Change-Id: I55656e867876677c5c55143449db371344be8600
(cherry picked from commit 836902bc8438a800d2c9cf1452da31d3ca967f3b)
doc/build/changelog/unreleased_14/7321.rst [new file with mode: 0644]
lib/sqlalchemy/ext/mypy/decl_class.py
lib/sqlalchemy/ext/mypy/util.py
test/ext/mypy/files/issue_7321.py [new file with mode: 0644]
test/ext/mypy/files/issue_7321_part2.py [new file with mode: 0644]