Skip to content

Commit

Permalink
DOC: better type hints, clarify pre-release notes
Browse files Browse the repository at this point in the history
  • Loading branch information
tangkong committed Oct 31, 2023
1 parent cf9fd1f commit 30d168e
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 16 deletions.
15 changes: 8 additions & 7 deletions atef/walk.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,20 @@
"""
from __future__ import annotations

from typing import Any, Generator, List, Tuple, Union
from typing import Generator, List, Tuple, Union

from atef.check import Comparison
from atef.config import (Configuration, PreparedComparison,
PreparedConfiguration, PreparedFile)
from atef.procedure import (PreparedProcedureFile, PreparedProcedureStep,
ProcedureStep)
from atef.config import (AnyPreparedConfiguration, Configuration,
PreparedComparison, PreparedConfiguration,
PreparedFile)
from atef.procedure import (AnyPreparedProcedure, PreparedProcedureFile,
PreparedProcedureStep, ProcedureStep)


def walk_config_file(
config: Union[PreparedFile, PreparedConfiguration, PreparedComparison],
level: int = 0
) -> Generator[Tuple[Any, int], None, None]:
) -> Generator[Tuple[Union[AnyPreparedConfiguration, PreparedComparison], int], None, None]:
"""
Yields each config and comparison and its depth
Performs a recursive depth-first search
Expand Down Expand Up @@ -49,7 +50,7 @@ def walk_config_file(
def walk_procedure_file(
config: Union[PreparedProcedureFile, PreparedProcedureStep, PreparedComparison],
level: int = 0
) -> Generator[Tuple[Any, int], None, None]:
) -> Generator[Tuple[Union[AnyPreparedProcedure, PreparedComparison], int], None, None]:
"""
Yields each ProcedureStep / Comparison and its depth
Performs a recursive depth-first search
Expand Down
25 changes: 17 additions & 8 deletions atef/widgets/config/result_summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import csv
import dataclasses
from typing import Any, List, Set
from typing import Any, List, Optional, Set, Union

from qtpy import QtCore, QtGui, QtWidgets
from qtpy.QtCore import Qt
Expand All @@ -23,16 +23,19 @@
class ResultInfo:
""" Normalized, and slightly processed view of configs/steps with results """
status: Severity
name: str
reason: str

# An un-prepared dataclass, to match the tree views (will not hold the result)
origin: AnyDataclass

@property
def type(self):
def type(self) -> str:
return type(self.origin).__name__

@property
def name(self) -> str:
return getattr(self.origin, 'name', '')


class ResultModel(QtCore.QAbstractTableModel):
"""
Expand All @@ -50,13 +53,21 @@ class ResultModel(QtCore.QAbstractTableModel):
'N/A': ('nothing', QtGui.QColor())
}

def __init__(self, *args, data: List[ResultInfo] = [], **kwargs) -> None:
def __init__(
self,
*args,
data: Optional[List[ResultInfo]] = None,
**kwargs
) -> None:
super().__init__(*args, **kwargs)
self.result_info = data
self.result_info = data or []
self.headers = ['Status', 'Type', 'Name', 'Reason']

@classmethod
def from_file(cls, file) -> ResultModel:
def from_file(
cls,
file: Union[PreparedFile, PreparedProcedureFile]
) -> ResultModel:
""" Build this model from a PreparedFile which contains results"""
if isinstance(file, PreparedFile):
datac = [cfg_tuple[0] for cfg_tuple in walk_config_file(file.root)]
Expand All @@ -68,7 +79,6 @@ def from_file(cls, file) -> ResultModel:
info = ResultInfo(
status=c.result.severity,
reason=c.result.reason or '',
name=origin.name or '',
origin=origin
)
data.append(info)
Expand All @@ -82,7 +92,6 @@ def from_file(cls, file) -> ResultModel:
data.append(ResultInfo(
status=s.result.severity,
reason=s.result.reason or '',
name=origin.name or '',
origin=origin
))

Expand Down
2 changes: 1 addition & 1 deletion docs/source/upcoming_release_notes/221-enh_status_out.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ API Breaks

Features
--------
- Adds results summary page accessible from run-mode
- Adds results summary page accessible from run-mode in the `atef config` GUI
- Adds icons to run-mode tree view

Bugfixes
Expand Down

0 comments on commit 30d168e

Please sign in to comment.