From 74d36cd83c4a52bea34df8cf00d9e6f6d97f7402 Mon Sep 17 00:00:00 2001 From: Kogia-sima Date: Tue, 12 Nov 2024 22:52:10 +0900 Subject: [PATCH] Fix compatibility issue with cPython<=3.11.3 --- src/anomalib/data/utils/download.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/anomalib/data/utils/download.py b/src/anomalib/data/utils/download.py index 7df5da1403..05afa30b30 100644 --- a/src/anomalib/data/utils/download.py +++ b/src/anomalib/data/utils/download.py @@ -8,6 +8,7 @@ import logging import os import re +import sys import tarfile from collections.abc import Iterable from dataclasses import dataclass @@ -231,7 +232,11 @@ def safe_extract(tar_file: TarFile, root: Path, members: list[TarInfo]) -> None: for member in members: # check if the file already exists if not (root / member.name).exists(): - tar_file.extract(member, root, filter="data") + if sys.version_info[:3] >= (3, 11, 4): + # filter argument only works with python>=3.11.4 + tar_file.extract(member, root, filter="data") + else: + tar_file.extract(member, root) def generate_hash(file_path: str | Path, algorithm: str = "sha256") -> str: