Skip to content

Commit ca0270d

Browse files
committed
Merge branch 'refs/heads/main' into type_annotations
# Conflicts: # adafruit_midi/midi_message.py
2 parents d4f1b04 + 36f8d5a commit ca0270d

25 files changed

+74
-56
lines changed

.pre-commit-config.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,21 @@
44

55
repos:
66
- repo: https://github.com/python/black
7-
rev: 22.3.0
7+
rev: 23.3.0
88
hooks:
99
- id: black
1010
- repo: https://github.com/fsfe/reuse-tool
11-
rev: v0.14.0
11+
rev: v1.1.2
1212
hooks:
1313
- id: reuse
1414
- repo: https://github.com/pre-commit/pre-commit-hooks
15-
rev: v4.2.0
15+
rev: v4.4.0
1616
hooks:
1717
- id: check-yaml
1818
- id: end-of-file-fixer
1919
- id: trailing-whitespace
2020
- repo: https://github.com/pycqa/pylint
21-
rev: v2.15.5
21+
rev: v2.17.4
2222
hooks:
2323
- id: pylint
2424
name: pylint (library code)

.pylintrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,4 +396,4 @@ min-public-methods=1
396396

397397
# Exceptions that will emit a warning when being caught. Defaults to
398398
# "Exception"
399-
overgeneral-exceptions=Exception
399+
overgeneral-exceptions=builtins.Exception

adafruit_midi/channel_pressure.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class ChannelPressure(MIDIMessage):
2828
:param int pressure: The pressure, 0-127.
2929
"""
3030

31+
_message_slots = ["pressure", "channel"]
3132
_STATUS = 0xD0
3233
_STATUSMASK = 0xF0
3334
LENGTH = 2

adafruit_midi/control_change.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ class ControlChange(MIDIMessage):
3030
3131
"""
3232

33+
_message_slots = ["control", "value", "channel"]
3334
_STATUS = 0xB0
3435
_STATUSMASK = 0xF0
3536
LENGTH = 3

adafruit_midi/midi_continue.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
class Continue(MIDIMessage):
2626
"""Continue MIDI message."""
2727

28+
_message_slots = []
29+
2830
_STATUS = 0xFB
2931
_STATUSMASK = 0xFF
3032
LENGTH = 1

adafruit_midi/midi_message.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,20 @@ def from_bytes(cls, msg_bytes: bytes) -> "MIDIMessage":
312312
representation of the MIDI message."""
313313
return cls()
314314

315+
def __str__(self):
316+
"""Print an instance"""
317+
cls = self.__class__
318+
if slots := getattr(cls, "_message_slots", None):
319+
# pylint: disable=not-an-iterable
320+
args = ", ".join(
321+
f"{name}={repr(getattr(self, name, None))}" for name in slots
322+
)
323+
else:
324+
args = "..."
325+
return f"{self.__class__.__name__}({args})"
326+
327+
__repr__ = __str__
328+
315329

316330
# DO NOT try to register these messages
317331
class MIDIUnknownEvent(MIDIMessage):
@@ -323,6 +337,7 @@ class MIDIUnknownEvent(MIDIMessage):
323337
or because it is not imported.
324338
"""
325339

340+
_message_slots = ["status"]
326341
LENGTH = -1
327342

328343
def __init__(self, status: int):
@@ -343,6 +358,8 @@ class MIDIBadEvent(MIDIMessage):
343358

344359
LENGTH = -1
345360

361+
_message_slots = ["msg_bytes", "exception"]
362+
346363
def __init__(self, msg_bytes: bytearray, exception: Exception):
347364
self.data = bytes(msg_bytes)
348365
self.exception_text = repr(exception)

adafruit_midi/mtc_quarter_frame.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ class MtcQuarterFrame(MIDIMessage):
4141
:param value: The quarter frame value for the specified type.
4242
"""
4343

44+
_message_slots = ["msgtype", "value"]
45+
4446
_STATUS = 0xF1
4547
_STATUSMASK = 0xFF
4648
LENGTH = 2

adafruit_midi/note_off.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ class NoteOff(MIDIMessage): # pylint: disable=duplicate-code
3131
3232
"""
3333

34+
_message_slots = ["note", "velocity", "channel"]
3435
_STATUS = 0x80
3536
_STATUSMASK = 0xF0
3637
LENGTH = 3

adafruit_midi/note_on.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ class NoteOn(MIDIMessage):
3131
to a Note Off, defaults to 127.
3232
"""
3333

34+
_message_slots = ["note", "velocity", "channel"]
35+
3436
_STATUS = 0x90
3537
_STATUSMASK = 0xF0
3638
LENGTH = 3

adafruit_midi/pitch_bend.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ class PitchBend(MIDIMessage):
2929
bend from 0 through 8192 (midpoint, no bend) to 16383.
3030
"""
3131

32+
_message_slots = ["pitch_bend", "channel"]
3233
_STATUS = 0xE0
3334
_STATUSMASK = 0xF0
3435
LENGTH = 3

0 commit comments

Comments
 (0)