Skip to content

Commit

Permalink
Address and enable flake8 type checking checks (#687)
Browse files Browse the repository at this point in the history
  • Loading branch information
agners authored May 7, 2024
1 parent 7dcf536 commit d1a3d40
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 26 deletions.
7 changes: 4 additions & 3 deletions matter_server/client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,10 @@
from __future__ import annotations

import asyncio
from collections.abc import Callable
import logging
from types import TracebackType
from typing import TYPE_CHECKING, Any, Final, Optional, cast
import uuid

from aiohttp import ClientSession
from chip.clusters import Objects as Clusters
from chip.clusters.Types import NullValue

Expand Down Expand Up @@ -50,6 +47,10 @@
)

if TYPE_CHECKING:
from collections.abc import Callable
from types import TracebackType

from aiohttp import ClientSession
from chip.clusters.Objects import ClusterCommand

SUB_WILDCARD: Final = "*"
Expand Down
6 changes: 4 additions & 2 deletions matter_server/client/models/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from dataclasses import dataclass
from enum import Enum
import logging
from typing import Any, TypeVar, cast
from typing import TYPE_CHECKING, Any, TypeVar, cast

from chip.clusters import Objects as Clusters
from chip.clusters.ClusterObjects import ALL_ATTRIBUTES, ALL_CLUSTERS
Expand All @@ -15,7 +15,6 @@
parse_attribute_path,
parse_value,
)
from matter_server.common.models import MatterNodeData

from .device_types import (
ALL_TYPES as DEVICE_TYPES,
Expand All @@ -25,6 +24,9 @@
RootNode,
)

if TYPE_CHECKING:
from matter_server.common.models import MatterNodeData

LOGGER = logging.getLogger(__name__)

# pylint: disable=invalid-name
Expand Down
8 changes: 4 additions & 4 deletions matter_server/common/helpers/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@
get_type_hints,
)

from chip.clusters.ClusterObjects import (
ClusterAttributeDescriptor,
ClusterObjectDescriptor,
)
from chip.clusters.Types import Nullable
from chip.tlv import float32, uint

if TYPE_CHECKING:
from _typeshed import DataclassInstance
from chip.clusters.ClusterObjects import (
ClusterAttributeDescriptor,
ClusterObjectDescriptor,
)

_T = TypeVar("_T", bound=DataclassInstance)

Expand Down
6 changes: 4 additions & 2 deletions matter_server/common/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@

from collections.abc import Callable
from dataclasses import dataclass, field
from datetime import datetime
from enum import Enum
from typing import Any
from typing import TYPE_CHECKING, Any

if TYPE_CHECKING:
from datetime import datetime

# Enums and constants

Expand Down
6 changes: 4 additions & 2 deletions matter_server/server/client_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from __future__ import annotations

import asyncio
from collections.abc import Callable
from concurrent import futures
from contextlib import suppress
import logging
Expand All @@ -15,7 +14,6 @@

from matter_server.common.const import VERBOSE_LOG_LEVEL
from matter_server.common.helpers.json import json_dumps, json_loads
from matter_server.common.models import EventType

from ..common.errors import InvalidArguments, InvalidCommand, MatterError
from ..common.helpers.api import parse_arguments
Expand All @@ -30,6 +28,10 @@
)

if TYPE_CHECKING:
from collections.abc import Callable

from matter_server.common.models import EventType

from ..common.helpers.api import APICommandHandler
from .server import MatterServer

Expand Down
10 changes: 5 additions & 5 deletions matter_server/server/device_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,18 @@

import asyncio
from collections import deque
from collections.abc import Callable, Iterable
from datetime import datetime
from functools import partial
import logging
from pathlib import Path
from random import randint
import time
from typing import TYPE_CHECKING, Any, TypeVar, cast

from chip.ChipDeviceCtrl import DeviceProxyWrapper
from chip.clusters import Attribute, Objects as Clusters
from chip.clusters.Attribute import ValueDecodeFailure
from chip.clusters.ClusterObjects import ALL_ATTRIBUTES, ALL_CLUSTERS, Cluster
from chip.discovery import DiscoveryType
from chip.exceptions import ChipStackError
from chip.native import PyChipError
from zeroconf import BadTypeInNameException, IPVersion, ServiceStateChange, Zeroconf
from zeroconf.asyncio import AsyncServiceBrowser, AsyncServiceInfo, AsyncZeroconf

Expand Down Expand Up @@ -57,7 +53,11 @@
from .helpers.paa_certificates import fetch_certificates

if TYPE_CHECKING:
from chip.ChipDeviceCtrl import ChipDeviceController
from collections.abc import Callable, Iterable
from pathlib import Path

from chip.ChipDeviceCtrl import ChipDeviceController, DeviceProxyWrapper
from chip.native import PyChipError

from .server import MatterServer

Expand Down
5 changes: 4 additions & 1 deletion matter_server/server/helpers/custom_web_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
from __future__ import annotations

import asyncio
from ssl import SSLContext
from typing import TYPE_CHECKING

from aiohttp import web
from yarl import URL

if TYPE_CHECKING:
from ssl import SSLContext


class MultiHostTCPSite(web.BaseSite):
"""Multiple host capable aiohttp Site.
Expand Down
4 changes: 3 additions & 1 deletion matter_server/server/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from __future__ import annotations

import asyncio
from collections.abc import Callable
from functools import partial
import ipaddress
import logging
Expand Down Expand Up @@ -36,6 +35,9 @@
from .storage import StorageController
from .vendor_info import VendorInfo

if TYPE_CHECKING:
from collections.abc import Callable

DASHBOARD_DIR = Path(__file__).parent.joinpath("../dashboard/").resolve()
DASHBOARD_DIR_EXISTS = DASHBOARD_DIR.exists()

Expand Down
5 changes: 0 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -162,16 +162,12 @@ ignore = [
"FIX002", # Just annoying, not really useful
"PLR2004", # Just annoying, not really useful
"PD011", # Just annoying, not really useful
"TCH001", # Just annoying, not really useful
"TCH003", # Just annoying, not really useful
"S101", # assert is often used to satisfy type checking
"TD002", # Just annoying, not really useful
"TD003", # Just annoying, not really useful
"TD004", # Just annoying, not really useful
"COM812", # Conflict with the Ruff formatter
"ISC001", # Conflict with the Ruff formatter
"TCH003", # TEMPORARY DISABLED
"TCH002", # TEMPORARY DISABLED
"TID252", # TEMPORARY DISABLED
"N805", # TEMPORARY DISABLED
"EXE002", # TEMPORARY DISABLED
Expand Down Expand Up @@ -216,7 +212,6 @@ ignore = [
"N801", # TEMPORARY DISABLED
"N813", # TEMPORARY DISABLED
"RUF012", # TEMPORARY DISABLED
"TCH001", # TEMPORARY DISABLED
"ANN102", # TEMPORARY DISABLED
"B007", # TEMPORARY DISABLED
"SIM102", # TEMPORARY DISABLED
Expand Down
10 changes: 9 additions & 1 deletion tests/server/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from __future__ import annotations

from collections.abc import AsyncGenerator, Generator
from typing import TYPE_CHECKING
from unittest.mock import MagicMock, patch

import pytest
Expand All @@ -11,6 +11,9 @@
from matter_server.common.models import APICommand
from matter_server.server.server import MatterServer

if TYPE_CHECKING:
from collections.abc import AsyncGenerator, Generator

pytestmark = pytest.mark.usefixtures(
"application",
"app_runner",
Expand Down Expand Up @@ -74,6 +77,11 @@ def chip_stack_fixture() -> Generator[MagicMock, None, None]:
@pytest.fixture(name="certificate_authority_manager")
def certificate_authority_manager_fixture() -> Generator[MagicMock, None, None]:
"""Return a mocked certificate authority manager."""

# Necessary for patching within tests
# pylint: disable=unused-import,import-outside-toplevel
import chip.CertificateAuthority # noqa: F401

with patch(
"matter_server.server.stack.chip.CertificateAuthority.CertificateAuthorityManager",
autospec=True,
Expand Down

0 comments on commit d1a3d40

Please sign in to comment.