From 063c9b47c4449a00a4596305013719256b814b40 Mon Sep 17 00:00:00 2001 From: Andrew Soltan Date: Wed, 3 Jul 2024 13:33:20 +0100 Subject: [PATCH] Changes to restore Python 3.8 compatibility (#1) * Changes to add Python 3.8 compatability 1. Revert to old-style typing importing to add Python 3.8 backwards (capitalisation of List and Dict) 2. Correct parynthesis use around file opening command for python 3.8 compatability * Update github workflow to include python 3.8 * Changes for haslib compatability Remove references to usedforsecurity for hashlib compatiablity * Correct syntax --- .github/workflows/main.yaml | 2 +- app/data/anno_dataset.py | 2 +- app/domain.py | 4 ++-- app/processors/metrics_collector.py | 8 ++++---- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index 10c38fc..5adf684 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -12,7 +12,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: [ '3.9', '3.10' ] + python-version: [ '3.8', '3.9', '3.10' ] max-parallel: 2 steps: diff --git a/app/data/anno_dataset.py b/app/data/anno_dataset.py index 59c422c..2176f01 100644 --- a/app/data/anno_dataset.py +++ b/app/data/anno_dataset.py @@ -45,7 +45,7 @@ def _generate_examples(self, filepaths: List[Path]) -> Iterable[Tuple[str, Dict] def generate_examples(filepaths: List[Path]) -> Iterable[Tuple[str, Dict]]: id_ = 1 for filepath in filepaths: - with (open(str(filepath), "r") as f): + with open(str(filepath), "r") as f: annotations = json.load(f) filtered = filter_by_concept_ids(annotations) for project in filtered["projects"]: diff --git a/app/domain.py b/app/domain.py index 37b8f42..224939f 100644 --- a/app/domain.py +++ b/app/domain.py @@ -56,8 +56,8 @@ class Annotation(BaseModel): categories: Optional[List[str]] = Field(default=None, description="The categories to which the annotation concept belongs") accuracy: Optional[float] = Field(default=None, description="The confidence score of the annotation") text: Optional[str] = Field(default=None, description="The string literal of the annotation span") - meta_anns: Optional[dict] = Field(default=None, description="The meta annotations") - athena_ids: Optional[list[dict]] = Field(default=None, description="The OHDSI Athena concept IDs") + meta_anns: Optional[Dict] = Field(default=None, description="The meta annotations") + athena_ids: Optional[List[Dict]] = Field(default=None, description="The OHDSI Athena concept IDs") @root_validator() def _validate(cls, values: Dict[str, Any]) -> Dict[str, Any]: diff --git a/app/processors/metrics_collector.py b/app/processors/metrics_collector.py index 865aba8..0bd5409 100644 --- a/app/processors/metrics_collector.py +++ b/app/processors/metrics_collector.py @@ -11,8 +11,8 @@ ANCHOR_DELIMITER = ";" DOC_SPAN_DELIMITER = "_" -STATE_MISSING = hashlib.sha1("MISSING".encode("utf-8"), usedforsecurity=False).hexdigest() -META_STATE_MISSING = hashlib.sha1("{}".encode("utf-8"), usedforsecurity=False).hexdigest() +STATE_MISSING = hashlib.sha1("MISSING".encode("utf-8")).hexdigest() +META_STATE_MISSING = hashlib.sha1("{}".encode("utf-8")).hexdigest() def sanity_check_model_with_trainer_export(trainer_export: Union[str, TextIO, Dict], @@ -425,12 +425,12 @@ def _filter_docspan_by_value(docspan2value: Dict, value: str) -> Dict: def _get_hashed_annotation_state(annotation: Dict, state_keys: Set[str]) -> str: - return hashlib.sha1("_".join([str(annotation.get(key)) for key in state_keys]).encode("utf-8"), usedforsecurity=False).hexdigest() + return hashlib.sha1("_".join([str(annotation.get(key)) for key in state_keys]).encode("utf-8")).hexdigest() def _get_hashed_meta_annotation_state(meta_anno: Dict) -> str: meta_anno = {key: val for key, val in sorted(meta_anno.items(), key=lambda item: item[0])} # may not be necessary - return hashlib.sha1(str(meta_anno).encode("utf=8"), usedforsecurity=False).hexdigest() + return hashlib.sha1(str(meta_anno).encode("utf=8")).hexdigest() def _get_cohens_kappa_coefficient(y1_labels: List, y2_labels: List) -> float: