Skip to content

Commit

Permalink
Add pylint checks
Browse files Browse the repository at this point in the history
  • Loading branch information
christiansandberg committed Oct 27, 2024
1 parent 17cf92d commit 4ae194f
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 24 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ jobs:
run: flake8 onedm
- name: Lint with mypy
run: mypy onedm
- name: Lint with pylint
run: pylint onedm
- name: Check formatting
run: black --check onedm
- name: Test with pytest
Expand Down
34 changes: 17 additions & 17 deletions onedm/sdf/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ def get_pydantic_schema(self) -> core_schema.CoreSchema:
schema = core_schema.nullable_schema(schema)
return schema

def validate_input(self, input: Any) -> Any:
def validate_input(self, value: Any) -> Any:
"""Validate and coerce a value."""
return SchemaValidator(self.get_pydantic_schema()).validate_python(input)
return SchemaValidator(self.get_pydantic_schema()).validate_python(value)


class NumberData(DataQualities):
Expand All @@ -77,8 +77,8 @@ class NumberData(DataQualities):
default: float | None = None

@field_serializer("type")
def always_include_type(self, type: str, _):
return type
def always_include_type(self, type_: str, _):
return type_

def _get_base_schema(self) -> core_schema.CoreSchema:
if self.sdf_type == "unix-time":
Expand Down Expand Up @@ -128,8 +128,8 @@ class IntegerData(DataQualities):
_enum = None

@field_serializer("type")
def always_include_type(self, type: str, _):
return type
def always_include_type(self, type_: str, _):
return type_

def _get_base_schema(self) -> core_schema.IntSchema:
return core_schema.int_schema(
Expand Down Expand Up @@ -158,12 +158,12 @@ def to_enum(self) -> EnumMeta | None:
)
return self._enum

def validate_input(self, input: Any) -> IntEnum | int:
value = super().validate_input(input)
def validate_input(self, value: Any) -> IntEnum | int:
value = super().validate_input(value)
# Convert to enum.IntEnum if possible
if enum_cls := self.to_enum():
try:
value = enum_cls(value)
return enum_cls(value)
except ValueError:
# Value is valid but not a specific enum value
pass
Expand All @@ -179,8 +179,8 @@ class BooleanData(DataQualities):
)

@field_serializer("type")
def always_include_type(self, type: str, _):
return type
def always_include_type(self, type_: str, _):
return type_

def _get_base_schema(self) -> core_schema.BoolSchema:
return core_schema.bool_schema()
Expand All @@ -201,8 +201,8 @@ class StringData(DataQualities):
default: str | None = None

@field_serializer("type")
def always_include_type(self, type: str, _):
return type
def always_include_type(self, type_: str, _):
return type_

def _get_base_schema(self) -> core_schema.CoreSchema:
if self.enum is not None:
Expand Down Expand Up @@ -238,8 +238,8 @@ class ArrayData(DataQualities):
default: list | None = None

@field_serializer("type")
def always_include_type(self, type: str, _):
return type
def always_include_type(self, type_: str, _):
return type_

def _get_base_schema(self) -> core_schema.ListSchema | core_schema.SetSchema:
if self.unique_items:
Expand All @@ -263,8 +263,8 @@ class ObjectData(DataQualities):
default: dict[str, Any] | None = None

@field_serializer("type")
def always_include_type(self, type: str, _):
return type
def always_include_type(self, type_: str, _):
return type_

def _get_base_schema(self) -> core_schema.CoreSchema:
if self.properties is None:
Expand Down
2 changes: 1 addition & 1 deletion onedm/sdf/definitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
)


class PropertyBase:
class PropertyBase: # pylint: disable=too-few-public-methods
observable: bool = True
readable: bool = True
writable: bool = True
Expand Down
12 changes: 7 additions & 5 deletions onedm/sdf/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class Document(BaseModel):
extra="allow", alias_generator=to_camel, populate_by_name=True
)

info: Information = Field(default_factory=lambda: Information())
info: Information = Field(default_factory=Information)
namespace: dict[str, str] = Field(
default_factory=dict,
description=(
Expand Down Expand Up @@ -113,9 +113,11 @@ def populate_sdf_data(self, data: dict, nxt):
"""
data = data.copy()

def update_from_parent(parent):
for property in parent.properties.values():
data.update(property.definitions)
def update_from_parent(
parent: Document | definitions.Object | definitions.Thing,
):
for prop in parent.properties.values():
data.update(prop.definitions)
for action in parent.actions.values():
if action.input_data:
data.update(action.input_data.definitions)
Expand All @@ -132,7 +134,7 @@ def update_from_parent(parent):
update_from_parent(obj)

update_from_parent(self)
for thing in self.things.values():
for thing in self.things.values(): # pylint: disable=no-member
update_from_parent(thing)

return nxt(data)
Expand Down
2 changes: 1 addition & 1 deletion onedm/sdf/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def __init__(self) -> None:

def load_file(self, path):
self.url = str(path)
with open(path, "r") as fp:
with open(path, "r", encoding="utf-8") as fp:
self.load_from_fp(fp)

def load_from_fp(self, fp: io.TextIOBase):
Expand Down
20 changes: 20 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,23 @@ Issues = "https://github.com/christiansandberg/onedm/issues"
[build-system]
requires = ["setuptools>=64", "setuptools_scm>=8"]
build-backend = "setuptools.build_meta"

[tool.isort]
profile = "black"

[tool.pylint."messages control"]
disable = [
"missing-module-docstring",
"missing-class-docstring",
"missing-function-docstring",
"too-many-instance-attributes",
"too-many-return-statements",
"duplicate-code",
"fixme",
]

[tool.pylint.format]
max-line-length = 88

[tool.mypy]
plugins = "pydantic.mypy"
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pytest
flake8
mypy
pylint
black

0 comments on commit 4ae194f

Please sign in to comment.