Skip to content

Commit dbcc854

Browse files
committed
Formatting fixes
1 parent 58dd3a5 commit dbcc854

File tree

28 files changed

+293
-266
lines changed

28 files changed

+293
-266
lines changed

examples/morse.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99

1010
def morse_beep(tps: TPS1200P, message: str, intensity: int):
11-
def letter_beep(tps: TPS1200P, l: str, intensity: int):
11+
def letter_beep(tps: TPS1200P, letter: str, intensity: int):
1212
lookup = {
1313
"a": ".-",
1414
"b": "-...",
@@ -47,7 +47,7 @@ def letter_beep(tps: TPS1200P, l: str, intensity: int):
4747
"9": "----.",
4848
"0": "-----"
4949
}
50-
code = lookup[l]
50+
code = lookup[letter]
5151
for i, signal in enumerate(code):
5252
tps.bmm.beep_on(intensity)
5353
match signal:
@@ -58,7 +58,7 @@ def letter_beep(tps: TPS1200P, l: str, intensity: int):
5858
tps.bmm.beep_off()
5959
if i != len(code) - 1:
6060
sleep(unit)
61-
61+
6262
unit = 0.05
6363
words = message.lower().split(" ")
6464
for i, word in enumerate(words):
@@ -79,7 +79,7 @@ def cli():
7979
parser.add_argument("message", help="message to encode", type=str)
8080

8181
args = parser.parse_args()
82-
82+
8383
port = Serial(args.port)
8484
with SerialConnection(port) as conn:
8585
ts = TPS1200P(conn)

src/geocompy/__init__.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
The package provides
1313
1. Utility data types for handling instrument responses
1414
2. Instrument software specific low level commands
15-
3. Instrument-agnostic higher level functions for instrument types
15+
3. Instrument-agnostic higher level functions for instrument types
1616
1717
Documentation
1818
-------------
@@ -58,8 +58,8 @@
5858

5959
try:
6060
from ._version import __version__
61-
except:
62-
__version__ = "0.0.0" # Placeholder value for source installs
61+
except Exception:
62+
__version__ = "0.0.0" # Placeholder value for source installs
6363

6464

6565
_T = TypeVar("_T")
@@ -163,6 +163,7 @@ class GeoComProtocol:
163163
Base class for GeoCom protocol versions.
164164
165165
"""
166+
166167
def __init__(
167168
self,
168169
connection: Connection,
@@ -176,7 +177,7 @@ def __init__(
176177
(usually :class:`~communication.SerialConnection`).
177178
logger : ~logging.Logger | None, optional
178179
Logger to log all requests and responses, by default None
179-
180+
180181
"""
181182
self._conn: Connection = connection
182183
if logger is None:
@@ -217,7 +218,7 @@ def request(
217218
------
218219
NotImplementedError
219220
If the method is not implemented on the child class.
220-
221+
221222
"""
222223
raise NotImplementedError()
223224

@@ -250,13 +251,14 @@ def parse_response(
250251
------
251252
NotImplementedError
252253
If the method is not implemented on the child class.
253-
254+
254255
"""
255256
raise NotImplementedError()
256257

257258

258259
class GsiOnlineResponse(Generic[_T]):
259260
"""Container class for parsed GSI Online responses."""
261+
260262
def __init__(
261263
self,
262264
desc: str,
@@ -293,7 +295,7 @@ def __init__(
293295
executed command."""
294296
self.comment: str = comment
295297
"""Additional comment (e.g. explanation of an error)."""
296-
298+
297299
def __str__(self) -> str:
298300
success = (
299301
"success"
@@ -306,7 +308,7 @@ def __str__(self) -> str:
306308
f"value: {self.value}, "
307309
f"(cmd: '{self.cmd}', response: '{self.response}')"
308310
)
309-
311+
310312
def __bool__(self) -> bool:
311313
return self.value is not None
312314

@@ -315,6 +317,7 @@ class GsiOnlineProtocol:
315317
"""
316318
Base class for GSI Online protocol versions.
317319
"""
320+
318321
def __init__(
319322
self,
320323
connection: Connection,
@@ -334,7 +337,7 @@ def __init__(
334337
logger = Logger("/dev/null")
335338
logger.addHandler(NullHandler())
336339
self._logger: Logger = logger
337-
340+
338341
def setrequest(
339342
self,
340343
param: int,
@@ -418,7 +421,7 @@ def putrequest(
418421
If the method is not implemented on the child class.
419422
"""
420423
raise NotImplementedError()
421-
424+
422425
def getrequest(
423426
self,
424427
mode: Literal['I', 'M', 'C'],

src/geocompy/communication.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,9 @@ def receive(self) -> str:
287287
eoabytes = self.eoa.encode("ascii")
288288
answer = self._port.read_until(eoabytes)
289289
if not answer.endswith(eoabytes):
290-
raise SerialTimeoutException("serial connection timed out on 'receive'")
290+
raise SerialTimeoutException(
291+
"serial connection timed out on 'receive'"
292+
)
291293

292294
return answer.decode("ascii").removesuffix(self.eoa)
293295

src/geocompy/data.py

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ def parsestr(value: str) -> str:
6969
"""
7070
if value[0] == value[-1] == "\"":
7171
return value[1:-1]
72-
72+
7373
return value
7474

7575

@@ -95,7 +95,7 @@ def toenum(e: type[_E], value: _E | str) -> _E:
9595
Examples
9696
--------
9797
>>> from enum import Enum
98-
>>>
98+
>>>
9999
>>> class MyEnum(Enum):
100100
... ONE = 1
101101
... TWO = 2
@@ -107,13 +107,13 @@ def toenum(e: type[_E], value: _E | str) -> _E:
107107
"""
108108
if isinstance(value, str):
109109
return e[value]
110-
110+
111111
if value not in e:
112112
raise ValueError(
113113
f"given member ({value}) is not a member "
114114
f"of the target enum: {e}"
115115
)
116-
116+
117117
return value
118118

119119

@@ -126,18 +126,18 @@ def enumparser(e: type[_E]) -> Callable[[str], _E]:
126126
----------
127127
e: Enum
128128
Target enum type.
129-
129+
130130
Returns
131131
-------
132132
Callable
133133
Parser function, that takes a string as input, and returns an
134134
enum member.
135-
135+
136136
Examples
137137
--------
138138
139139
>>> from enum import Enum
140-
>>>
140+
>>>
141141
>>> class MyEnum(Enum):
142142
... ONE = 1
143143
... TWO = 2
@@ -149,7 +149,7 @@ def enumparser(e: type[_E]) -> Callable[[str], _E]:
149149
"""
150150
def parseenum(value: str) -> _E:
151151
return e(int(value))
152-
152+
153153
return parseenum
154154

155155

@@ -426,11 +426,11 @@ def __str__(self) -> str:
426426

427427
def __repr__(self) -> str:
428428
return f"{type(self).__name__:s}({self.asunit(AngleUnit.DMS):s})"
429-
429+
430430
def __eq__(self, other: object) -> bool:
431431
if type(other) is not Angle:
432432
return False
433-
433+
434434
return math.isclose(self._value, other._value)
435435

436436
def __pos__(self) -> Angle:
@@ -621,7 +621,7 @@ def parse(cls, string: str) -> Byte:
621621
class Vector:
622622
"""
623623
Utility type to represent a position with 3D cartesian coordinates.
624-
624+
625625
Supported arithmetic operations:
626626
- \\+ `Vector`
627627
- \\- `Vector`
@@ -679,7 +679,7 @@ def __getitem__(self, idx: int) -> float:
679679

680680
coords = (self.x, self.y, self.z)
681681
return coords[idx]
682-
682+
683683
def __eq__(self, other) -> bool:
684684
if type(other) is not type(self):
685685
return False
@@ -689,77 +689,77 @@ def __eq__(self, other) -> bool:
689689
and math.isclose(self.y, other.y)
690690
and math.isclose(self.z, other.z)
691691
)
692-
692+
693693
def __pos__(self) -> Self:
694694
return type(self)(
695695
self.x,
696696
self.y,
697697
self.z
698698
)
699-
699+
700700
def __neg__(self) -> Self:
701701
return type(self)(
702702
-self.x,
703703
-self.y,
704704
-self.z
705705
)
706-
706+
707707
def __add__(self, other: Self) -> Self:
708708
if type(other) is not type(self):
709709
raise TypeError(
710710
f"unsupported operand type(s) for +: "
711711
f"'{type(self).__name__}' and "
712712
f"'{type(other).__name__}'"
713713
)
714-
714+
715715
return type(self)(
716716
self.x + other.x,
717717
self.y + other.y,
718718
self.z + other.z
719719
)
720-
720+
721721
def __sub__(self, other: Self) -> Self:
722722
if type(other) is not type(self):
723723
raise TypeError(
724724
f"unsupported operand type(s) for -: "
725725
f"'{type(self).__name__}' and "
726726
f"'{type(other).__name__}'"
727727
)
728-
728+
729729
return type(self)(
730730
self.x - other.x,
731731
self.y - other.y,
732732
self.z - other.z
733733
)
734-
734+
735735
def __mul__(self, other: int | float) -> Self:
736736
if type(other) not in (int, float):
737737
raise TypeError(
738738
f"unsupported operand type(s) for *: "
739739
f"'{type(self).__name__}' and "
740740
f"'{type(other).__name__}'"
741741
)
742-
742+
743743
return type(self)(
744744
self.x * other,
745745
self.y * other,
746746
self.z * other
747747
)
748-
748+
749749
def __truediv__(self, other: int | float) -> Self:
750750
if type(other) not in (int, float):
751751
raise TypeError(
752752
f"unsupported operand type(s) for /: "
753753
f"'{type(self).__name__}' and "
754754
f"'{type(other).__name__}'"
755755
)
756-
756+
757757
return type(self)(
758758
self.x / other,
759759
self.y / other,
760760
self.z / other
761761
)
762-
762+
763763
def length(self) -> float:
764764
"""
765765
Calculates the length of the vector.
@@ -778,7 +778,7 @@ def length(self) -> float:
778778
)
779779
)
780780
)
781-
781+
782782
def normalized(self) -> Self:
783783
"""
784784
Returns a copy of the vector, normalized to unit length.
@@ -788,17 +788,17 @@ def normalized(self) -> Self:
788788
Self
789789
Normalized vector.
790790
"""
791-
l = self.length()
792-
if l == 0:
791+
length = self.length()
792+
if length == 0:
793793
return +self
794-
795-
return self / l
794+
795+
return self / length
796796

797797

798798
class Coordinate(Vector):
799799
"""
800800
Utility type to represent a position with 3D cartesian coordinates.
801-
801+
802802
Supported arithmetic operations:
803803
- \\+ `Coordinate`
804804
- \\- `Coordinate`

0 commit comments

Comments
 (0)