Skip to content

Commit

Permalink
morel inting
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelveldt committed Jun 27, 2023
1 parent eec2eb5 commit bb78873
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ relies on the networking managed by your operating system.
Make sure your you run the container on the host network. The host network
interface needs to be in the same network as the Android/iPhone device
you are using for commissioning. Matter uses link-local multicast protocols
which do not work accross different LANs or VLANs.
which do not work across different LANs or VLANs.

The host network interface needs IPv6 support enabled.

Expand Down
2 changes: 1 addition & 1 deletion matter_server/common/helpers/json.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def json_encoder_default(obj: Any) -> Any:
return b64encode(obj).decode("utf-8")
if isinstance(obj, Exception):
return str(obj)
if type(obj) == type:
if type(obj) == type: # pylint: disable=unidiomatic-typecheck
return f"{obj.__module__}.{obj.__qualname__}"

raise TypeError
Expand Down
10 changes: 6 additions & 4 deletions matter_server/common/helpers/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ def parse_utc_timestamp(datetime_string: str) -> datetime:

def parse_value(name: str, value: Any, value_type: Any, default: Any = MISSING) -> Any:
"""Try to parse a value from raw (json) data and type annotations."""
# pylint: disable=too-many-return-statements,too-many-branches

if isinstance(value_type, str):
# this shouldn't happen, but just in case
Expand Down Expand Up @@ -143,9 +144,9 @@ def parse_value(name: str, value: Any, value_type: Any, default: Any = MISSING)
# raise exception, we have no idea how to handle this value
raise TypeError(err)
# failed to parse the (sub) value but None allowed, log only
logging.getLogger(__name__).warn(err)
logging.getLogger(__name__).warning(err)
return None
elif origin is type:
if origin is type:
return get_type_hints(value, globals(), locals())
# handle Any as value type (which is basically unprocessable)
if value_type is Any:
Expand All @@ -157,6 +158,7 @@ def parse_value(name: str, value: Any, value_type: Any, default: Any = MISSING)
try:
if issubclass(value_type, Enum):
# handle enums from the SDK that have a value that does not exist in the enum (sigh)
# pylint: disable=protected-access
if value not in value_type._value2member_map_:
# we do not want to crash so we return the raw value
return value
Expand Down Expand Up @@ -207,12 +209,12 @@ def dataclass_from_dict(cls: type[_T], dict_obj: dict, strict: bool = False) ->
Including support for nested structures and common type conversions.
If strict mode enabled, any additional keys in the provided dict will result in a KeyError.
"""
# pylint: disable=consider-using-set-comprehension
if strict:
extra_keys = dict_obj.keys() - set([f.name for f in fields(cls)])
if extra_keys:
raise KeyError(
"Extra key(s) %s not allowed for %s"
% (",".join(extra_keys), (str(cls)))
f'Extra key(s) {",".join(extra_keys)} not allowed for {str(cls)}'
)
type_hints = get_type_hints(cls)
return cls(
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ test = [
matter-server = "matter_server.server.__main__:main"

[tool.codespell]
ignore-words-list = "pase,"
ignore-words-list = "pase,nd"

[tool.mypy]
python_version = "3.10"
Expand Down

0 comments on commit bb78873

Please sign in to comment.