Skip to content

Commit

Permalink
[internal] Micropython Kompatibilität: Fallback für typing Modul hinz…
Browse files Browse the repository at this point in the history
…ugefügt

Micropython bietet kein typing Modul (ist in Arbeit, siehe
micropython/micropython-lib#584). Stattdessen wird ein
Mock benutzt.

CUST-234
  • Loading branch information
jkatins committed Jun 15, 2023
1 parent 0d1ba65 commit 187de80
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
7 changes: 7 additions & 0 deletions bec2format/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
import sys

if sys.implementation.name == "micropython":
from .compatibility import mock_module

mock_module("typing")

from .bec2file import (
CONFIG_SECURITY_CODE_SIZE,
Bec2File,
Expand Down
19 changes: 19 additions & 0 deletions bec2format/compatibility.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import sys


class _Mock:
def __getattr__(self, item):
return self

def __getitem__(self, item):
return self

def __or__(self, other):
return other

def __ror__(self, other):
return other


def mock_module(module_name: str) -> None:
sys.modules[module_name] = _Mock() # type: ignore

0 comments on commit 187de80

Please sign in to comment.