From 3f219c33a4e8bc6a375a2ea589d3f0edd1f9c2f7 Mon Sep 17 00:00:00 2001 From: Niklas Neugebauer <68709968+NiklasNeugebauer@users.noreply.github.com> Date: Fri, 28 Jun 2024 09:19:42 +0200 Subject: [PATCH] make type hints compatible with python 3.8 (#21) * make type hints compatible with python 3.8 * add python 3.8 to pytest matrix * fail-fast: false --- .github/workflows/pytest.yml | 6 +++++- learning_loop_node/detector/outbox.py | 6 +++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/.github/workflows/pytest.yml b/.github/workflows/pytest.yml index 521b4f16..d28c9535 100644 --- a/.github/workflows/pytest.yml +++ b/.github/workflows/pytest.yml @@ -6,12 +6,16 @@ jobs: pytest: runs-on: ubuntu-latest timeout-minutes: 30 + strategy: + matrix: + python-version: [3.8, 3.11] + fail-fast: false steps: - uses: actions/checkout@v2 - name: set up Python uses: actions/setup-python@v2 with: - python-version: "3.11" + python-version: ${{ matrix.python-version }} - name: set up Poetry uses: abatilo/actions-poetry@v2.0.0 with: diff --git a/learning_loop_node/detector/outbox.py b/learning_loop_node/detector/outbox.py index ac69a673..ac5566e8 100644 --- a/learning_loop_node/detector/outbox.py +++ b/learning_loop_node/detector/outbox.py @@ -11,7 +11,7 @@ from multiprocessing import Event from multiprocessing.synchronize import Event as SyncEvent from threading import Thread -from typing import List, Optional +from typing import List, Optional, Tuple, Union import requests from fastapi.encoders import jsonable_encoder @@ -108,7 +108,7 @@ def upload(self): self.log.info('No images found to upload') def _upload_batch(self, items: List[str]): - data: List[tuple[str, TextIOWrapper | BufferedReader]] = [] + data: List[Tuple[str, Union[TextIOWrapper, BufferedReader]]] = [] data = [('files', open(f'{item}/image.json', 'r')) for item in items] data += [('files', open(f'{item}/image.jpg', 'rb')) for item in items] @@ -166,7 +166,7 @@ def get_mode(self) -> OutboxMode: self.log.debug('Outbox: Current mode is %s', current_mode) return current_mode - def set_mode(self, mode: OutboxMode | str): + def set_mode(self, mode: Union[OutboxMode, str]) -> None: ''':param mode: 'continuous_upload' or 'stopped' :raises ValueError: if mode is not a valid OutboxMode :raises TimeoutError: if the upload thread does not terminate within 31 seconds with mode='stopped'