GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Configure mypy to run in venv and fix resulting issues · python-kasa/python-kasa@a6fcd08

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • .github/workflows
    • ci.yml
  • .pre-commit-config.yaml
  • devtools
    • bench
      • benchmark.py
    • run-in-env.sh
  • kasa
    • aestransport.py
    • cli.py
    • httpclient.py
    • tests
      • discovery_fixtures.py
      • fakeprotocol_smart.py
      • smart/modules
        • test_firmware.py
      • test_device.py
      • test_emeter.py
      • test_httpclient.py
      • test_iotdevice.py
    • xortransport.py
  • poetry.lock
  • pyproject.toml
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎.github/workflows/ci.yml‎

Copy file name to clipboardExpand all lines: .github/workflows/ci.yml
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ jobs:
2727
python-version: ${{ matrix.python-version }}
2828
cache-pre-commit: true
2929
poetry-version: ${{ env.POETRY_VERSION }}
30+
poetry-install-options: "--all-extras"
3031
- name: "Check supported device md files are up to date"
3132
run: |
3233
poetry run pre-commit run generate-supported --all-files
Collapse file

‎.pre-commit-config.yaml‎

Copy file name to clipboardExpand all lines: .pre-commit-config.yaml
+12-11Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,6 @@ repos:
1616
args: [--fix, --exit-non-zero-on-fix]
1717
- id: ruff-format
1818

19-
- repo: https://github.com/pre-commit/mirrors-mypy
20-
rev: v1.9.0
21-
hooks:
22-
- id: mypy
23-
additional_dependencies: [types-click]
24-
exclude: |
25-
(?x)^(
26-
kasa/modulemapping\.py|
27-
)$
28-
29-
3019
- repo: https://github.com/PyCQA/doc8
3120
rev: 'v1.1.1'
3221
hooks:
@@ -35,6 +24,18 @@ repos:
3524

3625
- repo: local
3726
hooks:
27+
# Run mypy in the virtual environment so it uses the installed dependencies
28+
# for more accurate checking than using the pre-commit mypy mirror
29+
- id: mypy
30+
name: mypy
31+
entry: devtools/run-in-env.sh mypy
32+
language: script
33+
types_or: [python, pyi]
34+
require_serial: true
35+
exclude: | # exclude required because --all-files passes py and pyi
36+
(?x)^(
37+
kasa/modulemapping\.py|
38+
)$
3839
- id: generate-supported
3940
name: Generate supported devices
4041
description: This hook generates the supported device sections of README.md and SUPPORTED.md
Collapse file

‎devtools/bench/benchmark.py‎

Copy file name to clipboardExpand all lines: devtools/bench/benchmark.py
+3-2Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55

66
import orjson
77
from kasa_crypt import decrypt, encrypt
8-
from utils.data import REQUEST, WIRE_RESPONSE
9-
from utils.original import OriginalTPLinkSmartHomeProtocol
8+
9+
from .utils.data import REQUEST, WIRE_RESPONSE
10+
from .utils.original import OriginalTPLinkSmartHomeProtocol
1011

1112

1213
def original_request_response() -> None:
Collapse file

‎devtools/run-in-env.sh‎

Copy file name to clipboard
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/bash
2+
source $(poetry env info --path)/bin/activate
3+
exec "$@"
Collapse file

‎kasa/aestransport.py‎

Copy file name to clipboardExpand all lines: kasa/aestransport.py
+4-1Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,10 @@ def create_from_keypair(handshake_key: str, keypair):
371371
handshake_key_bytes: bytes = base64.b64decode(handshake_key.encode("UTF-8"))
372372
private_key_data = base64.b64decode(keypair.get_private_key().encode("UTF-8"))
373373

374-
private_key = serialization.load_der_private_key(private_key_data, None, None)
374+
private_key = cast(
375+
rsa.RSAPrivateKey,
376+
serialization.load_der_private_key(private_key_data, None, None),
377+
)
375378
key_and_iv = private_key.decrypt(
376379
handshake_key_bytes, asymmetric_padding.PKCS1v15()
377380
)
Collapse file

‎kasa/cli.py‎

Copy file name to clipboardExpand all lines: kasa/cli.py
+6-8Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,7 @@ def error(msg: str):
101101
# Block list of commands which require no update
102102
SKIP_UPDATE_COMMANDS = ["raw-command", "command"]
103103

104-
click.anyio_backend = "asyncio"
105-
106-
pass_dev = click.make_pass_decorator(Device)
104+
pass_dev = click.make_pass_decorator(Device) # type: ignore[type-abstract]
107105

108106

109107
def CatchAllExceptions(cls):
@@ -996,7 +994,7 @@ async def time_get(dev: Device):
996994

997995
@time.command(name="sync")
998996
@pass_dev
999-
async def time_sync(dev: SmartDevice):
997+
async def time_sync(dev: Device):
1000998
"""Set the device time to current time."""
1001999
if not isinstance(dev, SmartDevice):
10021000
raise NotImplementedError("setting time currently only implemented on smart")
@@ -1134,7 +1132,7 @@ async def presets(ctx):
11341132

11351133
@presets.command(name="list")
11361134
@pass_dev
1137-
def presets_list(dev: IotBulb):
1135+
def presets_list(dev: Device):
11381136
"""List presets."""
11391137
if not dev.is_bulb or not isinstance(dev, IotBulb):
11401138
error("Presets only supported on iot bulbs")
@@ -1153,7 +1151,7 @@ def presets_list(dev: IotBulb):
11531151
@click.option("--saturation", type=int)
11541152
@click.option("--temperature", type=int)
11551153
@pass_dev
1156-
async def presets_modify(dev: IotBulb, index, brightness, hue, saturation, temperature):
1154+
async def presets_modify(dev: Device, index, brightness, hue, saturation, temperature):
11571155
"""Modify a preset."""
11581156
for preset in dev.presets:
11591157
if preset.index == index:
@@ -1181,7 +1179,7 @@ async def presets_modify(dev: IotBulb, index, brightness, hue, saturation, tempe
11811179
@click.option("--type", type=click.Choice(["soft", "hard"], case_sensitive=False))
11821180
@click.option("--last", is_flag=True)
11831181
@click.option("--preset", type=int)
1184-
async def turn_on_behavior(dev: IotBulb, type, last, preset):
1182+
async def turn_on_behavior(dev: Device, type, last, preset):
11851183
"""Modify bulb turn-on behavior."""
11861184
if not dev.is_bulb or not isinstance(dev, IotBulb):
11871185
error("Presets only supported on iot bulbs")
@@ -1239,7 +1237,7 @@ async def shell(dev: Device):
12391237
logging.getLogger("asyncio").setLevel(logging.WARNING)
12401238
loop = asyncio.get_event_loop()
12411239
try:
1242-
await embed(
1240+
await embed( # type: ignore[func-returns-value]
12431241
globals=globals(),
12441242
locals=locals(),
12451243
return_asyncio_coroutine=True,
Collapse file

‎kasa/httpclient.py‎

Copy file name to clipboardExpand all lines: kasa/httpclient.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class HttpClient:
3636

3737
def __init__(self, config: DeviceConfig) -> None:
3838
self._config = config
39-
self._client_session: aiohttp.ClientSession = None
39+
self._client_session: aiohttp.ClientSession | None = None
4040
self._jar = aiohttp.CookieJar(unsafe=True, quote_cookie=False)
4141
self._last_url = URL(f"http://{self._config.host}/")
4242

Collapse file

‎kasa/tests/discovery_fixtures.py‎

Copy file name to clipboardExpand all lines: kasa/tests/discovery_fixtures.py
+3-1Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,9 @@ def discovery_data(request, mocker):
231231
return {"system": {"get_sysinfo": fixture_data["system"]["get_sysinfo"]}}
232232

233233

234-
@pytest.fixture(params=UNSUPPORTED_DEVICES.values(), ids=UNSUPPORTED_DEVICES.keys())
234+
@pytest.fixture(
235+
params=UNSUPPORTED_DEVICES.values(), ids=list(UNSUPPORTED_DEVICES.keys())
236+
)
235237
def unsupported_device_info(request, mocker):
236238
"""Return unsupported devices for cli and discovery tests."""
237239
discovery_data = request.param
Collapse file

‎kasa/tests/fakeprotocol_smart.py‎

Copy file name to clipboardExpand all lines: kasa/tests/fakeprotocol_smart.py
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ def _send_request(self, request_dict: dict):
276276
):
277277
result["sum"] = len(result[list_key])
278278
if self.warn_fixture_missing_methods:
279-
pytest.fixtures_missing_methods.setdefault(
279+
pytest.fixtures_missing_methods.setdefault( # type: ignore[attr-defined]
280280
self.fixture_name, set()
281281
).add(f"{method} (incomplete '{list_key}' list)")
282282

@@ -305,7 +305,7 @@ def _send_request(self, request_dict: dict):
305305
}
306306
# Reduce warning spam by consolidating and reporting at the end of the run
307307
if self.warn_fixture_missing_methods:
308-
pytest.fixtures_missing_methods.setdefault(
308+
pytest.fixtures_missing_methods.setdefault( # type: ignore[attr-defined]
309309
self.fixture_name, set()
310310
).add(method)
311311
return retval
Collapse file

‎kasa/tests/smart/modules/test_firmware.py‎

Copy file name to clipboardExpand all lines: kasa/tests/smart/modules/test_firmware.py
+12-1Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import asyncio
44
import logging
5+
from typing import TypedDict
56

67
import pytest
78
from pytest_mock import MockerFixture
@@ -71,7 +72,17 @@ async def test_firmware_update(
7172
assert fw
7273

7374
upgrade_time = 5
74-
extras = {"reboot_time": 5, "upgrade_time": upgrade_time, "auto_upgrade": False}
75+
76+
class Extras(TypedDict):
77+
reboot_time: int
78+
upgrade_time: int
79+
auto_upgrade: bool
80+
81+
extras: Extras = {
82+
"reboot_time": 5,
83+
"upgrade_time": upgrade_time,
84+
"auto_upgrade": False,
85+
}
7586
update_states = [
7687
# Unknown 1
7788
DownloadState(status=1, download_progress=0, **extras),

0 commit comments

Comments
0 (0)
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.