]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Clean python UUID imports
authorVlastimil Zíma <vlastimil.zima@nic.cz>
Thu, 30 Jul 2020 07:56:39 +0000 (03:56 -0400)
committersqla-tester <sqla-tester@sqlalchemy.org>
Thu, 30 Jul 2020 07:56:39 +0000 (03:56 -0400)
Fixes: #5482
All supported python versions provide 'uuid' module.

Closes: #5483
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/5483
Pull-request-sha: fc32498a8b639ff21d5898100592782826d2c6dd

Change-Id: I8b41b811da7576f724353425dad5d6f581641b4b

lib/sqlalchemy/dialects/postgresql/base.py
lib/sqlalchemy/dialects/postgresql/pg8000.py
lib/sqlalchemy/dialects/postgresql/psycopg2.py
test/dialect/postgresql/test_types.py

index 5cef5d929b57475a9025e56ccf210ee2b316ff85..3bd7e62d53eebcbd6dbb6d3bea1ebdacba11d434 100644 (file)
@@ -992,6 +992,7 @@ E.g.::
 from collections import defaultdict
 import datetime as dt
 import re
+from uuid import UUID as _python_UUID
 
 from . import array as _array
 from . import hstore as _hstore
@@ -1023,12 +1024,6 @@ from ...types import TEXT
 from ...types import VARCHAR
 
 
-try:
-    from uuid import UUID as _python_UUID  # noqa
-except ImportError:
-    _python_UUID = None
-
-
 IDX_USING = re.compile(r"^(?:btree|hash|gist|gin|[\w_]+)$", re.I)
 
 AUTOCOMMIT_REGEXP = re.compile(
@@ -1302,11 +1297,6 @@ class UUID(sqltypes.TypeEngine):
          DBAPI.
 
          """
-        if as_uuid and _python_UUID is None:
-            raise NotImplementedError(
-                "This version of Python does not support "
-                "the native UUID type."
-            )
         self.as_uuid = as_uuid
 
     def bind_processor(self, dialect):
index 197d11cf4c65ecc22b1541f4dbfc606ecddc3cee..57c8f5a9af2591225be23c43162601645f83ad43 100644 (file)
@@ -69,6 +69,7 @@ of the :ref:`psycopg2 <psycopg2_isolation_level>` dialect:
 """  # noqa
 import decimal
 import re
+from uuid import UUID as _python_UUID
 
 from .base import _DECIMAL_TYPES
 from .base import _FLOAT_TYPES
@@ -86,12 +87,6 @@ from ... import util
 from ...sql.elements import quoted_name
 
 
-try:
-    from uuid import UUID as _python_UUID  # noqa
-except ImportError:
-    _python_UUID = None
-
-
 class _PGNumeric(sqltypes.Numeric):
     def result_processor(self, dialect, coltype):
         if self.asdecimal:
index 850e5717c6299d015672f2d4155b2cafe6f1761f..2161b24fc866394058dc6753a0cd97e5bc898d9e 100644 (file)
@@ -466,6 +466,7 @@ from __future__ import absolute_import
 import decimal
 import logging
 import re
+from uuid import UUID as _python_UUID
 
 from .base import _DECIMAL_TYPES
 from .base import _FLOAT_TYPES
@@ -486,11 +487,6 @@ from ... import util
 from ...engine import cursor as _cursor
 from ...util import collections_abc
 
-try:
-    from uuid import UUID as _python_UUID  # noqa
-except ImportError:
-    _python_UUID = None
-
 
 logger = logging.getLogger("sqlalchemy.dialects.postgresql")
 
index d229892918dec90513bd68028dfb986d8b44711b..95486b19799cab8997c10dba4ae13768ca3f05f6 100644 (file)
@@ -33,7 +33,6 @@ from sqlalchemy import Unicode
 from sqlalchemy import util
 from sqlalchemy.dialects import postgresql
 from sqlalchemy.dialects.postgresql import array
-from sqlalchemy.dialects.postgresql import base
 from sqlalchemy.dialects.postgresql import DATERANGE
 from sqlalchemy.dialects.postgresql import HSTORE
 from sqlalchemy.dialects.postgresql import hstore
@@ -2135,14 +2134,6 @@ class UUIDTest(fixtures.TestBase):
     def test_uuid_array(self, datatype, value1, value2, connection):
         self.test_round_trip(datatype, value1, value2, connection)
 
-    def test_no_uuid_available(self):
-        uuid_type = base._python_UUID
-        base._python_UUID = None
-        try:
-            assert_raises(NotImplementedError, postgresql.UUID, as_uuid=True)
-        finally:
-            base._python_UUID = uuid_type
-
 
 class HStoreTest(AssertsCompiledSQL, fixtures.TestBase):
     __dialect__ = "postgresql"