Skip to content

Commit a2f8990

Browse files
committed
fix more mypy and flake8 warnings
1 parent 4f64920 commit a2f8990

6 files changed

Lines changed: 17 additions & 18 deletions

File tree

pythonosc/dispatcher.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def __init__(self, _callback: Callable, _args: Union[Any, List[Any]],
3232

3333
# needed for test module
3434
def __eq__(self, other: Any) -> bool:
35-
return (type(self) == type(other) and
35+
return (isinstance(self, type(other)) and
3636
self.callback == other.callback and
3737
self.args == other.args and
3838
self.needs_reply_address == other.needs_reply_address)
@@ -63,8 +63,8 @@ class Dispatcher(object):
6363
"""
6464

6565
def __init__(self) -> None:
66-
self._map = collections.defaultdict(list) # type: DefaultDict[str, List[Handler]]
67-
self._default_handler = None # type: Optional[Handler]
66+
self._map: DefaultDict[str, List[Handler]] = collections.defaultdict(list)
67+
self._default_handler: Optional[Handler] = None
6868

6969
def map(self, address: str, handler: Callable, *args: Union[Any, List[Any]],
7070
needs_reply_address: bool = False) -> Handler:

pythonosc/osc_bundle_builder.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def __init__(self, timestamp: int) -> None:
2525
seconds since the epoch in UTC or IMMEDIATELY.
2626
"""
2727
self._timestamp = timestamp
28-
self._contents = [] # type: List[osc_bundle.OscBundle]
28+
self._contents: List[osc_bundle.OscBundle] = []
2929

3030
def add_content(self, content: osc_bundle.OscBundle) -> None:
3131
"""Add a new content to this bundle.
@@ -45,8 +45,8 @@ def build(self) -> osc_bundle.OscBundle:
4545
try:
4646
dgram += osc_types.write_date(self._timestamp)
4747
for content in self._contents:
48-
if (type(content) == osc_message.OscMessage
49-
or type(content) == osc_bundle.OscBundle):
48+
if (isinstance(content, osc_message.OscMessage)
49+
or isinstance(content, osc_bundle.OscBundle)):
5050
size = content.size
5151
dgram += osc_types.write_int(size)
5252
dgram += content.dgram

pythonosc/osc_packet.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from pythonosc import osc_bundle
1010
from pythonosc import osc_message
1111

12-
from typing import Union, List, NamedTuple
12+
from typing import List, NamedTuple
1313

1414
# A namedtuple as returned my the _timed_msg_of_bundle function.
1515
# 1) the system time at which the message should be executed

pythonosc/parsing/ntp.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@ def parse_timestamp(timestamp: int) -> Timestamp:
4141
def ntp_to_system_time(timestamp: bytes) -> float:
4242
"""Convert a NTP timestamp to system time in seconds."""
4343
try:
44-
timestamp = struct.unpack('>Q', timestamp)[0]
44+
ts = struct.unpack('>Q', timestamp)[0]
4545
except Exception as e:
4646
raise NtpError(e)
47-
return timestamp * _NTP_TIMESTAMP_TO_SECONDS - _NTP_DELTA
47+
return ts * _NTP_TIMESTAMP_TO_SECONDS - _NTP_DELTA
4848

4949

5050
def system_time_to_ntp(seconds: float) -> bytes:

pythonosc/test/test_osc_message.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,21 +66,21 @@ def test_switch_goes_off(self):
6666
msg = osc_message.OscMessage(_DGRAM_SWITCH_GOES_OFF)
6767
self.assertEqual("/SYNC", msg.address)
6868
self.assertEqual(1, len(msg.params))
69-
self.assertTrue(type(msg.params[0]) == float)
69+
self.assertTrue(isinstance(msg.params[0], float))
7070
self.assertAlmostEqual(0.0, msg.params[0])
7171

7272
def test_switch_goes_on(self):
7373
msg = osc_message.OscMessage(_DGRAM_SWITCH_GOES_ON)
7474
self.assertEqual("/SYNC", msg.address)
7575
self.assertEqual(1, len(msg.params))
76-
self.assertTrue(type(msg.params[0]) == float)
76+
self.assertTrue(isinstance(msg.params[0], float))
7777
self.assertAlmostEqual(0.5, msg.params[0])
7878

7979
def test_knob_rotates(self):
8080
msg = osc_message.OscMessage(_DGRAM_KNOB_ROTATES)
8181
self.assertEqual("/FB", msg.address)
8282
self.assertEqual(1, len(msg.params))
83-
self.assertTrue(type(msg.params[0]) == float)
83+
self.assertTrue(isinstance(msg.params[0], float))
8484

8585
def test_no_params(self):
8686
msg = osc_message.OscMessage(_DGRAM_NO_PARAMS)
@@ -126,7 +126,7 @@ def test_ignores_unknown_param(self):
126126
msg = osc_message.OscMessage(_DGRAM_UNKNOWN_PARAM_TYPE)
127127
self.assertEqual("/SYNC", msg.address)
128128
self.assertEqual(1, len(msg.params))
129-
self.assertTrue(type(msg.params[0]) == float)
129+
self.assertTrue(isinstance(msg.params[0], float))
130130
self.assertAlmostEqual(0.5, msg.params[0])
131131

132132
def test_raises_on_invalid_array(self):

pythonosc/udp_client.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,11 @@ def send_message(self, address: str, value: ArgValue) -> None:
6868
"""
6969
builder = OscMessageBuilder(address=address)
7070
if value is None:
71-
values = []
71+
pass
7272
elif not isinstance(value, Iterable) or isinstance(value, (str, bytes)):
73-
values = [value]
73+
builder.add_arg(value)
7474
else:
75-
values = value
76-
for val in values:
77-
builder.add_arg(val)
75+
for val in value:
76+
builder.add_arg(val)
7877
msg = builder.build()
7978
self.send(msg)

0 commit comments

Comments
 (0)