Skip to content

Commit

Permalink
pybricksdev.cli.lwp3.repl: fix exception on PortID enum
Browse files Browse the repository at this point in the history
In Python 3.12, we are getting an exception when trying to cast an int
to a PortID since the enum doesn't have any members.

This can be fixed by adding an unused member.

Fixes: #91
  • Loading branch information
dlech committed Jul 1, 2024
1 parent 2f84b6c commit 527cf47
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Fixed
- Fixed `PortID` exception when running `lwp3 repl` command.

## [1.0.0-alpha.49] - 2024-06-30

### Changed
Expand Down
6 changes: 6 additions & 0 deletions pybricksdev/ble/lwp3/bytecodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,9 @@ class PortID(IntEnum):
All enum members are dynamic. (0 to 49 are external and 50 - 100 are internal)
"""

# not used - Python requires at least one member
_PLACEHOLDER = -1

@property
def internal(self) -> bool:
"""Tests if the port is internal."""
Expand Down Expand Up @@ -905,6 +908,9 @@ class HwNetExtFamily(IntEnum):
a single byte.
"""

# not used - Python requires at least one member
_PLACEHOLDER = -1

@property
def family(self) -> HwNetFamily:
return HwNetFamily(self & 0x0F)
Expand Down
2 changes: 2 additions & 0 deletions pybricksdev/cli/lwp3/repl.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ def get_completions(self, document: Document, complete_event):
)
if cls and issubclass(cls, Enum):
for m in cls:
if m.name.startswith("_"):
continue
yield Completion(m.name)
elif document.find_enclosing_bracket_left("(", ")") is not None:
# if we are inside of "(...)", list the enums and other parameter types
Expand Down

0 comments on commit 527cf47

Please sign in to comment.