Skip to content

Commit b3329cd

Browse files
authored
Python3.14 support (#302)
1 parent 32205f2 commit b3329cd

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

meta_row.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
11
import csv
22
import dataclasses
33
import os
4+
import sys
45
from pathlib import Path
5-
from typing import Union, List, Generator
6+
from typing import Union, List, Generator, Any
67

7-
from constants import ALLOWED_LABELS, LABEL_TRUE, PRIVATE_KEY_CATEGORY, OTHER_CATEGORY
8+
from constants import ALLOWED_LABELS, OTHER_CATEGORY
9+
10+
11+
def _get_annotations(cls) -> dict[str, Any]:
12+
# may be removed when 3.13 support ends
13+
if (3, 13) < sys.version_info:
14+
import annotationlib
15+
return annotationlib.get_annotations(cls.__class__)
16+
return cls.__annotations__
817

918

1019
# dataclass is required for csv writer
@@ -27,9 +36,10 @@ class MetaRow:
2736
Category: str
2837

2938
def __init__(self, row: dict):
30-
if not isinstance(row, dict) or self.__annotations__.keys() != row.keys():
39+
annotations = _get_annotations(self)
40+
if not isinstance(row, dict) or annotations.keys() != row.keys():
3141
raise ValueError(f"ERROR: wrong row {row}")
32-
for key, typ in self.__annotations__.items():
42+
for key, typ in annotations.items():
3343
if key.startswith("__"):
3444
continue
3545
row_val = row.get(key)
@@ -53,7 +63,7 @@ def __init__(self, row: dict):
5363
raise ValueError(f"ERROR: Category must be set {row}")
5464
if ':' in self.Category:
5565
rules = self.Category.split(':')
56-
rule_set=set(rules)
66+
rule_set = set(rules)
5767
if len(rules) != len(rule_set):
5868
raise ValueError(f"ERROR: Each rule must be once in Category {row}")
5969
if OTHER_CATEGORY in rule_set:

0 commit comments

Comments
 (0)