Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions docs/releases/3.1.0.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# StateChart 3.1.0

*Not released yet*

## What's new in 3.1.0

### Bugfixes in 3.1.0

- Fixes silent misuse of `Event()` with multiple positional arguments. Passing more than one
transition to `Event()` (e.g., `Event(t1, t2)`) now raises {ref}`InvalidDefinition` with a
clear message suggesting the `|` operator. Previously, the second argument was silently
interpreted as the event `id`, leaving the extra transitions eventless (auto-firing).
[#588](https://github.com/fgmacedo/python-statemachine/pull/588).

## Misc in 3.1.0
1 change: 1 addition & 0 deletions docs/releases/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Requires Python 3.9+.
```{toctree}
:maxdepth: 2

3.1.0
3.0.0

```
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "python-statemachine"
version = "3.0.0"
version = "3.1.0"
description = "Python Finite State Machines made easy."
authors = [{ name = "Fernando Macedo", email = "[email protected]" }]
maintainers = [{ name = "Fernando Macedo", email = "[email protected]" }]
Expand Down
2 changes: 1 addition & 1 deletion statemachine/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

__author__ = """Fernando Macedo"""
__email__ = "[email protected]"
__version__ = "3.0.0"
__version__ = "3.1.0"

__all__ = [
"StateChart",
Expand Down
9 changes: 9 additions & 0 deletions statemachine/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,15 @@ def __new__(
id = transitions
transitions = None

if id is not None and not isinstance(id, str):
raise InvalidDefinition(
_(
"Event() received a non-string 'id' ({cls_name}). "
"To combine multiple transitions under one event, "
"use the | operator: t1 | t2."
).format(cls_name=type(id).__name__)
)

_has_real_id = id is not None
id = str(id) if _has_real_id else f"__event__{uuid4().hex}"

Expand Down
15 changes: 15 additions & 0 deletions tests/test_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,3 +330,18 @@ def test_events_match_none_with_empty():

events = Events()
assert events.match(None) is True


def test_event_raises_on_non_string_id():
"""Event() should raise InvalidDefinition when id is not a string.

This catches a common mistake where users pass multiple transitions as
positional args (e.g. Event(t1, t2)) instead of combining them with |.
"""
s1 = State(initial=True)
s2 = State(final=True)
t1 = s1.to(s2)
t2 = s2.to(s1)

with pytest.raises(InvalidDefinition, match="non-string 'id'.*use the \\| operator"):
Event(t1, t2)
1,594 changes: 798 additions & 796 deletions uv.lock

Large diffs are not rendered by default.

Loading