mirror of
https://github.com/pre-commit/pre-commit-hooks.git
synced 2026-04-12 05:54:18 +00:00
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
This commit is contained in:
parent
72ad6dc953
commit
f4cd1ba0d6
813 changed files with 66015 additions and 58839 deletions
|
|
@ -1,6 +1,5 @@
|
|||
# Licensed under the Apache License: http://www.apache.org/licenses/LICENSE-2.0
|
||||
# For details: https://github.com/nedbat/coveragepy/blob/master/NOTICE.txt
|
||||
|
||||
"""
|
||||
Functions to manipulate packed binary representations of number sets.
|
||||
|
||||
|
|
@ -13,12 +12,10 @@ in the blobs should be considered an implementation detail that might change in
|
|||
the future. Use these functions to work with those binary blobs of data.
|
||||
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import sqlite3
|
||||
|
||||
from itertools import zip_longest
|
||||
from typing import Iterable
|
||||
|
||||
|
|
@ -36,10 +33,10 @@ def nums_to_numbits(nums: Iterable[int]) -> bytes:
|
|||
nbytes = max(nums) // 8 + 1
|
||||
except ValueError:
|
||||
# nums was empty.
|
||||
return b""
|
||||
return b''
|
||||
b = bytearray(nbytes)
|
||||
for num in nums:
|
||||
b[num//8] |= 1 << num % 8
|
||||
b[num // 8] |= 1 << num % 8
|
||||
return bytes(b)
|
||||
|
||||
|
||||
|
|
@ -82,7 +79,7 @@ def numbits_intersection(numbits1: bytes, numbits2: bytes) -> bytes:
|
|||
"""
|
||||
byte_pairs = zip_longest(numbits1, numbits2, fillvalue=0)
|
||||
intersection_bytes = bytes(b1 & b2 for b1, b2 in byte_pairs)
|
||||
return intersection_bytes.rstrip(b"\0")
|
||||
return intersection_bytes.rstrip(b'\0')
|
||||
|
||||
|
||||
def numbits_any_intersection(numbits1: bytes, numbits2: bytes) -> bool:
|
||||
|
|
@ -140,8 +137,8 @@ def register_sqlite_functions(connection: sqlite3.Connection) -> None:
|
|||
(47,)
|
||||
)
|
||||
"""
|
||||
connection.create_function("numbits_union", 2, numbits_union)
|
||||
connection.create_function("numbits_intersection", 2, numbits_intersection)
|
||||
connection.create_function("numbits_any_intersection", 2, numbits_any_intersection)
|
||||
connection.create_function("num_in_numbits", 2, num_in_numbits)
|
||||
connection.create_function("numbits_to_nums", 1, lambda b: json.dumps(numbits_to_nums(b)))
|
||||
connection.create_function('numbits_union', 2, numbits_union)
|
||||
connection.create_function('numbits_intersection', 2, numbits_intersection)
|
||||
connection.create_function('numbits_any_intersection', 2, numbits_any_intersection)
|
||||
connection.create_function('num_in_numbits', 2, num_in_numbits)
|
||||
connection.create_function('numbits_to_nums', 1, lambda b: json.dumps(numbits_to_nums(b)))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue