Skip to content

Commit 3f3d352

Browse files
committed
Linting and type hint updates for new version
1 parent 9211d97 commit 3f3d352

20 files changed

+93
-79
lines changed

.flake8

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,21 @@ max-line-length = 119
44
# but keep line length to 88 in general
55
# - use "black" to auto-format
66

7+
# D400 and D205 are because we sometimes split the first line of the docstring
8+
# F821 is temporary, until code is complete and stuff like ObjectDisposedException is gone
79
ignore =
8-
# D400 and D205 are because we sometimes split the first line of the docstring
9-
*.py E203, W503, D100,D101,D102,D105,D106,D107, D400,D205, D415
10-
# temporary, until code is complete and stuff like ObjectDisposedException is gone:
11-
*.py F821
10+
E203,
11+
W503,
12+
D100,
13+
D101,
14+
D102,
15+
D105,
16+
D106,
17+
D107,
18+
D400,
19+
D205,
20+
D415,
21+
F821
1222

1323
# Config for flake8-docstrings
1424
docstring-convention = google

nisystemlink/clients/core/_http_configuration.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ def __init__(
5858
)
5959
self._server_uri = urllib.parse.urlunsplit(uri[:2] + ("", "", ""))
6060

61-
self._api_keys = None # type: Optional[Dict[str, str]]
62-
self._username = None # type: Optional[str]
63-
self._password = None # type: Optional[str]
61+
self._api_keys: Optional[Dict[str, str]] = None
62+
self._username: Optional[str] = None
63+
self._password: Optional[str] = None
6464
if api_key:
6565
self._api_keys = {self._SYSTEM_LINK_API_KEY_HEADER: api_key}
6666
elif username or password:
@@ -71,7 +71,7 @@ def __init__(
7171

7272
self._cert_path = cert_path
7373

74-
self._user_agent = "" # type: Optional[str]
74+
self._user_agent: Optional[str] = ""
7575

7676
self._timeout_ms = self.DEFAULT_TIMEOUT_MILLISECONDS
7777

nisystemlink/clients/core/_http_configuration_manager.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ def _read_virtual_configurations(cls) -> Dict[str, core.HttpConfiguration]:
110110
A dictionary mapping each loaded configuration ID to its corresponding
111111
:class:`HttpConfiguration`.
112112
"""
113-
configurations = {} # type: Dict[str, core.HttpConfiguration]
113+
configurations: Dict[str, core.HttpConfiguration] = {}
114114
try:
115115
configurations[cls._HTTP_JUPYTER_CONFIGURATION_ID] = (
116116
core.JupyterHttpConfiguration()
@@ -135,7 +135,7 @@ def _read_configurations(cls) -> Dict[str, core.HttpConfiguration]:
135135
ApiException: if an OS or permission error prevents reading the directory
136136
that contains HTTP configurations.
137137
"""
138-
configurations = {} # type: Dict[str, core.HttpConfiguration]
138+
configurations: Dict[str, core.HttpConfiguration] = {}
139139
path = cls._http_configurations_directory()
140140
if not path.exists():
141141
return configurations
@@ -162,14 +162,12 @@ def _read_configurations(cls) -> Dict[str, core.HttpConfiguration]:
162162
if not config_file.uri:
163163
continue
164164

165-
cert_path = None # type: Optional[pathlib.Path]
165+
cert_path: Optional[pathlib.Path] = None
166166
if config_file.cert_path:
167-
cert_path = typing.cast(
168-
pathlib.Path,
169-
PathConstants.application_data_directory
170-
/ "Certificates"
171-
/ config_file.cert_path,
167+
app_data_dir = typing.cast(
168+
pathlib.Path, PathConstants.application_data_directory
172169
)
170+
cert_path = app_data_dir / "Certificates" / config_file.cert_path
173171
if not cert_path.exists():
174172
cert_path = None
175173
configurations[config_file.id] = core.HttpConfiguration(
@@ -226,7 +224,10 @@ def _http_configurations_directory(cls) -> pathlib.Path:
226224
Returns:
227225
pathlib.Path: The path of the HTTP Configurations directory.
228226
"""
229-
return PathConstants.application_data_directory / "HttpConfigurations"
227+
app_data_dir = typing.cast(
228+
pathlib.Path, PathConstants.application_data_directory
229+
)
230+
return app_data_dir / "HttpConfigurations"
230231

231232
@classmethod
232233
def _salt_grains_path(cls) -> pathlib.Path:
@@ -235,7 +236,8 @@ def _salt_grains_path(cls) -> pathlib.Path:
235236
Returns:
236237
pathlib.Path: The path of SALT grains config file
237238
"""
238-
return PathConstants.salt_data_directory / "conf" / "grains"
239+
salt_data_dir = typing.cast(pathlib.Path, PathConstants.salt_data_directory)
240+
return salt_data_dir / "conf" / "grains"
239241

240242
@classmethod
241243
def _read_system_workspace(cls) -> Optional[str]:

nisystemlink/clients/core/_internal/_path_constants.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import os
66
import pathlib
77
import typing
8-
from typing import Optional
98

109
from nisystemlink.clients.core._internal._classproperty_support import (
1110
ClasspropertySupport,
@@ -21,9 +20,9 @@ class PathConstants(metaclass=ClasspropertySupport):
2120

2221
PRODUCT_NAME = "Skyline"
2322

24-
_application_data_directory = None # type: Optional[pathlib.Path]
23+
_application_data_directory: typing.Optional[pathlib.Path] = None
2524

26-
_salt_data_directory = None # type: Optional[pathlib.Path]
25+
_salt_data_directory: typing.Optional[pathlib.Path] = None
2726

2827
def __init_subclass__(cls) -> None:
2928
raise TypeError("type 'PathConstants' is not an acceptable base type")

nisystemlink/clients/tag/_async_tag_query_result_collection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def __init__(
2222
skip: The skip used for the first page of results.
2323
"""
2424
self._total_count = total_count
25-
self._current_page = None # type: Optional[List[tbase.TagData]]
25+
self._current_page: Optional[List[tbase.TagData]] = None
2626
if first_page:
2727
if skip >= total_count:
2828
raise core.ApiException(

nisystemlink/clients/tag/_buffered_tag_writer.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66
import datetime
77
import sys
88
import threading
9+
import typing # noqa: F401
910
from types import TracebackType
10-
from typing import Any, Callable, Optional, Type
11+
from typing import Any, Optional, Type
1112

1213
from nisystemlink.clients import core, tag as tbase
1314
from nisystemlink.clients.tag._core._itime_stamper import ITimeStamper
@@ -45,9 +46,9 @@ def __init__(
4546

4647
self._closed = False
4748
self._num_buffered = 0
48-
self._send_error = None # type: Optional[core.ApiException]
49+
self._send_error: Optional[core.ApiException] = None
4950
self._timer_generation = 0
50-
self._timer_handler = None # type: Optional[Callable[[], None]]
51+
self._timer_handler: typing.Optional[typing.Callable[[], None]] = None
5152

5253
@abc.abstractmethod
5354
def _buffer_value(self, path: str, value: Any) -> None:

nisystemlink/clients/tag/_core/_manual_reset_timer.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ def __init_subclass__(cls) -> None:
3838
# Under certain circumstances, mypy complains about the event not having a type hint
3939
# unless we specify it explicitly. (But we also need to delete the attribute so that
4040
# Events.__getattr__ can do its magic.)
41-
elapsed = None # type: events._EventSlot
41+
elapsed: events._EventSlot = None # type: ignore[assignment]
4242
del elapsed
4343

44-
__null_timer_impl = None # type: Optional[ManualResetTimer]
44+
__null_timer_impl: Optional["ManualResetTimer"] = None
4545

4646
@ClasspropertySupport.classproperty
4747
def null_timer(cls) -> "ManualResetTimer":
@@ -77,7 +77,7 @@ def __init__(self, interval: datetime.timedelta) -> None:
7777
self._running = [None] # used as mutable boolean; non-empty is True
7878
self._timer_start = threading.Event()
7979
self._timer_cancel = threading.Event()
80-
self._thread = threading.Thread(
80+
self._thread: Optional[threading.Thread] = threading.Thread(
8181
target=self._run,
8282
args=[
8383
self._running,
@@ -86,7 +86,7 @@ def __init__(self, interval: datetime.timedelta) -> None:
8686
self._timer_cancel,
8787
self.elapsed,
8888
],
89-
) # type: Optional[threading.Thread]
89+
)
9090
self._thread.daemon = True
9191
self._thread.start()
9292

nisystemlink/clients/tag/_http/_http_buffered_tag_writer.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def __init__(
2828
) -> None:
2929
super().__init__(stamper, buffer_size, flush_timer)
3030
self._api = client.at_uri("/nitag/v2")
31-
self._buffer = OrderedDict() # type: OrderedDict[str, Dict[str, Any]]
31+
self._buffer: OrderedDict[str, Dict[str, Any]] = OrderedDict()
3232

3333
def _buffer_value(self, path: str, value: Dict[str, Any]) -> None:
3434
if path not in self._buffer:
@@ -50,9 +50,9 @@ def _create_item(
5050
value: str,
5151
timestamp: Optional[datetime.datetime] = None,
5252
) -> Dict[str, Any]:
53-
item = {
53+
item: Dict[str, Any] = {
5454
"value": {"value": value, "type": data_type.api_name}
55-
} # type: Dict[str, Any]
55+
}
5656
if timestamp is not None:
5757
item["timestamp"] = TimestampUtilities.datetime_to_str(timestamp)
5858
return item

nisystemlink/clients/tag/_http/_http_tag_selection.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ async def _close_internal_async(self) -> None:
163163
def _create_subscription_internal(
164164
self, update_interval: Optional[datetime.timedelta] = None
165165
) -> tbase.TagSubscription:
166-
update_timer = None # type: Optional[ManualResetTimer]
166+
update_timer: Optional[ManualResetTimer] = None
167167
if update_interval is not None:
168168
update_timer = ManualResetTimer(update_interval)
169169
paths = set(self.paths).union(self.metadata.keys())
@@ -174,7 +174,7 @@ def _create_subscription_internal(
174174
async def _create_subscription_internal_async(
175175
self, update_interval: Optional[datetime.timedelta] = None
176176
) -> tbase.TagSubscription:
177-
update_timer = None # type: Optional[ManualResetTimer]
177+
update_timer: Optional[ManualResetTimer] = None
178178
if update_interval is not None:
179179
update_timer = ManualResetTimer(update_interval)
180180
paths = set(self.paths).union(self.metadata.keys())
@@ -241,7 +241,7 @@ def _handle_read_tags_values(
241241
if response is None or any(t is None for t in response):
242242
raise tbase.TagManager.invalid_response(http_response)
243243

244-
result = [] # type: List[Optional[SerializedTagWithAggregates]]
244+
result: List[Optional[SerializedTagWithAggregates]] = []
245245
for i, t in enumerate(response):
246246
path = paths[i] if paths else t.get("path")
247247
if path is None:

nisystemlink/clients/tag/_http/_http_tag_subscription.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ def callback() -> None:
124124

125125
self._update_timer_handler = callback
126126
self._update_timer.elapsed += self._update_timer_handler
127-
self._token = None # type: Optional[str]
127+
self._token: Optional[str] = None
128128

129129
# Base class implementation is sufficient:
130130
# def __enter__(self):

0 commit comments

Comments
 (0)