Skip to content

Commit 238754b

Browse files
committed
Add type annotation
1 parent 740514a commit 238754b

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

pythonosc/osc_bundle.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
from pythonosc import osc_message
44
from pythonosc.parsing import osc_types
55

6+
from typing import Any, Iterator
7+
68
_BUNDLE_PREFIX = b"#bundle\x00"
79

810

@@ -16,7 +18,7 @@ class OscBundle(object):
1618
An element can be another OscBundle or an OscMessage.
1719
"""
1820

19-
def __init__(self, dgram):
21+
def __init__(self, dgram: bytes) -> None:
2022
"""Initializes the OscBundle with the given datagram.
2123
2224
Args:
@@ -35,7 +37,9 @@ def __init__(self, dgram):
3537
# Get the contents as a list of OscBundle and OscMessage.
3638
self._contents = self._parse_contents(index)
3739

38-
def _parse_contents(self, index):
40+
# Return type is actually List[OscBundle], but that would require import annotations from __future__, which is
41+
# python 3.7+ only.
42+
def _parse_contents(self, index: int) -> Any:
3943
contents = []
4044

4145
try:
@@ -64,34 +68,34 @@ def _parse_contents(self, index):
6468
return contents
6569

6670
@staticmethod
67-
def dgram_is_bundle(dgram):
71+
def dgram_is_bundle(dgram: bytes) -> bool:
6872
"""Returns whether this datagram starts like an OSC bundle."""
6973
return dgram.startswith(_BUNDLE_PREFIX)
7074

7175
@property
72-
def timestamp(self):
76+
def timestamp(self) -> int:
7377
"""Returns the timestamp associated with this bundle."""
7478
return self._timestamp
7579

7680
@property
77-
def num_contents(self):
81+
def num_contents(self) -> int:
7882
"""Shortcut for len(*bundle) returning the number of elements."""
7983
return len(self._contents)
8084

8185
@property
82-
def size(self):
86+
def size(self) -> int:
8387
"""Returns the length of the datagram for this bundle."""
8488
return len(self._dgram)
8589

8690
@property
87-
def dgram(self):
91+
def dgram(self) -> bytes:
8892
"""Returns the datagram from which this bundle was built."""
8993
return self._dgram
9094

91-
def content(self, index):
95+
def content(self, index) -> Any:
9296
"""Returns the bundle's content 0-indexed."""
9397
return self._contents[index]
9498

95-
def __iter__(self):
99+
def __iter__(self) -> Iterator[Any]:
96100
"""Returns an iterator over the bundle's content."""
97101
return iter(self._contents)

0 commit comments

Comments
 (0)