diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2021-04-19 18:03:12 -0400 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2021-04-20 13:05:49 -0400 |
commit | 0e1a011aa3091aa2d6d95b269ff6da518db8e1a3 (patch) | |
tree | f9c90c014aba42801f671455f812d303c2cf2d80 /test/ext/mypy/test_mypy_plugin_py3k.py | |
parent | a58c99977eafc5f69a3e37f9ddcc328698e7fe1e (diff) | |
download | sqlalchemy-0e1a011aa3091aa2d6d95b269ff6da518db8e1a3.tar.gz |
Re-infer statements that got more specific on subsequent pass
Fixed issue where mypy plugin would not correctly interpret an explicit
:class:`_orm.Mapped` annotation in conjunction with a
:func:`_orm.relationship` that refers to a class by string name; the
correct annotation would be downgraded to a less specific one leading to
typing errors.
The thing figured out here is that after we've already scanned
a class in the semanal stage and created DeclClassApplied,
when we are called again with that same DeclClassApplied, for this
specific kind of case we actually now have *better* types than
we did before, where the left side that looked like
List?[Address?] now seems to say
builtins.list[official.module.Address] - so let's take the
right side expression again, this time embedded in our
Mapped._empty_constructor() expression, and run the infer
all over again just like mypy would. Just not setting the
"wrong" type here fixed the test cases but by re-applying the
whole infer we get the correct Mapped[] on the left side too.
Fixes: #6255
Change-Id: Iafe7254374f685a8458c7a1db82aafc2ed6d0232
Diffstat (limited to 'test/ext/mypy/test_mypy_plugin_py3k.py')
-rw-r--r-- | test/ext/mypy/test_mypy_plugin_py3k.py | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/test/ext/mypy/test_mypy_plugin_py3k.py b/test/ext/mypy/test_mypy_plugin_py3k.py index 4ab16540d..c853f7be5 100644 --- a/test/ext/mypy/test_mypy_plugin_py3k.py +++ b/test/ext/mypy/test_mypy_plugin_py3k.py @@ -171,9 +171,13 @@ class MypyPluginTest(fixtures.TestBase): errors.append(e) for num, is_mypy, msg in expected_errors: + msg = msg.replace("'", '"') prefix = "[SQLAlchemy Mypy plugin] " if not is_mypy else "" for idx, errmsg in enumerate(errors): - if f"{filename}:{num + 1}: error: {prefix}{msg}" in errmsg: + if ( + f"{filename}:{num + 1}: error: {prefix}{msg}" + in errmsg.replace("'", '"') + ): break else: continue |