From 86d047a2af578e7ee1ac0ea1f718a1d2aa8dcb2a Mon Sep 17 00:00:00 2001 From: Misha Brukman Date: Mon, 4 Nov 2024 20:18:16 -0500 Subject: [PATCH] Use `override` from `typing_extensions` Instead of a having a custom implementation, use the `override` implementation from the `typing_extensions` module which properly handles Python versions before 3.12 which don't yet include support for `typing.override`. Add latest `typing-extensions` to `requirements.txt`. Instead of using `/usr/bin/python` runline from each Python file, use `python` or `python3` runner which will pick up the earliest appearing Python binary which we also previously used when we installed `typing-extensions` module via `python -m pip install`. On GitHub Actions, this is not `/usr/bin/python`, so if we install using the default Python, then `/usr/bin/python` will complain of a missing package. This only appears to fail on Ubuntu 22.04, but was still annoying to track down. --- .github/workflows/main.yml | 5 +++++ csv2txf_test.sh | 2 +- decorators.py | 33 --------------------------------- interactive_brokers.py | 2 +- requirements.txt | 9 +-------- run_all_tests.sh | 2 +- tdameritrade.py | 2 +- vanguard.py | 2 +- 8 files changed, 11 insertions(+), 46 deletions(-) delete mode 100644 decorators.py diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 9ce3624..92999f6 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -49,6 +49,11 @@ jobs: python-version: ${{ matrix.python }} cache: 'pip' + - name: Install general Python deps + run: | + python -m pip install --upgrade pip + python -m pip install -r requirements.txt + - name: Run tests run: make test VERBOSE=1 diff --git a/csv2txf_test.sh b/csv2txf_test.sh index 60cb1ee..35e7f31 100755 --- a/csv2txf_test.sh +++ b/csv2txf_test.sh @@ -24,7 +24,7 @@ fi declare -i num_failures=0 # macOS 12+ doesn't provide /usr/bin/python, but provides /usr/bin/python3 -PYTHON="" +PYTHON="python" if ! [[ -f "/usr/bin/python" ]] && [[ -f "/usr/bin/python3" ]]; then PYTHON="python3" fi diff --git a/decorators.py b/decorators.py deleted file mode 100644 index d552ef8..0000000 --- a/decorators.py +++ /dev/null @@ -1,33 +0,0 @@ -# Copyright 2024 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -from __future__ import annotations - -import sys - - -if (sys.version_info.major, sys.version_info.minor) >= (3, 12): - # This was added in Python 3.12: - # - # * https://docs.python.org/3/library/typing.html#typing.override - # * https://peps.python.org/pep-0698/ - from typing import override -else: - from typing import TypeVar - - _F = TypeVar('_F') - - def override(func: _F) -> _F: - """No-op @override for Python versions prior to 3.12.""" - return func diff --git a/interactive_brokers.py b/interactive_brokers.py index 43c0996..17087d0 100644 --- a/interactive_brokers.py +++ b/interactive_brokers.py @@ -26,7 +26,7 @@ from typing import Optional from broker import Broker -from decorators import override +from typing_extensions import override import utils diff --git a/requirements.txt b/requirements.txt index 6c0b23e..a24812c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,8 +1 @@ -# We don't need any content here, but the absence of this file breaks -# actions/setup-python in GitHub Actions, e.g., -# -# https://github.com/mbrukman/csv2txf/actions/runs/10437183622/job/28903088310?pr=29 -# -# > Error: No file in /Users/runner/work/csv2txf/csv2txf matched to -# > [**/requirements.txt or **/pyproject.toml], make sure you have checked out -# > the target repository +typing-extensions ~= 4.12.2 diff --git a/run_all_tests.sh b/run_all_tests.sh index e70b252..dd662f9 100755 --- a/run_all_tests.sh +++ b/run_all_tests.sh @@ -17,7 +17,7 @@ declare -i success=0 # macOS 12+ doesn't provide /usr/bin/python, but provides /usr/bin/python3 -PYTHON="" +PYTHON="python" if ! [[ -f "/usr/bin/python" ]] && [[ -f "/usr/bin/python3" ]]; then PYTHON="python3" fi diff --git a/tdameritrade.py b/tdameritrade.py index 62a3f1a..00bf48e 100644 --- a/tdameritrade.py +++ b/tdameritrade.py @@ -32,7 +32,7 @@ from typing import Optional from broker import Broker -from decorators import override +from typing_extensions import override import utils diff --git a/vanguard.py b/vanguard.py index 93ac15a..7d41e93 100644 --- a/vanguard.py +++ b/vanguard.py @@ -30,7 +30,7 @@ from typing import Optional from broker import Broker -from decorators import override +from typing_extensions import override import utils