Skip to content

Commit

Permalink
chore: Drop support for Python3.7 and 3.8 due to the lack of support …
Browse files Browse the repository at this point in the history
…for TypedDict and | operator
  • Loading branch information
fgmacedo committed Dec 3, 2024
1 parent c40e7e6 commit f1edb7f
Show file tree
Hide file tree
Showing 5 changed files with 152 additions and 282 deletions.
2 changes: 2 additions & 0 deletions .github/ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ Tell us what happened, what went wrong, and what you expected to happen.
Paste the command(s) you ran and the output.
If there was a crash, please include the traceback here.
```

If you're reporting a bug, consider providing a complete example that can be used directly in the automated tests. We allways write tests to reproduce the issue in order to avoid future regressions.
6 changes: 1 addition & 5 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]

steps:
- uses: actions/checkout@v4
Expand All @@ -33,10 +33,6 @@ jobs:
cache-suffix: "python${{ matrix.python-version }}"
- name: Install the project
run: uv sync --all-extras --dev
- name: Install old pydot for 3.7 only
if: matrix.python-version == 3.7
run: |
uv pip install pydot==2.0.0
#----------------------------------------------
# run ruff
#----------------------------------------------
Expand Down
22 changes: 10 additions & 12 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,11 @@ classifiers = [
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Topic :: Home Automation",
"Topic :: Software Development :: Libraries",
]
requires-python = ">=3.7"
requires-python = ">=3.9"

[project.urls]
homepage = "https://github.com/fgmacedo/python-statemachine"
Expand All @@ -44,15 +42,15 @@ dev = [
"pytest-asyncio",
"pydot",
"django >=5.0.8; python_version >='3.10'",
"pytest-django >=4.8.0; python_version >'3.8'",
"Sphinx; python_version >'3.8'",
"sphinx-gallery; python_version >'3.8'",
"myst-parser; python_version >'3.8'",
"pillow; python_version >'3.8'",
"sphinx-autobuild; python_version >'3.8'",
"furo >=2024.5.6; python_version >'3.8'",
"sphinx-copybutton >=0.5.2; python_version >'3.8'",
"pdbr>=0.8.9; python_version >='3.8'",
"pytest-django >=4.8.0",
"Sphinx",
"sphinx-gallery",
"myst-parser",
"pillow",
"sphinx-autobuild",
"furo >=2024.5.6",
"sphinx-copybutton >=0.5.2",
"pdbr>=0.8.9",
]

[build-system]
Expand Down
48 changes: 43 additions & 5 deletions statemachine/io/__init__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,50 @@
from typing import Any
from typing import Callable
from typing import Dict
from typing import List
from typing import Mapping
from typing import TypedDict
from typing import cast

from ..factory import StateMachineMetaclass
from ..state import State
from ..statemachine import StateMachine
from ..transition_list import TransitionList

CallbacksType = str | Callable | List[str] | List[Callable]

def create_machine_class_from_definition(name: str, **definition) -> StateMachine: # noqa: C901

class TransitionDict(TypedDict, total=False):
target: str
event: str
internal: bool
validators: bool
cond: CallbacksType
unless: CallbacksType
on: CallbacksType
before: CallbacksType
after: CallbacksType


class StateDict(TypedDict, total=False):
name: str
value: Any
initial: bool
final: bool
enter: CallbacksType
exit: CallbacksType


class StateWithTransitionsDict(StateDict, total=False):
on: Dict[str, List[TransitionDict]]


StateOptions = StateDict | StateWithTransitionsDict


def create_machine_class_from_definition(
name: str, states: Mapping[str, StateOptions], **definition
) -> StateMachine: # noqa: C901
"""
Creates a StateMachine class from a dictionary definition, using the StateMachineMetaclass.
Expand All @@ -27,10 +65,10 @@ def create_machine_class_from_definition(name: str, **definition) -> StateMachin
states_instances: Dict[str, State] = {}
events_definitions: Dict[str, dict] = {}

for state_id, state_kwargs in definition.pop("states").items():
on_events = state_kwargs.pop("on", {})
if on_events:
events_definitions[state_id] = on_events
for state_id, state_kwargs in states.items():
transition_definitions = cast(StateWithTransitionsDict, state_kwargs).pop("on", {})
if transition_definitions:
events_definitions[state_id] = transition_definitions

states_instances[state_id] = State(**state_kwargs)

Expand Down
Loading

0 comments on commit f1edb7f

Please sign in to comment.