]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
Use class instead of type() to create the specific hstore dumper
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>
Tue, 21 Sep 2021 16:03:52 +0000 (17:03 +0100)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Tue, 21 Sep 2021 17:01:32 +0000 (18:01 +0100)
The name is not variable so it's not useful to use the less common
constructor.

psycopg/psycopg/types/hstore.py

index e45b9414f131c584dbe0dd9592265356c0baac08..2980994a5447861ffa5cf8b7aa23187a24aa6429 100644 (file)
@@ -5,7 +5,7 @@ Dict to hstore adaptation
 # Copyright (C) 2021 The Psycopg Team
 
 import re
-from typing import Dict, List, Optional, Type
+from typing import Dict, List, Optional
 
 from .. import errors as e
 from .. import postgres
@@ -118,10 +118,10 @@ def register_hstore(
     adapters = context.adapters if context else postgres.adapters
 
     # Generate and register a customized text dumper
-    dumper: Type[BaseHstoreDumper] = type(
-        "HstoreDumper", (BaseHstoreDumper,), {"oid": info.oid}
-    )
-    adapters.register_dumper(dict, dumper)
+    class HstoreDumper(BaseHstoreDumper):
+        oid = info.oid
+
+    adapters.register_dumper(dict, HstoreDumper)
 
     # register the text loader on the oid
     adapters.register_loader(info.oid, HstoreLoader)