From 8f873937bdee0d3008286e87a264224f50e6ef84 Mon Sep 17 00:00:00 2001 From: Daniele Varrazzo Date: Sun, 20 Mar 2022 01:44:07 +0100 Subject: [PATCH] perf: use `b"'"[0]` as const value to represent `ord("'")` The value is expanded at compile time:: >>> dis.dis('b"\'"[0]') 1 0 LOAD_CONST 0 (39) 2 RETURN_VALUE --- psycopg/psycopg/sql.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/psycopg/psycopg/sql.py b/psycopg/psycopg/sql.py index eb5be8aef..4e0d0d3de 100644 --- a/psycopg/psycopg/sql.py +++ b/psycopg/psycopg/sql.py @@ -395,7 +395,7 @@ class Literal(Composable): rv = dumper.quote(self._obj) # If the result is quoted and the oid not unknown, # add an explicit type cast. - if rv[-1] == 39 and dumper.oid: + if rv[-1] == b"'"[0] and dumper.oid: ti = tx.adapters.types.get(dumper.oid) if ti: # TODO: ugly encoding just to be decoded by as_string() -- 2.47.3