Skip to content

Commit 8bb0cdf

Browse files
authored
Merge pull request #528 from ianmcorvidae/protobufs-mypy
Protobuf type interfaces for type-checking & undoing protobufs hack
2 parents 218e9b9 + 7a1b4b0 commit 8bb0cdf

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+9458
-299
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ jobs:
3434
which meshtastic
3535
meshtastic --version
3636
- name: Run pylint
37-
run: pylint meshtastic examples/ --ignore-patterns ".*_pb2.py$"
37+
run: pylint meshtastic examples/ --ignore-patterns ".*_pb2.pyi?$"
38+
- name: Check types with mypy
39+
run: mypy meshtastic/
3840
- name: Run tests with pytest
3941
run: pytest --cov=meshtastic
4042
- name: Generate coverage report

bin/regen-protobufs.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
#gsed -i 's/import "\//import ".\//g' ./protobufs/meshtastic/*
55
#gsed -i 's/package meshtastic;//g' ./protobufs/meshtastic/*
66

7-
./nanopb-0.4.7/generator-bin/protoc -I=protobufs --python_out ./ ./protobufs/meshtastic/*.proto
8-
./nanopb-0.4.7/generator-bin/protoc -I=protobufs --python_out ./meshtastic/ ./protobufs/nanopb.proto
7+
./nanopb-0.4.7/generator-bin/protoc -I=protobufs --python_out ./ --mypy_out ./ ./protobufs/meshtastic/*.proto
8+
./nanopb-0.4.7/generator-bin/protoc -I=protobufs --python_out ./meshtastic/ --mypy_out ./meshtastic/ ./protobufs/nanopb.proto
99

1010
# workaround for import bug in protoc https://github.com/protocolbuffers/protobuf/issues/1491#issuecomment-690618628
1111

meshtastic/__main__.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,15 @@
99
import sys
1010
import time
1111

12-
import pyqrcode
12+
import pyqrcode # type: ignore[import-untyped]
1313
import yaml
1414
from google.protobuf.json_format import MessageToDict
15-
from pubsub import pub
15+
from pubsub import pub # type: ignore[import-untyped]
1616

1717
import meshtastic.test
1818
import meshtastic.util
19-
from meshtastic import channel_pb2, config_pb2, portnums_pb2, remote_hardware
19+
from meshtastic import channel_pb2, config_pb2, portnums_pb2, remote_hardware, BROADCAST_ADDR
2020
from meshtastic.version import get_active_version
21-
from meshtastic.__init__ import BROADCAST_ADDR
2221
from meshtastic.ble_interface import BLEInterface
2322
from meshtastic.globals import Globals
2423

@@ -147,7 +146,7 @@ def setPref(config, comp_name, valStr) -> bool:
147146

148147
objDesc = config.DESCRIPTOR
149148
config_type = objDesc.fields_by_name.get(name[0])
150-
pref = False
149+
pref = None
151150
if config_type and config_type.message_type is not None:
152151
pref = config_type.message_type.fields_by_name.get(snake_name)
153152
# Others like ChannelSettings are standalone

meshtastic/admin_pb2.py

Lines changed: 11 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)