]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
Upgrade flake to 3.9
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>
Thu, 30 Sep 2021 18:58:43 +0000 (20:58 +0200)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Thu, 30 Sep 2021 18:58:43 +0000 (20:58 +0200)
This version reports an error if a name is declared but not defined, so
set the lazy imported objects to None and deal with mypy complaining.

psycopg/psycopg/types/net.py
psycopg/psycopg/types/uuid.py
psycopg/setup.py

index 614fe566d00592223ebedeb662b247ed1b3bbdf6..264f8dbf7e3090f51b6002f30b3e3d10730af265 100644 (file)
@@ -19,16 +19,15 @@ Interface = Union["ipaddress.IPv4Interface", "ipaddress.IPv6Interface"]
 Network = Union["ipaddress.IPv4Network", "ipaddress.IPv6Network"]
 
 # These objects will be imported lazily
-imported = False
-ip_address: Callable[[str], Address]
-ip_interface: Callable[[str], Interface]
-ip_network: Callable[[str], Network]
-IPv4Address: "Type[ipaddress.IPv4Address]"
-IPv6Address: "Type[ipaddress.IPv6Address]"
-IPv4Interface: "Type[ipaddress.IPv4Interface]"
-IPv6Interface: "Type[ipaddress.IPv6Interface]"
-IPv4Network: "Type[ipaddress.IPv4Network]"
-IPv6Network: "Type[ipaddress.IPv6Network]"
+ip_address: Callable[[str], Address] = None  # type: ignore[assignment]
+ip_interface: Callable[[str], Interface] = None  # type: ignore[assignment]
+ip_network: Callable[[str], Network] = None  # type: ignore[assignment]
+IPv4Address: "Type[ipaddress.IPv4Address]" = None  # type: ignore[assignment]
+IPv6Address: "Type[ipaddress.IPv6Address]" = None  # type: ignore[assignment]
+IPv4Interface: "Type[ipaddress.IPv4Interface]" = None  # type: ignore[assignment]
+IPv6Interface: "Type[ipaddress.IPv6Interface]" = None  # type: ignore[assignment]
+IPv4Network: "Type[ipaddress.IPv4Network]" = None  # type: ignore[assignment]
+IPv6Network: "Type[ipaddress.IPv6Network]" = None  # type: ignore[assignment]
 
 PGSQL_AF_INET = 2
 PGSQL_AF_INET6 = 3
@@ -38,18 +37,16 @@ IPV6_PREFIXLEN = 128
 
 class _LazyIpaddress:
     def _ensure_module(self) -> None:
-        global imported, ip_address, ip_interface, ip_network
+        global ip_address, ip_interface, ip_network
         global IPv4Address, IPv6Address, IPv4Interface, IPv6Interface
         global IPv4Network, IPv6Network
 
-        if not imported:
+        if not ip_address:
             from ipaddress import ip_address, ip_interface, ip_network
             from ipaddress import IPv4Address, IPv6Address
             from ipaddress import IPv4Interface, IPv6Interface
             from ipaddress import IPv4Network, IPv6Network
 
-            imported = True
-
 
 class InterfaceDumper(Dumper):
 
index a3b962d83f8e77c98c82f72a6fa6b1dfc34ff02d..3ff43b9376fa054e2edf7c0dfa6bf25db01795ee 100644 (file)
@@ -15,8 +15,7 @@ if TYPE_CHECKING:
     import uuid
 
 # Importing the uuid module is slow, so import it only on request.
-imported = False
-UUID: Callable[..., "uuid.UUID"]
+UUID: Callable[..., "uuid.UUID"] = None  # type: ignore[assignment]
 
 
 class UUIDDumper(Dumper):
@@ -38,12 +37,10 @@ class UUIDBinaryDumper(UUIDDumper):
 class UUIDLoader(Loader):
     def __init__(self, oid: int, context: Optional[AdaptContext] = None):
         super().__init__(oid, context)
-        global imported, UUID
-        if not imported:
+        global UUID
+        if not UUID:
             from uuid import UUID
 
-            imported = True
-
     def load(self, data: Buffer) -> "uuid.UUID":
         if isinstance(data, memoryview):
             data = bytes(data)
index e71b757388d7dadfeefcf317f9b069f6ef5143a6..04d41563248761dc3fc2fc97499627c1d082fee2 100644 (file)
@@ -47,7 +47,7 @@ extras_require = {
     # Requirements needed for development
     "dev": [
         "black",
-        "flake8 >= 3.8, < 3.9",
+        "flake8 ~= 3.9.2",
         "mypy >= 0.812",
         "wheel",
     ],