Skip to content

Commit 5d4eaab

Browse files
committed
Update codebase to Python 3.11
- Modernize type hints: `X | None`, `list[X]`, `collections.abc` imports across 28 files - Remove unused code: dead assignments, duplicate methods, legacy files (`exceptions.py`, `windows_notification.py`) - Apply reviewer suggestions: Qt6 enums, `_set_password_visibility` helper, `Version.from_v_str` - Bump `pyproject.toml` to `requires-python = ">=3.11"`, regenerate `poetry.lock` - Update CI/CD workflows to Python 3.11 (Linux containers + macOS brew with `--overwrite`) - Fix code style: `ruff format` + `ruff check --fix`
1 parent 5969ad1 commit 5d4eaab

38 files changed

Lines changed: 172 additions & 337 deletions

.github/workflows/cd-linux-arm64.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
version-check:
1616
name: Check versioning
1717
runs-on: ubuntu-24.04-arm
18-
container: python:3.10-slim-trixie
18+
container: python:3.11-slim-trixie
1919
if: github.event_name == 'release'
2020
steps:
2121
- name: Checkout repository
@@ -41,7 +41,7 @@ jobs:
4141
build-onefile:
4242
name: Build onefile
4343
runs-on: ubuntu-24.04-arm
44-
container: python:3.10-slim-trixie
44+
container: python:3.11-slim-trixie
4545
steps:
4646
- name: Checkout repository
4747
uses: actions/checkout@v6
@@ -80,7 +80,7 @@ jobs:
8080
publish-binary:
8181
name: Publish binary
8282
runs-on: ubuntu-24.04-arm
83-
container: python:3.10-slim-trixie
83+
container: python:3.11-slim-trixie
8484
needs: [build-onefile, version-check]
8585
if: github.event_name == 'release'
8686
permissions:

.github/workflows/cd-linux-x64.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
version-check:
1616
name: Check versioning
1717
runs-on: ubuntu-latest
18-
container: python:3.10-slim-bookworm
18+
container: python:3.11-slim-bookworm
1919
if: github.event_name == 'release'
2020
steps:
2121
- name: Checkout repository
@@ -41,7 +41,7 @@ jobs:
4141
build-onefile:
4242
name: Build onefile
4343
runs-on: ubuntu-latest
44-
container: python:3.10-slim-bookworm
44+
container: python:3.11-slim-bookworm
4545
steps:
4646
- name: Checkout repository
4747
uses: actions/checkout@v6
@@ -80,7 +80,7 @@ jobs:
8080
publish-binary:
8181
name: Publish binary
8282
runs-on: ubuntu-latest
83-
container: python:3.10-slim-bookworm
83+
container: python:3.11-slim-bookworm
8484
needs: [build-onefile, version-check]
8585
if: github.event_name == 'release'
8686
permissions:

.github/workflows/cd-macos-arm64.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ on:
99
workflow_dispatch:
1010

1111
env:
12-
PYTHON_VERSION: "3.10"
12+
PYTHON_VERSION: "3.11"
1313

1414
jobs:
1515
version-check:
@@ -20,7 +20,7 @@ jobs:
2020
- name: Checkout repository
2121
uses: actions/checkout@v6
2222
- name: Install required packages
23-
run: brew install python@${{ env.PYTHON_VERSION }} poetry swig
23+
run: brew install --overwrite python@${{ env.PYTHON_VERSION }} poetry swig
2424
- name: Create virtual environment
2525
run: |
2626
poetry env use python${{ env.PYTHON_VERSION }}
@@ -41,7 +41,7 @@ jobs:
4141
- name: Checkout repository
4242
uses: actions/checkout@v6
4343
- name: Install required packages
44-
run: brew install python@${{ env.PYTHON_VERSION }} poetry swig
44+
run: brew install --overwrite python@${{ env.PYTHON_VERSION }} poetry swig
4545
- name: Create virtual environment
4646
run: |
4747
poetry env use python${{ env.PYTHON_VERSION }}

.github/workflows/cd-macos-intel64.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ on:
99
workflow_dispatch:
1010

1111
env:
12-
PYTHON_VERSION: "3.10"
12+
PYTHON_VERSION: "3.11"
1313

1414
jobs:
1515
version-check:
@@ -20,7 +20,7 @@ jobs:
2020
- name: Checkout repository
2121
uses: actions/checkout@v6
2222
- name: Install required packages
23-
run: brew install python@${{ env.PYTHON_VERSION }} poetry swig
23+
run: brew install --overwrite python@${{ env.PYTHON_VERSION }} poetry swig
2424
- name: Create virtual environment
2525
run: |
2626
poetry env use python${{ env.PYTHON_VERSION }}
@@ -41,7 +41,7 @@ jobs:
4141
- name: Checkout repository
4242
uses: actions/checkout@v6
4343
- name: Install required packages
44-
run: brew install python@${{ env.PYTHON_VERSION }} poetry swig
44+
run: brew install --overwrite python@${{ env.PYTHON_VERSION }} poetry swig
4545
- name: Create virtual environment
4646
run: |
4747
poetry env use python${{ env.PYTHON_VERSION }}

.github/workflows/cd-pypi.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
check-package-version:
1616
name: Check package version
1717
runs-on: ubuntu-latest
18-
container: python:3.10-slim
18+
container: python:3.11-slim
1919
steps:
2020
- name: Checkout repository
2121
uses: actions/checkout@v6
@@ -30,7 +30,7 @@ jobs:
3030
check-tag-version:
3131
name: Check tag version
3232
runs-on: ubuntu-latest
33-
container: python:3.10-slim
33+
container: python:3.11-slim
3434
if: github.event_name == 'release'
3535
steps:
3636
- name: Checkout repository
@@ -48,7 +48,7 @@ jobs:
4848
build:
4949
name: Build
5050
runs-on: ubuntu-latest
51-
container: python:3.10-slim
51+
container: python:3.11-slim
5252
needs: check-package-version
5353
steps:
5454
- name: Checkout repository

.github/workflows/ci.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
pyproject-lock-file-check:
1515
name: Check pyproject syntax
1616
runs-on: ubuntu-latest
17-
container: python:3.10-slim
17+
container: python:3.11-slim
1818
steps:
1919
- name: Checkout repository
2020
uses: actions/checkout@v6
@@ -25,7 +25,7 @@ jobs:
2525
format-code:
2626
name: Check code format
2727
runs-on: ubuntu-latest
28-
container: python:3.10-slim
28+
container: python:3.11-slim
2929
steps:
3030
- name: Checkout repository
3131
uses: actions/checkout@v6
@@ -41,7 +41,7 @@ jobs:
4141
lint-style:
4242
name: Check code style
4343
runs-on: ubuntu-latest
44-
container: python:3.10-slim
44+
container: python:3.11-slim
4545
steps:
4646
- name: Checkout repository
4747
uses: actions/checkout@v6
@@ -57,7 +57,7 @@ jobs:
5757
lint-typing:
5858
name: Check static typing
5959
runs-on: ubuntu-latest
60-
container: python:3.10-slim
60+
container: python:3.11-slim
6161
steps:
6262
- name: Checkout repository
6363
uses: actions/checkout@v6
@@ -84,7 +84,7 @@ jobs:
8484
check-version-accordance-flatpak-metadata:
8585
name: Check for version accordance with Flatpak metadata file
8686
runs-on: ubuntu-latest
87-
container: python:3.10-slim
87+
container: python:3.11-slim
8888
steps:
8989
- name: Checkout repository
9090
uses: actions/checkout@v6

nitrokeyapp/__main__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import sys
2+
from collections.abc import Callable, Generator
23
from contextlib import contextmanager
34
from types import TracebackType
4-
from typing import Any, Callable, Generator, Optional, Type
5+
from typing import Any
56

67
from PySide6 import QtWidgets
78

@@ -11,7 +12,7 @@
1112

1213
@contextmanager
1314
def exception_handler(
14-
hook: Callable[[Type[BaseException], BaseException, Optional[TracebackType]], Any],
15+
hook: Callable[[type[BaseException], BaseException, TracebackType | None], Any],
1516
) -> Generator[None, None, None]:
1617
old_hook = sys.excepthook
1718
sys.excepthook = hook

nitrokeyapp/common_ui.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from dataclasses import dataclass
2-
31
from PySide6.QtCore import QObject, Signal
42

53
from nitrokeyapp.information_box import InfoUi
@@ -15,7 +13,6 @@ def __init__(self) -> None:
1513
super().__init__()
1614

1715

18-
@dataclass
1916
class CommonUi:
2017
touch: TouchUi
2118
info: InfoUi

nitrokeyapp/device_data.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import logging
22
from contextlib import AbstractContextManager
33
from types import TracebackType
4-
from typing import Generic, List, Optional, TypeVar
4+
from typing import Generic, TypeVar
55

66
from nitrokey import nk3, nkpk
77
from nitrokey.nk3 import NK3
@@ -26,9 +26,9 @@ def __enter__(self) -> T:
2626

2727
def __exit__(
2828
self,
29-
exc_type: Optional[type[BaseException]],
30-
exc_val: Optional[BaseException],
31-
exc_tb: Optional[TracebackType],
29+
exc_type: type[BaseException] | None,
30+
exc_val: BaseException | None,
31+
exc_tb: TracebackType | None,
3232
) -> None:
3333
pass
3434

@@ -39,9 +39,9 @@ def __init__(self, device: TrussedBase, using_ccid: bool) -> None:
3939
self.model = device.model
4040
self.updating = False
4141

42-
self._status: Optional[Status] = None
43-
self._uuid: Optional[Uuid] = None
44-
self._version: Optional[Version] = None
42+
self._status: Status | None = None
43+
self._uuid: Uuid | None = None
44+
self._version: Version | None = None
4545
self._device = device
4646
self._using_ccid = using_ccid
4747

@@ -58,7 +58,7 @@ def __repr__(self) -> str:
5858
return f"DeviceData({fields_str})"
5959

6060
@classmethod
61-
def list(cls) -> List["DeviceData"]:
61+
def list(cls) -> list["DeviceData"]:
6262
use_ccid = should_use_ccid()
6363

6464
nk3_devices = [cls(dev, use_ccid) for dev in nk3.list(use_ccid, exclusive=True)]
@@ -108,7 +108,7 @@ def version(self) -> Version:
108108
return self._version
109109

110110
@property
111-
def uuid(self) -> Optional[Uuid]:
111+
def uuid(self) -> Uuid | None:
112112
assert isinstance(self._device, TrussedDevice)
113113
if not self._uuid:
114114
self._uuid = self._device.uuid()
@@ -124,7 +124,7 @@ def uuid_prefix(self) -> str:
124124
return str(self.uuid)[:5]
125125

126126
def open(self) -> AbstractContextManager[TrussedDevice]:
127-
device: Optional[TrussedDevice] = None
127+
device: TrussedDevice | None = None
128128
if self.is_bootloader:
129129
raise RuntimeError("Trying to open a device that is a bootloader")
130130

@@ -148,7 +148,7 @@ def open(self) -> AbstractContextManager[TrussedDevice]:
148148
else:
149149
raise RuntimeError(f"Unknown device model {self._device}")
150150

151-
def update(self, ui: UpdateGUI, image: Optional[str] = None) -> UpdateResult:
151+
def update(self, ui: UpdateGUI, image: str | None = None) -> UpdateResult:
152152
if self.path is None:
153153
return UpdateResult(
154154
self.model, UpdateStatus.ERROR, "Administrator rights are required for updating"

nitrokeyapp/device_manager.py

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import logging
2-
from typing import Iterator, List
2+
from collections.abc import Iterator
33

44
from nitrokeyapp.device_data import DeviceData
55

@@ -19,18 +19,9 @@ def match(lhs: DeviceData, rhs: DeviceData) -> bool:
1919
return False
2020

2121

22-
def test(devices: List[DeviceData]) -> bool:
23-
for dev in devices:
24-
if dev.is_bootloader:
25-
continue
26-
if dev.uuid is not None:
27-
continue
28-
return True
29-
30-
3122
class DeviceManager:
3223
def __init__(self) -> None:
33-
self._devices: List[DeviceData] = []
24+
self._devices: list[DeviceData] = []
3425

3526
def __iter__(self) -> Iterator[DeviceData]:
3627
for item in self._devices:
@@ -42,10 +33,9 @@ def __len__(self) -> int:
4233
def clear(self) -> None:
4334
self._devices = []
4435

45-
def add(self) -> List[DeviceData]:
36+
def add(self) -> list[DeviceData]:
4637
try:
4738
all_devs = DeviceData.list()
48-
test(all_devs)
4939
except Exception as e:
5040
logger.error(f"failed listing nk3 devices: {e}")
5141
return []
@@ -88,10 +78,9 @@ def add(self) -> List[DeviceData]:
8878

8979
return new_devices
9080

91-
def remove(self) -> List[DeviceData]:
81+
def remove(self) -> list[DeviceData]:
9282
try:
9383
all_devs = DeviceData.list()
94-
test(all_devs)
9584
except Exception as e:
9685
logger.error(f"failed listing nk3 devices: {e}")
9786
return []
@@ -102,7 +91,7 @@ def remove(self) -> List[DeviceData]:
10291
if dev.updating:
10392
continue
10493

105-
res = list(filter(lambda x: match(x, dev), all_devs))
94+
res = [x for x in all_devs if match(x, dev)]
10695
if len(res) == 0:
10796
self._devices.remove(dev)
10897
out.append(dev)

0 commit comments

Comments
 (0)