From: Daniele Varrazzo Date: Sun, 30 Jan 2022 13:38:47 +0000 (+0000) Subject: Move to using the stable black version 22.1.0 X-Git-Tag: pool-3.1~3^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a452d6a630b4c722bde3b5211d5e1ef705fbc27f;p=thirdparty%2Fpsycopg.git Move to using the stable black version 22.1.0 --- diff --git a/psycopg/psycopg/copy.py b/psycopg/psycopg/copy.py index df0f23732..6ddadd706 100644 --- a/psycopg/psycopg/copy.py +++ b/psycopg/psycopg/copy.py @@ -576,7 +576,7 @@ def _format_row_text( b = dumper.dump(item) out += _dump_re.sub(_dump_sub, b) else: - out += br"\N" + out += rb"\N" out += b"\t" out[-1:] = b"\n" diff --git a/psycopg/psycopg/types/array.py b/psycopg/psycopg/types/array.py index 9b7d24016..f1c6f621a 100644 --- a/psycopg/psycopg/types/array.py +++ b/psycopg/psycopg/types/array.py @@ -139,7 +139,7 @@ class ListDumper(BaseListDumper): # Double quotes and backslashes embedded in element values will be # backslash-escaped. - _re_esc = re.compile(br'(["\\])') + _re_esc = re.compile(rb'(["\\])') def dump(self, obj: List[Any]) -> bytes: tokens: List[bytes] = [] @@ -159,7 +159,7 @@ class ListDumper(BaseListDumper): if needs_quotes(ad): if not isinstance(ad, bytes): ad = bytes(ad) - ad = b'"' + self._re_esc.sub(br"\\\1", ad) + b'"' + ad = b'"' + self._re_esc.sub(rb"\\\1", ad) + b'"' tokens.append(ad) else: tokens.append(b"NULL") @@ -190,7 +190,7 @@ def _get_needs_quotes_regexp(delimiter: bytes) -> Pattern[bytes]: double quotes, backslashes, or white space, or match the word NULL. """ return re.compile( - br"""(?xi) + rb"""(?xi) ^$ # the empty string | ["{}%s\\\s] # or a char to escape | ^null$ # or the word NULL @@ -359,7 +359,7 @@ class ArrayLoader(BaseArrayLoader): v = None else: if t.startswith(b'"'): - t = self._re_unescape.sub(br"\1", t[1:-1]) + t = self._re_unescape.sub(rb"\1", t[1:-1]) v = cast(t) stack[-1].append(v) @@ -367,7 +367,7 @@ class ArrayLoader(BaseArrayLoader): assert rv is not None return rv - _re_unescape = re.compile(br"\\(.)") + _re_unescape = re.compile(rb"\\(.)") @lru_cache() @@ -376,7 +376,7 @@ def _get_array_parse_regexp(delimiter: bytes) -> Pattern[bytes]: Return a regexp to tokenize an array representation into item and brackets """ return re.compile( - br"""(?xi) + rb"""(?xi) ( [{}] # open or closed bracket | " (?: [^"\\] | \\. )* " # or a quoted string | [^"{}%s\\]+ # or an unquoted non-empty string diff --git a/psycopg/psycopg/types/composite.py b/psycopg/psycopg/types/composite.py index 486c03fcc..57881e6b7 100644 --- a/psycopg/psycopg/types/composite.py +++ b/psycopg/psycopg/types/composite.py @@ -44,7 +44,7 @@ class SequenceDumper(RecursiveDumper): if not ad: ad = b'""' elif self._re_needs_quotes.search(ad): - ad = b'"' + self._re_esc.sub(br"\1\1", ad) + b'"' + ad = b'"' + self._re_esc.sub(rb"\1\1", ad) + b'"' parts.append(ad) parts.append(sep) @@ -53,8 +53,8 @@ class SequenceDumper(RecursiveDumper): return b"".join(parts) - _re_needs_quotes = re.compile(br'[",\\\s()]') - _re_esc = re.compile(br"([\\\"])") + _re_needs_quotes = re.compile(rb'[",\\\s()]') + _re_esc = re.compile(rb"([\\\"])") class TupleDumper(SequenceDumper): @@ -106,7 +106,7 @@ class BaseCompositeLoader(RecursiveLoader): if m.group(1): yield None elif m.group(2) is not None: - yield self._re_undouble.sub(br"\1", m.group(2)) + yield self._re_undouble.sub(rb"\1", m.group(2)) else: yield m.group(3) @@ -116,14 +116,14 @@ class BaseCompositeLoader(RecursiveLoader): yield None _re_tokenize = re.compile( - br"""(?x) + rb"""(?x) (,) # an empty token, representing NULL | " ((?: [^"] | "")*) " ,? # or a quoted string | ([^",)]+) ,? # or an unquoted string """ ) - _re_undouble = re.compile(br'(["\\])\1') + _re_undouble = re.compile(rb'(["\\])\1') class RecordLoader(BaseCompositeLoader): diff --git a/psycopg/psycopg/types/datetime.py b/psycopg/psycopg/types/datetime.py index 7ba84044d..342bda361 100644 --- a/psycopg/psycopg/types/datetime.py +++ b/psycopg/psycopg/types/datetime.py @@ -639,7 +639,7 @@ class TimestamptzBinaryLoader(Loader): class IntervalLoader(Loader): _re_interval = re.compile( - br""" + rb""" (?: ([-+]?\d+) \s+ years? \s* )? # Years (?: ([-+]?\d+) \s+ mons? \s* )? # Months (?: ([-+]?\d+) \s+ days? \s* )? # Days diff --git a/psycopg/psycopg/types/numeric.py b/psycopg/psycopg/types/numeric.py index b718e86fc..5045895d8 100644 --- a/psycopg/psycopg/types/numeric.py +++ b/psycopg/psycopg/types/numeric.py @@ -139,13 +139,13 @@ class IntDumper(Dumper): _int_numeric_dumper = IntNumericDumper(IntNumeric) def upgrade(self, obj: int, format: PyFormat) -> Dumper: - if -(2 ** 31) <= obj < 2 ** 31: - if -(2 ** 15) <= obj < 2 ** 15: + if -(2**31) <= obj < 2**31: + if -(2**15) <= obj < 2**15: return self._int2_dumper else: return self._int4_dumper else: - if -(2 ** 63) <= obj < 2 ** 63: + if -(2**63) <= obj < 2**63: return self._int8_dumper else: return self._int_numeric_dumper diff --git a/psycopg/psycopg/types/range.py b/psycopg/psycopg/types/range.py index e1e2c73b3..85b270f9e 100644 --- a/psycopg/psycopg/types/range.py +++ b/psycopg/psycopg/types/range.py @@ -338,7 +338,7 @@ def dump_range_text(obj: Range[Any], dump: Callable[[Any], Buffer]) -> Buffer: if not ad: return b'""' elif _re_needs_quotes.search(ad): - return b'"' + _re_esc.sub(br"\1\1", ad) + b'"' + return b'"' + _re_esc.sub(rb"\1\1", ad) + b'"' else: return ad @@ -355,8 +355,8 @@ def dump_range_text(obj: Range[Any], dump: Callable[[Any], Buffer]) -> Buffer: return b"".join(parts) -_re_needs_quotes = re.compile(br'[",\\\s()\[\]]') -_re_esc = re.compile(br"([\\\"])") +_re_needs_quotes = re.compile(rb'[",\\\s()\[\]]') +_re_esc = re.compile(rb"([\\\"])") class RangeBinaryDumper(BaseRangeDumper): diff --git a/psycopg/setup.py b/psycopg/setup.py index 37977c6ab..b9c7897e8 100644 --- a/psycopg/setup.py +++ b/psycopg/setup.py @@ -46,7 +46,7 @@ extras_require = { ], # Requirements needed for development "dev": [ - "black >= 21.12b0", + "black >= 22.1.0", "dnspython >= 2.1", "flake8 >= 4.0", "mypy >= 0.920, != 0.930, != 0.931", diff --git a/tests/constraints.txt b/tests/constraints.txt index 2afc92043..b560cc520 100644 --- a/tests/constraints.txt +++ b/tests/constraints.txt @@ -16,7 +16,7 @@ pytest-cov == 3.0.0 pytest-randomly == 3.10.0 # From the 'dev' extra -black == 21.12b0 +black == 22.1.0 dnspython == 2.1.0 flake8 == 4.0.0 mypy == 0.920 diff --git a/tests/pq/test_escaping.py b/tests/pq/test_escaping.py index 6743dc80f..6262d3f71 100644 --- a/tests/pq/test_escaping.py +++ b/tests/pq/test_escaping.py @@ -153,7 +153,7 @@ def test_escape_string_badenc(pgconn): @pytest.mark.parametrize("data", [(b"hello\00world"), (b"\00\00\00\00")]) def test_escape_bytea(pgconn, data): - exp = br"\x" + b"".join(b"%02x" % c for c in data) + exp = rb"\x" + b"".join(b"%02x" % c for c in data) esc = pq.Escaping(pgconn) rv = esc.escape_bytea(data) assert rv == exp @@ -178,13 +178,13 @@ def test_escape_1char(pgconn): esc = pq.Escaping(pgconn) for c in range(256): rv = esc.escape_bytea(bytes([c])) - exp = br"\x%02x" % c + exp = rb"\x%02x" % c assert rv == exp @pytest.mark.parametrize("data", [(b"hello\00world"), (b"\00\00\00\00")]) def test_unescape_bytea(pgconn, data): - enc = br"\x" + b"".join(b"%02x" % c for c in data) + enc = rb"\x" + b"".join(b"%02x" % c for c in data) esc = pq.Escaping(pgconn) rv = esc.unescape_bytea(enc) assert rv == data diff --git a/tests/types/test_numeric.py b/tests/types/test_numeric.py index 61ef60fe8..ee8d39c7a 100644 --- a/tests/types/test_numeric.py +++ b/tests/types/test_numeric.py @@ -23,8 +23,8 @@ from psycopg.types.numeric import FloatLoader (-1, "'-1'::int"), (42, "'42'::smallint"), (-42, "'-42'::smallint"), - (int(2 ** 63 - 1), "'9223372036854775807'::bigint"), - (int(-(2 ** 63)), "'-9223372036854775808'::bigint"), + (int(2**63 - 1), "'9223372036854775807'::bigint"), + (int(-(2**63)), "'-9223372036854775808'::bigint"), ], ) @pytest.mark.parametrize("fmt_in", PyFormat) @@ -43,18 +43,18 @@ def test_dump_int(conn, val, expr, fmt_in): (-1, "'-1'::smallint"), (42, "'42'::smallint"), (-42, "'-42'::smallint"), - (int(2 ** 15 - 1), f"'{2 ** 15 - 1}'::smallint"), - (int(-(2 ** 15)), f"'{-2 ** 15}'::smallint"), - (int(2 ** 15), f"'{2 ** 15}'::integer"), - (int(-(2 ** 15) - 1), f"'{-2 ** 15 - 1}'::integer"), - (int(2 ** 31 - 1), f"'{2 ** 31 - 1}'::integer"), - (int(-(2 ** 31)), f"'{-2 ** 31}'::integer"), - (int(2 ** 31), f"'{2 ** 31}'::bigint"), - (int(-(2 ** 31) - 1), f"'{-2 ** 31 - 1}'::bigint"), - (int(2 ** 63 - 1), f"'{2 ** 63 - 1}'::bigint"), - (int(-(2 ** 63)), f"'{-2 ** 63}'::bigint"), - (int(2 ** 63), f"'{2 ** 63}'::numeric"), - (int(-(2 ** 63) - 1), f"'{-2 ** 63 - 1}'::numeric"), + (int(2**15 - 1), f"'{2 ** 15 - 1}'::smallint"), + (int(-(2**15)), f"'{-2 ** 15}'::smallint"), + (int(2**15), f"'{2 ** 15}'::integer"), + (int(-(2**15) - 1), f"'{-2 ** 15 - 1}'::integer"), + (int(2**31 - 1), f"'{2 ** 31 - 1}'::integer"), + (int(-(2**31)), f"'{-2 ** 31}'::integer"), + (int(2**31), f"'{2 ** 31}'::bigint"), + (int(-(2**31) - 1), f"'{-2 ** 31 - 1}'::bigint"), + (int(2**63 - 1), f"'{2 ** 63 - 1}'::bigint"), + (int(-(2**63)), f"'{-2 ** 63}'::bigint"), + (int(2**63), f"'{2 ** 63}'::numeric"), + (int(-(2**63) - 1), f"'{-2 ** 63 - 1}'::numeric"), ], ) @pytest.mark.parametrize("fmt_in", PyFormat) @@ -91,12 +91,12 @@ def test_dump_enum(conn, fmt_in): (-1, b" -1"), (42, b"42"), (-42, b" -42"), - (int(2 ** 63 - 1), b"9223372036854775807"), - (int(-(2 ** 63)), b" -9223372036854775808"), - (int(2 ** 63), b"9223372036854775808"), - (int(-(2 ** 63 + 1)), b" -9223372036854775809"), - (int(2 ** 100), b"1267650600228229401496703205376"), - (int(-(2 ** 100)), b" -1267650600228229401496703205376"), + (int(2**63 - 1), b"9223372036854775807"), + (int(-(2**63)), b" -9223372036854775808"), + (int(2**63), b"9223372036854775808"), + (int(-(2**63 + 1)), b" -9223372036854775809"), + (int(2**100), b"1267650600228229401496703205376"), + (int(-(2**100)), b" -1267650600228229401496703205376"), ], ) def test_quote_int(conn, val, expr): diff --git a/tests/types/test_range.py b/tests/types/test_range.py index d7d18ebd6..d1934e799 100644 --- a/tests/types/test_range.py +++ b/tests/types/test_range.py @@ -26,10 +26,10 @@ tzinfo = dt.timezone(dt.timedelta(hours=2)) samples = [ ("int4range", None, None, "()"), ("int4range", 10, 20, "[]"), - ("int4range", -(2 ** 31), (2 ** 31) - 1, "[)"), + ("int4range", -(2**31), (2**31) - 1, "[)"), ("int8range", None, None, "()"), ("int8range", 10, 20, "[)"), - ("int8range", -(2 ** 63), (2 ** 63) - 1, "[)"), + ("int8range", -(2**63), (2**63) - 1, "[)"), ("numrange", Decimal(-100), Decimal("100.123"), "(]"), ("numrange", Decimal(100), None, "()"), ("numrange", None, Decimal(100), "()"), diff --git a/tools/update_oids.py b/tools/update_oids.py index ec0345a6c..4d5ac72c5 100755 --- a/tools/update_oids.py +++ b/tools/update_oids.py @@ -114,7 +114,7 @@ def update_file(fn: Path, queries: List[str]) -> None: istart, iend = [ i for i, line in enumerate(lines) - if re.match(br"\s*#\s*autogenerated:\s+(start|end)", line) + if re.match(rb"\s*#\s*autogenerated:\s+(start|end)", line) ] lines[istart + 1 : iend] = new