From: Daniele Varrazzo Date: Tue, 21 Sep 2021 16:03:52 +0000 (+0100) Subject: Use class instead of type() to create the specific hstore dumper X-Git-Tag: 3.0~72 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=7f1e69d946d5f85e194bc77b62ec8e820760948e;p=thirdparty%2Fpsycopg.git Use class instead of type() to create the specific hstore dumper The name is not variable so it's not useful to use the less common constructor. --- diff --git a/psycopg/psycopg/types/hstore.py b/psycopg/psycopg/types/hstore.py index e45b9414f..2980994a5 100644 --- a/psycopg/psycopg/types/hstore.py +++ b/psycopg/psycopg/types/hstore.py @@ -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)