Skip to content

Commit e3e2dda

Browse files
committed
Type these named tuples
This fixes warnings around passing their arguments as named (which was not really supported) and means we get better typing information around their values.
1 parent 373c636 commit e3e2dda

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

pythonosc/osc_packet.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,22 @@
33
It lets you access easily to OscMessage and OscBundle instances in the packet.
44
"""
55

6-
import collections
76
import time
87

98
from pythonosc.parsing import osc_types
109
from pythonosc import osc_bundle
1110
from pythonosc import osc_message
1211

13-
from typing import Union, List
12+
from typing import Union, List, NamedTuple
1413

1514
# A namedtuple as returned my the _timed_msg_of_bundle function.
1615
# 1) the system time at which the message should be executed
1716
# in seconds since the epoch.
1817
# 2) the actual message.
19-
TimedMessage = collections.namedtuple(
20-
typename='TimedMessage',
21-
field_names=('time', 'message'))
18+
TimedMessage = NamedTuple('TimedMessage', [
19+
('time', float),
20+
('message', osc_message.OscMessage),
21+
])
2222

2323

2424
def _timed_msg_of_bundle(bundle: osc_bundle.OscBundle, now: float) -> List[TimedMessage]:

pythonosc/parsing/ntp.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
import datetime
44
import struct
55
import time
6-
import collections
76

7+
from typing import NamedTuple
88

99
# 63 zero bits followed by a one in the least signifigant bit is a special
1010
# case meaning "immediately."
@@ -21,9 +21,10 @@
2121
_NTP_DELTA = (_SYSTEM_EPOCH - _NTP_EPOCH).days * 24 * 3600
2222

2323

24-
Timestamp = collections.namedtuple(
25-
typename='Timetag',
26-
field_names=('seconds', 'fraction'))
24+
Timestamp = NamedTuple('Timestamp', [
25+
('seconds', int),
26+
('fraction', int),
27+
])
2728

2829

2930
class NtpError(Exception):

0 commit comments

Comments
 (0)