diff options
author | mike bayer <mike_mp@zzzcomputing.com> | 2022-07-04 18:13:32 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@ci3.zzzcomputing.com> | 2022-07-04 18:13:32 +0000 |
commit | 0bbee53b852eef58affb81acad055549f4749eab (patch) | |
tree | d25ddd213c171365bb94dc16f9734ddaeed19f5e | |
parent | 148711cb8515a19b6177dc07655cc6e652de0553 (diff) | |
parent | ccfec76b829e7eccd9e08d7f757da3590497f197 (diff) | |
download | sqlalchemy-0bbee53b852eef58affb81acad055549f4749eab.tar.gz |
Merge "Support lambda expression in mypy plugin" into main
-rw-r--r-- | doc/build/changelog/unreleased_14/8196.rst | 7 | ||||
-rw-r--r-- | lib/sqlalchemy/ext/mypy/infer.py | 5 | ||||
-rw-r--r-- | test/ext/mypy/plugin_files/lambda_default.py | 11 |
3 files changed, 23 insertions, 0 deletions
diff --git a/doc/build/changelog/unreleased_14/8196.rst b/doc/build/changelog/unreleased_14/8196.rst new file mode 100644 index 000000000..d5afbb8f7 --- /dev/null +++ b/doc/build/changelog/unreleased_14/8196.rst @@ -0,0 +1,7 @@ +.. change:: + :tags: bug, mypy + :tickets: 8196 + + Fixed a crash of the mypy plugin when using a lambda as a Column + default. Pull request curtesy of tchapi. + diff --git a/lib/sqlalchemy/ext/mypy/infer.py b/lib/sqlalchemy/ext/mypy/infer.py index 08035d74c..479be40c3 100644 --- a/lib/sqlalchemy/ext/mypy/infer.py +++ b/lib/sqlalchemy/ext/mypy/infer.py @@ -16,6 +16,7 @@ from mypy.nodes import AssignmentStmt from mypy.nodes import CallExpr from mypy.nodes import Expression from mypy.nodes import FuncDef +from mypy.nodes import LambdaExpr from mypy.nodes import MemberExpr from mypy.nodes import NameExpr from mypy.nodes import RefExpr @@ -423,6 +424,10 @@ def _infer_type_from_decl_column( elif isinstance(column_arg, (StrExpr,)): # x = Column("name", String), go to next argument continue + elif isinstance(column_arg, (LambdaExpr,)): + # x = Column("name", String, default=lambda: uuid.uuid4()) + # go to next argument + continue else: assert False diff --git a/test/ext/mypy/plugin_files/lambda_default.py b/test/ext/mypy/plugin_files/lambda_default.py new file mode 100644 index 000000000..a1019f0d0 --- /dev/null +++ b/test/ext/mypy/plugin_files/lambda_default.py @@ -0,0 +1,11 @@ +import uuid + +from sqlalchemy import Column +from sqlalchemy import String +from sqlalchemy.orm import declarative_base + +Base = declarative_base() + + +class MyClass(Base): + id = Column(String, default=lambda: uuid.uuid4(), primary_key=True) |