Skip to content

Commit dc51571

Browse files
ci(pre-commit.ci): 🎨 Auto format from pre-commit.com hooks
1 parent 47ca33d commit dc51571

9 files changed

Lines changed: 21 additions & 19 deletions

File tree

micropy/app/stubs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ def _get_desc(name: str, cfg: dict):
179179
pyb.run_script(create_stubs, DevicePath(dev_path))
180180
except Exception as e:
181181
# TODO: Handle more usage cases
182-
log.error(f"Failed to execute script: {str(e)}", exception=e)
182+
log.error(f"Failed to execute script: {e!s}", exception=e)
183183
raise
184184
log.success("Done!")
185185
log.info("Copying stubs...")

micropy/exceptions.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
"""Micropy Exceptions."""
22
from __future__ import annotations
33

4+
from typing import Optional
5+
46

57
class MicropyException(Exception):
68
"""Generic MicroPy Exception."""
@@ -21,7 +23,7 @@ class StubValidationError(StubError):
2123
"""Raised when a stub fails validation."""
2224

2325
def __init__(self, path, errors, *args, **kwargs):
24-
msg = f"Stub at[{str(path)}] encountered" f" the following validation errors: {str(errors)}"
26+
msg = f"Stub at[{path!s}] encountered" f" the following validation errors: {errors!s}"
2527
super().__init__(msg, *args, **kwargs)
2628

2729
def __str__(self):
@@ -52,7 +54,7 @@ class RequirementNotFound(RequirementException):
5254
class PyDeviceError(MicropyException):
5355
"""Generic PyDevice exception."""
5456

55-
def __init__(self, message: str = None):
57+
def __init__(self, message: Optional[str] = None):
5658
super().__init__(message)
5759
self.message = message
5860

micropy/logger.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ def exception(self, error, **kwargs):
254254
255255
"""
256256
name = type(error).__name__
257-
msg = f"{name}: {str(error)}"
257+
msg = f"{name}: {error!s}"
258258
return self.echo(msg, log="exception", title_color="red", fg="red", accent="red", **kwargs)
259259

260260
def success(self, msg, **kwargs):

micropy/project/modules/stubs.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import sys
44
from pathlib import Path
5-
from typing import Any, List, Sequence, Union
5+
from typing import Any, List, Optional, Sequence, Union
66

77
from boltons import setutils
88
from micropy.project.modules import ProjectModule
@@ -22,7 +22,7 @@ class StubsModule(ProjectModule):
2222
PRIORITY: int = 9
2323

2424
def __init__(
25-
self, stub_manager: StubManager, stubs: Sequence[DeviceStub] = None, **kwargs: Any
25+
self, stub_manager: StubManager, stubs: Optional[Sequence[DeviceStub]] = None, **kwargs: Any
2626
):
2727
super().__init__(**kwargs)
2828
self.stub_manager: StubManager = stub_manager

micropy/project/template.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ def render_to(self, name, parent_dir, *args, **kwargs):
296296
297297
"""
298298
template = self.get(name, **kwargs)
299-
self.log.debug(f"Loaded: {str(template)}")
299+
self.log.debug(f"Loaded: {template!s}")
300300
if self.run_checks:
301301
self.log.debug(f"Verifying {template} requirements...")
302302
template.run_checks()
@@ -305,7 +305,7 @@ def render_to(self, name, parent_dir, *args, **kwargs):
305305
self.log.debug(f"Create: {out_dir}")
306306
parent_dir.mkdir(exist_ok=True)
307307
out_dir.parent.mkdir(exist_ok=True, parents=True)
308-
self.log.debug(f"Rendered: {name} to {str(out_dir)}")
308+
self.log.debug(f"Rendered: {name} to {out_dir!s}")
309309
self.log.info(f"$[{name.capitalize()}] File Generated!")
310310
stream = template.render_stream()
311311
return stream.dump(str(out_dir))
@@ -326,13 +326,13 @@ def update(self, name, root_dir, **kwargs):
326326
327327
"""
328328
template = self.get(name, **kwargs)
329-
self.log.debug(f"Loaded: {str(template)}")
329+
self.log.debug(f"Loaded: {template!s}")
330330
try:
331331
template.update(root_dir)
332332
except FileNotFoundError:
333333
self.log.debug("Template does not exist!")
334334
return self.render_to(name, root_dir, **kwargs)
335-
self.log.debug(f"Updated: {str(template)}")
335+
self.log.debug(f"Updated: {template!s}")
336336
return template
337337

338338
@property

micropy/pyd/abc.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
import abc
44
from io import BytesIO, StringIO
55
from pathlib import Path
6-
from typing import Any, AnyStr, Generic, NewType, Protocol, TypeVar
6+
from typing import Any, AnyStr, Generic, NewType, Optional, Protocol, TypeVar
77

88
HostPath = NewType("HostPath", str)
99
DevicePath = NewType("DevicePath", str)
1010

1111

1212
class StartHandler(Protocol):
13-
def __call__(self, *, name: str = None, size: int | None = None) -> Any:
13+
def __call__(self, *, name: Optional[str] = None, size: int | None = None) -> Any:
1414
...
1515

1616

micropy/pyd/backend_upydevice.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ def write_file(
203203
target_path = self.resolve_path(target_path)
204204
self._pydevice.cmd("import gc")
205205
self._pydevice.cmd("import ubinascii")
206-
self._pydevice.cmd(f"f = open('{str(target_path)}', 'wb')")
206+
self._pydevice.cmd(f"f = open('{target_path!s}', 'wb')")
207207

208208
content_iter = (
209209
iterutils.chunked_iter(contents, self.BUFFER_SIZE)
@@ -212,7 +212,7 @@ def write_file(
212212
)
213213

214214
content_size = len(contents)
215-
consumer.on_start(name=f"Writing {str(target_path)}", size=content_size)
215+
consumer.on_start(name=f"Writing {target_path!s}", size=content_size)
216216

217217
for chunk in content_iter:
218218
cmd = (

micropy/pyd/consumers.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from __future__ import annotations
22

33
from functools import partialmethod
4-
from typing import Any, Callable, NamedTuple, cast
4+
from typing import Any, Callable, NamedTuple, Optional, cast
55

66
from micropy.pyd.abc import (
77
EndHandler,
@@ -19,14 +19,14 @@ class ProgressStreamConsumer:
1919

2020
def __init__(
2121
self,
22-
on_description: Callable[
23-
[str, dict[str, Any] | None], tuple[str, dict[str, Any] | None]
22+
on_description: Optional[
23+
Callable[[str, dict[str, Any] | None], tuple[str, dict[str, Any] | None]]
2424
] = None,
2525
**kwargs,
2626
):
2727
self._on_description = on_description or (lambda s, cfg: (s, cfg))
2828

29-
def on_start(self, *, name: str = None, size: int | None = None):
29+
def on_start(self, *, name: Optional[str] = None, size: int | None = None):
3030
bar_format = "{l_bar}{bar}| [{n_fmt}/{total_fmt} @ {rate_fmt}]"
3131
tqdm_kwargs = {
3232
"unit_scale": True,

tests/test_stubs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ def test_manager_resolve_subresource(mock_mp_stubs, tmp_path):
191191
subresource = tmp_path / "stub_subresource"
192192
subresource.mkdir()
193193
manager = mock_mp_stubs.stubs.resolve_subresource(test_stubs, subresource)
194-
linked_stub = list(manager)[0]
194+
linked_stub = next(iter(manager))
195195
assert linked_stub.path.is_symlink()
196196
assert linked_stub in list(mock_mp_stubs.stubs)
197197

0 commit comments

Comments
 (0)