Skip to content

Commit 3e99504

Browse files
committed
import annotations from future for python3.9 union/optional types
1 parent 5f59d45 commit 3e99504

File tree

6 files changed

+29
-24
lines changed

6 files changed

+29
-24
lines changed

pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ exclude_also = [
7676
omit = ["*/__main__.py"]
7777

7878

79+
[tool.ruff]
80+
target-version = "py39"
81+
7982
[tool.ruff.lint]
8083
preview = true
8184
extend-select = [

tests/test_ui.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Vapor UI tests."""
22

3-
from typing import Optional
3+
from __future__ import annotations
4+
45
from unittest.mock import Mock, patch
56

67
import pytest
@@ -45,7 +46,7 @@ def config() -> Config:
4546
class MockCache:
4647
"""Mock Cache object with set anticheat data."""
4748

48-
def get_anticheat_data(self, app_id: str) -> Optional[AntiCheatData]:
49+
def get_anticheat_data(self, app_id: str) -> AntiCheatData | None:
4950
"""Return anticheat status denied for id 123."""
5051
if app_id == '123':
5152
return AntiCheatData('123', AntiCheatStatus.DENIED)

vapor/api_interface.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
"""Steam and ProtonDB API helper functions."""
22

3+
from __future__ import annotations
4+
35
import json
4-
from typing import Optional
56

67
import aiohttp
78

@@ -68,13 +69,13 @@ async def check_game_is_native(app_id: str) -> bool:
6869
)
6970

7071

71-
async def get_anti_cheat_data() -> Optional[Cache]:
72+
async def get_anti_cheat_data() -> Cache | None:
7273
"""Get the anti-cheat data from cache.
7374
7475
If expired, this function will fetch new data and write that to cache.
7576
7677
Returns:
77-
Optional[Cache]: The cache containing anti-cheat data.
78+
Cache | None: The cache containing anti-cheat data.
7879
"""
7980
cache = Cache().load_cache()
8081
if cache.has_anticheat_cache:

vapor/cache_handler.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import json
66
from datetime import datetime
77
from pathlib import Path
8-
from typing import Optional
98

109
from typing_extensions import Self, override
1110

@@ -86,37 +85,37 @@ def has_anticheat_cache(self) -> bool:
8685
"""Whether or not there is anticheat cache loaded."""
8786
return bool(self._anti_cheat_data)
8887

89-
def get_game_data(self, app_id: str) -> Optional[Game]:
88+
def get_game_data(self, app_id: str) -> Game | None:
9089
"""Get game data from app ID.
9190
9291
Args:
9392
app_id (str): The game's app ID.
9493
9594
Returns:
96-
Optional[Game]: The game data if exists. If not, None.
95+
Game | None: The game data if exists. If not, None.
9796
"""
9897
data = self._games_data.get(app_id, None)
9998
if data is not None:
10099
return data[0]
101100

102101
return None
103102

104-
def get_anticheat_data(self, app_id: str) -> Optional[AntiCheatData]:
103+
def get_anticheat_data(self, app_id: str) -> AntiCheatData | None:
105104
"""Get anticheat data from app ID.
106105
107106
Args:
108107
app_id (str): The game's app ID.
109108
110109
Returns:
111-
Optional[AntiCheatData]: The game anticheat data if exists. If not, None.
110+
AntiCheatData | None: The game anticheat data if exists. If not, None.
112111
"""
113112
data = self._anti_cheat_data.get(app_id, None)
114113
if data is not None:
115114
return data
116115

117116
return None
118117

119-
def load_cache(self, prune: Optional[bool] = True) -> Self:
118+
def load_cache(self, prune: bool | None = True) -> Self:
120119
"""Load and deserialize the cache.
121120
122121
Args:
@@ -159,15 +158,15 @@ def load_cache(self, prune: Optional[bool] = True) -> Self:
159158

160159
def update_cache(
161160
self,
162-
game_list: Optional[list[Game]] = None,
163-
anti_cheat_list: Optional[list[AntiCheatData]] = None,
161+
game_list: list[Game] | None = None,
162+
anti_cheat_list: list[AntiCheatData] | None = None,
164163
) -> Self:
165164
"""Update the cache file with new game and anticheat data.
166165
167166
Args:
168-
game_list (Optional[list[Game]]): list of new game data.
167+
game_list (list[Game] | None): list of new game data.
169168
Defaults to None.
170-
anti_cheat_list (Optional[list[AntiCheatData]]): list of new
169+
anti_cheat_list (list[AntiCheatData] | None): list of new
171170
anticheat data. Defaults to None.
172171
173172
Returns:

vapor/config_handler.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
"""Vapor configuration file handling."""
22

3+
from __future__ import annotations
4+
35
from configparser import ConfigParser
46
from pathlib import Path
5-
from typing import Optional
67

78
from typing_extensions import Self
89

@@ -22,7 +23,7 @@ class Config:
2223
def __init__(self) -> None:
2324
"""Construct a new Config object."""
2425
self._config_path: Path = CONFIG_PATH
25-
self._config_data: Optional[ConfigParser] = None
26+
self._config_data: ConfigParser | None = None
2627

2728
def set_value(self, key: str, value: str) -> Self:
2829
"""Set a value in the config file.

vapor/main.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from __future__ import annotations
44

55
from pathlib import Path
6-
from typing import ClassVar, Optional, Union, cast
6+
from typing import ClassVar, cast
77
from urllib.parse import urlparse
88

99
from rich.text import Text
@@ -108,13 +108,13 @@ def on_button_pressed(self) -> None:
108108
class SteamApp(App[None]):
109109
"""Main application class."""
110110

111-
CSS_PATH: ClassVar[Optional[CSSPathType]] = 'main.tcss'
112-
TITLE: Optional[str] = 'Steam Profile Proton Compatibility Checker'
111+
CSS_PATH: ClassVar[CSSPathType | None] = 'main.tcss'
112+
TITLE: str | None = 'Steam Profile Proton Compatibility Checker'
113113
BINDINGS: ClassVar[list[BindingType]] = [
114114
Binding('ctrl+s', "push_screen('settings')", 'Settings', show=True),
115115
]
116116

117-
def __init__(self, custom_config: Optional[Config] = None) -> None:
117+
def __init__(self, custom_config: Config | None = None) -> None:
118118
"""Construct the application.
119119
120120
This reads and instantiates the config.
@@ -155,15 +155,15 @@ def compose(self) -> ComposeResult:
155155
id='user-rating',
156156
),
157157
),
158-
DataTable[Union[str, Text]](zebra_stripes=True),
158+
DataTable[str | Text](zebra_stripes=True),
159159
id='body',
160160
)
161161
yield Footer()
162162

163163
def on_mount(self) -> None:
164164
"""On mount, we initialize the table columns."""
165165
# add nothing to table so that it shows up
166-
table: DataTable[Union[str, Text]] = self.query_one(DataTable)
166+
table: DataTable[str | Text] = self.query_one(DataTable)
167167
table.add_columns('Title', 'Compatibility', 'Anti-Cheat Compatibility')
168168

169169
for _ in range(12):
@@ -190,7 +190,7 @@ async def populate_table(self) -> None:
190190
item.refresh()
191191

192192
# set the DataTable as loading
193-
table: DataTable[Union[str, Text]] = self.query_one(DataTable)
193+
table: DataTable[str | Text] = self.query_one(DataTable)
194194
table.set_loading(loading=True)
195195

196196
# get user's API key and ID

0 commit comments

Comments
 (0)