Skip to content

Commit f2606d1

Browse files
authored
Update pyproject.toml license settings and minimum python version (#191)
1 parent 9daa5c9 commit f2606d1

File tree

24 files changed

+119
-115
lines changed

24 files changed

+119
-115
lines changed

flow/record/adapter/broker.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from typing import TYPE_CHECKING
44

55
from flow.broker import Publisher, Subscriber
6+
67
from flow.record.adapter import AbstractReader, AbstractWriter
78

89
if TYPE_CHECKING:

flow/record/adapter/csvfile.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ def __iter__(self) -> Iterator[Record]:
118118
ctx = get_app_context()
119119
selector = self.selector
120120
for row in self.reader:
121-
rdict = dict(zip(self.fields, row))
121+
rdict = dict(zip(self.fields, row, strict=False))
122122
record = self.desc.init_from_dict(rdict)
123123
if match_record_with_context(record, selector, ctx):
124124
yield record

flow/record/adapter/sqlite.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ def read_table(self, table_name: str) -> Iterator[Record]:
192192
row[idx] = None
193193
elif isinstance(value, str):
194194
row[idx] = value.encode(errors="surrogateescape")
195-
yield descriptor_cls.init_from_dict(dict(zip(fnames, row)))
195+
yield descriptor_cls.init_from_dict(dict(zip(fnames, row, strict=False)))
196196

197197
def __iter__(self) -> Iterator[Record]:
198198
"""Iterate over all tables in the database and yield records."""

flow/record/adapter/xlsx.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ def __iter__(self) -> Iterator[Record]:
144144
for col in row
145145
if col.value and not col.value.startswith("_")
146146
]
147-
desc = record.RecordDescriptor(desc_name, list(zip(field_types, field_names)))
147+
desc = record.RecordDescriptor(desc_name, list(zip(field_types, field_names, strict=False)))
148148
continue
149149

150150
record_values = []

flow/record/base.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
TYPE_CHECKING,
2222
Any,
2323
BinaryIO,
24-
Callable,
2524
)
2625
from urllib.parse import parse_qsl, urlparse
2726

@@ -60,7 +59,7 @@
6059
from flow.record.whitelist import WHITELIST, WHITELIST_TREE
6160

6261
if TYPE_CHECKING:
63-
from collections.abc import Iterator, Mapping, Sequence
62+
from collections.abc import Callable, Iterator, Mapping, Sequence
6463

6564
from flow.record.adapter import AbstractReader, AbstractWriter
6665

@@ -1000,7 +999,7 @@ def merge_record_descriptors(
1000999
field_map[fname] = ftype
10011000
if name is None and descriptors:
10021001
name = descriptors[0].name
1003-
return RecordDescriptor(name, zip(field_map.values(), field_map.keys()))
1002+
return RecordDescriptor(name, zip(field_map.values(), field_map.keys(), strict=False))
10041003

10051004

10061005
def extend_record(

flow/record/context.py

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from __future__ import annotations
22

3-
import sys
43
from contextlib import contextmanager
54
from contextvars import ContextVar
65
from dataclasses import dataclass
@@ -37,15 +36,7 @@ def fresh_app_context() -> Generator[AppContext, None, None]:
3736
APP_CONTEXT.reset(token)
3837

3938

40-
# Use slots=True on dataclass for better performance which requires Python 3.10 or later.
41-
# This can be removed when we drop support for Python 3.9.
42-
if sys.version_info >= (3, 10):
43-
app_dataclass = dataclass(slots=True) # novermin
44-
else:
45-
app_dataclass = dataclass
46-
47-
48-
@app_dataclass
39+
@dataclass(slots=True)
4940
class AppContext:
5041
"""Context for the application, holding metrics like amount of processed records."""
5142

flow/record/fieldtypes/net/ip.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,15 @@
1111
ip_interface,
1212
ip_network,
1313
)
14-
from typing import Union
1514

1615
from flow.record.base import FieldType
1716
from flow.record.fieldtypes import defang
1817

19-
_IPNetwork = Union[IPv4Network, IPv6Network]
20-
_IPAddress = Union[IPv4Address, IPv6Address]
21-
_IPInterface = Union[IPv4Interface, IPv6Interface]
22-
_ConversionTypes = Union[str, int, bytes]
23-
_IPTypes = Union[_IPNetwork, _IPAddress, _IPInterface]
18+
_IPNetwork = IPv4Network | IPv6Network
19+
_IPAddress = IPv4Address | IPv6Address
20+
_IPInterface = IPv4Interface | IPv6Interface
21+
_ConversionTypes = str | int | bytes
22+
_IPTypes = _IPNetwork | _IPAddress | _IPInterface
2423

2524

2625
class ipaddress(FieldType):

flow/record/fieldtypes/net/ipv4.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def addr_str(s: address | int | str) -> str:
2929

3030

3131
def mask_to_bits(n: int) -> int:
32-
return bin(n).count("1")
32+
return n.bit_count()
3333

3434

3535
def bits_to_mask(b: int) -> int:
@@ -51,7 +51,7 @@ def __init__(self, addr: str, netmask: int | None = None):
5151
raise TypeError(f"Subnet() argument 1 must be string, not {type(addr).__name__}")
5252

5353
if netmask is None:
54-
ip, sep, mask = addr.partition("/")
54+
ip, _, mask = addr.partition("/")
5555
self.mask = bits_to_mask(int(mask)) if mask else 0xFFFFFFFF
5656
self.net = addr_long(ip)
5757
else:
@@ -93,7 +93,7 @@ def __init__(self):
9393
def load(self, path: str | Path) -> None:
9494
with Path(path).open() as fh:
9595
for line in fh:
96-
entry, desc = line.split(" ", 1)
96+
entry, _ = line.split(" ", 1)
9797
self.subnets.append(subnet(entry))
9898

9999
def add(self, entry: str) -> None:

flow/record/selector.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
import ast
55
import operator
66
import re
7-
from typing import TYPE_CHECKING, Any, Callable
7+
from typing import TYPE_CHECKING, Any
88

99
from flow.record.base import GroupedRecord, Record, dynamic_fieldtype
1010
from flow.record.fieldtypes import net
1111
from flow.record.whitelist import WHITELIST, WHITELIST_TREE
1212

1313
if TYPE_CHECKING:
14-
from collections.abc import Iterator
14+
from collections.abc import Callable, Iterator
1515

1616
try:
1717
import astor

flow/record/utils.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@
55
import sys
66
import warnings
77
from functools import wraps
8-
from typing import Any, BinaryIO, Callable, TextIO
8+
from typing import TYPE_CHECKING, Any, BinaryIO, TextIO
9+
10+
if TYPE_CHECKING:
11+
from collections.abc import Callable
912

1013
LOGGING_TRACE_LEVEL = 5
1114

0 commit comments

Comments
 (0)