diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2022-11-09 09:13:44 -0500 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2022-11-09 15:02:29 -0500 |
| commit | ebb54e80a5a52d0cce4cba1abc21c707a42c2c73 (patch) | |
| tree | a72c7d810cffc60cd85d5c7118759ef6be8dae40 /lib/sqlalchemy/util | |
| parent | 8745dcf3e167a68c4665255716eefe138c89a8d2 (diff) | |
| download | sqlalchemy-ebb54e80a5a52d0cce4cba1abc21c707a42c2c73.tar.gz | |
try to support mypy 0.990
mypy introduces a crash we need to work around, also
some new rules. It also has either a behavioral change
regarding how output is rendered in relationship to
files being within sys.path or not, so work around
that for test_mypy_plugin_py3k.py
References: https://github.com/python/mypy/issues/14027
Change-Id: I689c7fe27dc52abee932de9e0fb23b2a2eba76fa
Diffstat (limited to 'lib/sqlalchemy/util')
| -rw-r--r-- | lib/sqlalchemy/util/langhelpers.py | 2 | ||||
| -rw-r--r-- | lib/sqlalchemy/util/typing.py | 49 |
2 files changed, 32 insertions, 19 deletions
diff --git a/lib/sqlalchemy/util/langhelpers.py b/lib/sqlalchemy/util/langhelpers.py index d4dac7249..d8d39f56c 100644 --- a/lib/sqlalchemy/util/langhelpers.py +++ b/lib/sqlalchemy/util/langhelpers.py @@ -1448,7 +1448,7 @@ def duck_type_collection( else: return specimen.__emulates__ # type: ignore - isa = isinstance(specimen, type) and issubclass or isinstance + isa = issubclass if isinstance(specimen, type) else isinstance if isa(specimen, list): return list elif isa(specimen, set): diff --git a/lib/sqlalchemy/util/typing.py b/lib/sqlalchemy/util/typing.py index e4674a44c..9eb761eff 100644 --- a/lib/sqlalchemy/util/typing.py +++ b/lib/sqlalchemy/util/typing.py @@ -1,3 +1,9 @@ +# util/typing.py +# Copyright (C) 2022 the SQLAlchemy authors and contributors +# <see AUTHORS file> +# +# This module is part of SQLAlchemy and is released under +# the MIT License: https://www.opensource.org/licenses/mit-license.php # mypy: allow-untyped-defs, allow-untyped-calls from __future__ import annotations @@ -17,6 +23,7 @@ from typing import Optional from typing import overload from typing import Tuple from typing import Type +from typing import TYPE_CHECKING from typing import TypeVar from typing import Union @@ -368,14 +375,16 @@ class DescriptorReference(Generic[_DESC]): """ - def __get__(self, instance: object, owner: Any) -> _DESC: - ... + if TYPE_CHECKING: - def __set__(self, instance: Any, value: _DESC) -> None: - ... + def __get__(self, instance: object, owner: Any) -> _DESC: + ... - def __delete__(self, instance: Any) -> None: - ... + def __set__(self, instance: Any, value: _DESC) -> None: + ... + + def __delete__(self, instance: Any) -> None: + ... _DESC_co = TypeVar("_DESC_co", bound=DescriptorProto, covariant=True) @@ -389,14 +398,16 @@ class RODescriptorReference(Generic[_DESC_co]): """ - def __get__(self, instance: object, owner: Any) -> _DESC_co: - ... + if TYPE_CHECKING: - def __set__(self, instance: Any, value: Any) -> NoReturn: - ... + def __get__(self, instance: object, owner: Any) -> _DESC_co: + ... - def __delete__(self, instance: Any) -> NoReturn: - ... + def __set__(self, instance: Any, value: Any) -> NoReturn: + ... + + def __delete__(self, instance: Any) -> NoReturn: + ... _FN = TypeVar("_FN", bound=Optional[Callable[..., Any]]) @@ -411,14 +422,16 @@ class CallableReference(Generic[_FN]): """ - def __get__(self, instance: object, owner: Any) -> _FN: - ... + if TYPE_CHECKING: - def __set__(self, instance: Any, value: _FN) -> None: - ... + def __get__(self, instance: object, owner: Any) -> _FN: + ... - def __delete__(self, instance: Any) -> None: - ... + def __set__(self, instance: Any, value: _FN) -> None: + ... + + def __delete__(self, instance: Any) -> None: + ... # $def ro_descriptor_reference(fn: Callable[]) |
