Skip to content

Feature/mypy precommit #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions .github/workflows/code_quality_checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,12 @@ jobs:

steps:
- uses: actions/checkout@v3
- uses: pre-commit/[email protected]

- name: setup environment
run: |
./dev-setup.sh
- name: run pre-commit hooks
run: |
pre-commit run --all-files --show-diff-on-failure --color=always
- name: Print message on failure
if: failure()
run: |
Expand Down
6 changes: 6 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,9 @@ repos:
rev: 25.1.0
hooks:
- id: black
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.15.0
hooks:
- id: mypy
args: [--install-types, --non-interactive, --explicit-package-bases, --allow-redefinition]
language: system
6 changes: 3 additions & 3 deletions nodescraper/interfaces/dataanalyzertask.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,19 +119,19 @@ def __init_subclass__(cls, **kwargs: dict[str, Any]) -> None:
raise TypeError(f"No data model set for {cls.__name__}")

if hasattr(cls, "analyze_data"):
cls.analyze_data = analyze_decorator(cls.analyze_data)
setattr(cls, "analyze_data", analyze_decorator(cls.analyze_data))

@abc.abstractmethod
def analyze_data(
self,
data: TDataModel,
args: Optional[TAnalyzeArg | dict],
args: Optional[TAnalyzeArg],
) -> TaskResult:
"""Analyze the provided data and return a TaskResult

Args:
data (TDataModel): data to analyze
args (Optional[TAnalyzeArg | dict]): Optional arguments for analysis, can be a model or dict
args (Optional[TAnalyzeArg]): Optional arguments for analysis. Dicts will be handled in the decorator"

Returns:
TaskResult: Task result containing the analysis outcome
Expand Down
2 changes: 1 addition & 1 deletion nodescraper/interfaces/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def max_event_priority_level(self, input_value: str | EventPriority):
if isinstance(input_value, str):
value: EventPriority = getattr(EventPriority, input_value)
elif isinstance(input_value, EventPriority):
value: EventPriority = input_value
value: EventPriority = input_value # type:ignore
else:
raise ValueError(f"Invalid type for max_event_priority_level: {type(input_value)}")

Expand Down
5 changes: 3 additions & 2 deletions nodescraper/models/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ def validate_timestamp(cls, timestamp: datetime.datetime) -> datetime.datetime:
if timestamp.tzinfo is None or timestamp.tzinfo.utcoffset(timestamp) is None:
raise ValueError("datetime must be timezone aware")

if timestamp.utcoffset() is not None and timestamp.utcoffset().total_seconds() != 0:
utc_offset = timestamp.utcoffset()
if utc_offset is not None and utc_offset.total_seconds() != 0:
timestamp = timestamp.astimezone(datetime.timezone.utc)

return timestamp
Expand All @@ -90,7 +91,7 @@ def validate_category(cls, category: str | Enum) -> str:
if isinstance(category, Enum):
category = category.value

category = category.strip().upper()
category = str(category).strip().upper()
category = re.sub(r"[\s-]", "_", category)
return category

Expand Down
4 changes: 2 additions & 2 deletions nodescraper/plugins/inband/cmdline/analyzer_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@


class CmdlineAnalyzerArgs(BaseModel):
required_cmdline: str | list = Field(default_factory=list)
banned_cmdline: str | list = Field(default_factory=list)
required_cmdline: list = Field(default_factory=list)
banned_cmdline: list = Field(default_factory=list)

model_config = {"extra": "forbid"}

Expand Down
18 changes: 13 additions & 5 deletions nodescraper/resultcollators/tablesummary.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def collate_results(
connection_results (list[TaskResult]): list of connection results to collate
"""

def gen_str_table(headers: list[str], rows: list[str]):
def gen_str_table(headers: list[str], rows: list[list[str | None]]):
column_widths = [len(header) for header in headers]
for row in rows:
for i, cell in enumerate(row):
Expand All @@ -59,16 +59,24 @@ def gen_row(row):
tables = ""
if connection_results:
rows = []
for result in connection_results:
rows.append([result.task, result.status.name, result.message])
for connection_result in connection_results:
rows.append(
[
connection_result.task,
connection_result.status.name,
connection_result.message,
]
)

table = gen_str_table(["Connection", "Status", "Message"], rows)
tables += f"\n\n{table}"

if plugin_results:
rows = []
for result in plugin_results:
Copy link
Collaborator

@alexandraBara alexandraBara Jun 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure this rename was needed

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mypy doesn't like re-use of variable names, I can ignore it if needed

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the change is fine in that case, I would maybe suggest just also updating the previous loop as well to be connection_result instead of just result for consistency.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated previous loop to connection_result as well for consistency

rows.append([result.source, result.status.name, result.message])
for plugin_result in plugin_results:
rows.append(
[plugin_result.source, plugin_result.status.name, plugin_result.message]
)

table = gen_str_table(["Plugin", "Status", "Message"], rows)
tables += f"\n\n{table}"
Expand Down
5 changes: 3 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ dev = [
"ruff",
"pre-commit",
"pytest",
"pytest-cov"
"pytest-cov",
"mypy"
]

[project.urls]
Expand Down Expand Up @@ -58,4 +59,4 @@ profile = "black"

[tool.ruff.lint]
select = ["F", "B", "T20", "N", "W", "I", "E"]
ignore = ["E501", "N806"]
ignore = ["E501", "N806", "B010"]
Loading