diff options
| author | Gord Thompson <gord@gordthompson.com> | 2020-12-07 18:37:29 -0500 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2020-12-08 19:54:05 -0500 |
| commit | b71e46f0470964358d44aec08f940260f78691f0 (patch) | |
| tree | 44c9b5934ad550b4688700e8124204411e42190f /lib/sqlalchemy/util | |
| parent | 18b1b261ff988549e75b011f2f4296fb13b24d64 (diff) | |
| download | sqlalchemy-b71e46f0470964358d44aec08f940260f78691f0.tar.gz | |
Implement `TypeEngine.as_generic`
Added :meth:`_types.TypeEngine.as_generic` to map dialect-specific types,
such as :class:`sqlalchemy.dialects.mysql.INTEGER`, with the "best match"
generic SQLAlchemy type, in this case :class:`_types.Integer`. Pull
request courtesy Andrew Hannigan.
Abstract away how we check for "overridden methods" so it is more
clear what the intent is and that the methodology can be
independently tested.
Fixes: #5659
Closes: #5714
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/5714
Pull-request-sha: 91afb9a0ba3bfa81a1ded80c025989213cf6e4eb
Change-Id: Ic54d6690ecc10dc69e6e72856d5620036cea472a
Diffstat (limited to 'lib/sqlalchemy/util')
| -rw-r--r-- | lib/sqlalchemy/util/__init__.py | 1 | ||||
| -rw-r--r-- | lib/sqlalchemy/util/langhelpers.py | 15 |
2 files changed, 16 insertions, 0 deletions
diff --git a/lib/sqlalchemy/util/__init__.py b/lib/sqlalchemy/util/__init__.py index 2db1adb8d..f4363d03c 100644 --- a/lib/sqlalchemy/util/__init__.py +++ b/lib/sqlalchemy/util/__init__.py @@ -147,6 +147,7 @@ from .langhelpers import md5_hex # noqa from .langhelpers import memoized_instancemethod # noqa from .langhelpers import memoized_property # noqa from .langhelpers import MemoizedSlots # noqa +from .langhelpers import method_is_overridden # noqa from .langhelpers import methods_equivalent # noqa from .langhelpers import monkeypatch_proxied_specials # noqa from .langhelpers import NoneType # noqa diff --git a/lib/sqlalchemy/util/langhelpers.py b/lib/sqlalchemy/util/langhelpers.py index 8d6c2d8ee..b0963ce43 100644 --- a/lib/sqlalchemy/util/langhelpers.py +++ b/lib/sqlalchemy/util/langhelpers.py @@ -114,6 +114,21 @@ def clsname_as_plain_name(cls): ) +def method_is_overridden(instance_or_cls, against_method): + """Return True if the two class methods don't match.""" + + if not isinstance(instance_or_cls, type): + current_cls = instance_or_cls.__class__ + else: + current_cls = instance_or_cls + + method_name = against_method.__name__ + + current_method = getattr(current_cls, method_name) + + return current_method != against_method + + def decode_slice(slc): """decode a slice object as sent to __getitem__. |
