Skip to content

Commit

Permalink
🎨 Minor formatting fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
je-cook committed Sep 10, 2024
1 parent 6ab720b commit 3de496a
Show file tree
Hide file tree
Showing 17 changed files with 81 additions and 48 deletions.
7 changes: 4 additions & 3 deletions bluemira/base/parameter_frame/_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
)

if TYPE_CHECKING:
from collections.abc import Generator, Iterable
from collections.abc import Iterable, Iterator
from types import GenericAlias

from bluemira.base.parameter_frame.typed import ParameterFrameLike, ParameterFrameT
Expand Down Expand Up @@ -121,7 +121,7 @@ def _get_types(cls) -> dict[str, GenericAlias]:
frame_type_hints = get_type_hints(cls)
return {f.name: frame_type_hints[f.name] for f in fields(cls)}

def __iter__(self) -> Generator[Parameter, None, None]:
def __iter__(self) -> Iterator[Parameter]:
"""
Iterate over this frame's parameters.
Expand All @@ -130,7 +130,8 @@ def __iter__(self) -> Generator[Parameter, None, None]:
Yields
------
Each parameter in the frame
:
Each parameter in the frame
"""
for field in fields(self):
yield getattr(self, field.name)
Expand Down
7 changes: 4 additions & 3 deletions bluemira/codes/_freecadapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import math
import os
import sys
from collections.abc import Callable, Iterable
from collections.abc import Callable, Iterable, Iterator
from dataclasses import asdict, dataclass
from functools import wraps
from pathlib import Path
Expand Down Expand Up @@ -1225,7 +1225,7 @@ def _setup_document(
labels: Iterable[str] | None = None,
*,
rotate: bool = False,
) -> Iterable[Part.Feature]:
) -> Iterator[Part.Feature]:
"""
Setup FreeCAD document.
Expand All @@ -1238,7 +1238,8 @@ def _setup_document(
Yields
------
Each document object
:
Each document object
Notes
-----
Expand Down
7 changes: 4 additions & 3 deletions bluemira/codes/process/_inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
Parameter classes/structures for Process
"""

from collections.abc import Generator
from collections.abc import Iterator
from dataclasses import dataclass, fields

from bluemira.codes.process.api import _INVariable
Expand Down Expand Up @@ -703,7 +703,7 @@ class ProcessInputs:
ims: int | None = None
ifci: int | None = None

def __iter__(self) -> Generator[tuple[str, float | list | dict], None, None]:
def __iter__(self) -> Iterator[tuple[str, float | list | dict]]:
"""
Iterate over this dataclass
Expand All @@ -712,7 +712,8 @@ def __iter__(self) -> Generator[tuple[str, float | list | dict], None, None]:
Yields
------
the field name and its value
:
the field name and its value
"""
for _field in fields(self):
yield _field.name, getattr(self, _field.name)
Expand Down
7 changes: 4 additions & 3 deletions bluemira/equilibria/find.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
from bluemira.utilities.tools import floatify

if TYPE_CHECKING:
from collections.abc import Iterable
from collections.abc import Iterable, Iterator

import numpy.typing as npt

Expand Down Expand Up @@ -64,13 +64,14 @@ def __init__(self, x: float, z: float, psi: float):
self.x, self.z = x, z
self.psi = psi

def __iter__(self):
def __iter__(self) -> Iterator[float]:
"""
Imbue PsiPoint with generator-like behaviour
Yields
------
x z psi in order
:
x z psi in order
"""
yield self.x
yield self.z
Expand Down
7 changes: 5 additions & 2 deletions bluemira/equilibria/limiter.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
from bluemira.equilibria.plotting import LimiterPlotter

if TYPE_CHECKING:
from collections.abc import Iterator

import numpy.typing as npt
from matplotlib.pyplot import Axes

Expand All @@ -44,13 +46,14 @@ def __init__(self, x: npt.ArrayLike, z: npt.ArrayLike):
self.xz = cycle(np.array([x, z]).T)
self._i = 0

def __iter__(self):
def __iter__(self) -> Iterator[npt.NDArray]:
"""
Hacky phoenix iterator
Yields
------
next element of xz
:
next element of xz
"""
i = 0
while i < len(self):
Expand Down
15 changes: 10 additions & 5 deletions bluemira/gen_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ def def_param() -> dict[str, str]:
Returns
-------
the default parameter keys and types
:
The default parameter keys and types
"""
dp = deepcopy(ParamDictT.__annotations__)
del dp["name"]
Expand Down Expand Up @@ -78,7 +79,8 @@ def create_parameterframe(
Returns
-------
Python parameter frame as a string
:
Python parameter frame as a string
"""
param_cls = (
Expand Down Expand Up @@ -109,7 +111,8 @@ def parse_args():
Returns
-------
parsed argument namespace
:
Parsed argument namespace
"""
parser = argparse.ArgumentParser(
description="Generate ParameterFrame files from module or package"
Expand Down Expand Up @@ -149,7 +152,8 @@ def get_param_classes(module) -> dict:
Returns
-------
all found ParameterFrames
:
All found ParameterFrames
"""
return {
f"{m[0]}: {m[1].param_cls.__name__}": m[1].param_cls
Expand All @@ -164,7 +168,8 @@ def find_modules(path: str) -> set:
Returns
-------
all found modules
:
All found modules
"""
modules = set()
for pkg in find_packages(path):
Expand Down
3 changes: 2 additions & 1 deletion bluemira/magnetostatics/fem_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,8 @@ def pyvista_plot_show_save(filename: str = "field.svg"):
Yields
------
the pyvista plotter
:
the pyvista plotter
"""
import pyvista # noqa: PLC0415

Expand Down
3 changes: 2 additions & 1 deletion bluemira/materials/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ def patch_nmm_openmc():
Yields
------
NeutronicsMaterialMaker package
:
NeutronicsMaterialMaker package
"""
nmm = import_nmm()
if value := nmm.material.OPENMC_AVAILABLE:
Expand Down
3 changes: 2 additions & 1 deletion bluemira/structural/loads.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,8 @@ def __iter__(self) -> Iterator[Load]:
Yields
------
Each Load
:
Each Load
"""
yield from self._data

Expand Down
12 changes: 6 additions & 6 deletions bluemira/utilities/opt_variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@
from pathlib import Path
from typing import TYPE_CHECKING, TextIO, TypedDict

if TYPE_CHECKING:
import numpy.typing as npt

import numpy as np
from tabulate import tabulate
from typing_extensions import NotRequired
Expand All @@ -28,7 +25,9 @@
from bluemira.utilities.tools import json_writer

if TYPE_CHECKING:
from collections.abc import Generator
from collections.abc import Iterator

import numpy.typing as npt


class OptVarVarDictValueT(TypedDict, total=False):
Expand Down Expand Up @@ -397,7 +396,7 @@ def __new__(cls, *_args, **_kwargs):

return super().__new__(cls)

def __iter__(self) -> Generator[OptVariable, None, None]:
def __iter__(self) -> Iterator[OptVariable]:
"""
Iterate over this frame's parameters.
Expand All @@ -406,7 +405,8 @@ def __iter__(self) -> Generator[OptVariable, None, None]:
Yields
------
Each optimisation variable
:
Each optimisation variable
"""
for field_name in self.__dataclass_fields__: # type: ignore[attr-defined]
yield getattr(self, field_name)
Expand Down
3 changes: 2 additions & 1 deletion conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ def setup_sybil_namespace(namespace):
Returns
-------
expanded namespace for docstring code blocks
:
Expanded namespace for docstring code blocks
"""
namespace["MyPlasma"] = type("MyPlasma", (ComponentManager,), {})
namespace["MyTfCoils"] = type("MyTfCoils", (ComponentManager,), {})
Expand Down
21 changes: 14 additions & 7 deletions scripts/format_warning_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ def __str__(self) -> str:
Returns
-------
Formatted string
:
Formatted string
"""
return f"{self.filename}:{self.lineno}: {self.category}: {self.message}"

Expand All @@ -47,7 +48,8 @@ def parse_args(sys_args: list[str]) -> argparse.Namespace:
Returns
-------
Parsed argument namespace
:
Parsed argument namespace
"""
parser = argparse.ArgumentParser(PROG, description=__doc__)
parser.add_argument("report_file", help="path to .report.json to parse")
Expand All @@ -65,7 +67,8 @@ def load_warnings(file_path: str) -> set[Warning]:
Returns
-------
A set of warnings in from file
:
A set of warnings in from file
"""
with open(file_path) as f:
data = json.load(f)
Expand All @@ -80,7 +83,8 @@ def format_warnings_list(warnings: Iterable[Warning]) -> list[str]:
Returns
-------
Formatted list of warnings
:
Formatted list of warnings
"""
whens: dict[str, list[Warning]] = {}
for warning in warnings:
Expand All @@ -101,7 +105,8 @@ def make_collapsable(md_lines: list[str], summary: str) -> list[str]:
Returns
-------
Formatted list of strings
:
Formatted list of strings
"""
lines = [
"<details>\n",
Expand All @@ -117,7 +122,8 @@ def elements_not_in(head: Iterable[Any], ref: Iterable[Any]) -> list:
Returns
-------
elements not in ref
:
Elements not in ref
"""
return [head_el for head_el in head if head_el not in ref]

Expand All @@ -144,7 +150,8 @@ def format_warning_report(sys_args: list[str]) -> int:
Returns
-------
exit code
:
Exit code
"""
inputs = parse_args(sys_args)
warnings = load_warnings(inputs.report_file)
Expand Down
3 changes: 2 additions & 1 deletion scripts/openmc_data_download/multithreaded_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ async def get_size(url: str, timeout: int = 10) -> int:
Returns
-------
length in bytes of file
:
Length in bytes of file
"""
loop = asyncio.get_running_loop()
response = await loop.run_in_executor(
Expand Down
11 changes: 7 additions & 4 deletions scripts/openmc_data_download/neutronics_data_downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,9 @@ def _filter_members(
Returns
-------
A filtered list of filepaths based on user selection
for a given data library
:
A filtered list of filepaths based on user selection
for a given data library
Raises
------
Expand Down Expand Up @@ -140,7 +141,8 @@ def _filter(
Returns
-------
A filtered list of filepaths based on user selection
:
A filtered list of filepaths based on user selection
"""
filtered_members = []
mem_keys = members.keys()
Expand Down Expand Up @@ -216,7 +218,8 @@ def parse_args(args: list[str] | None = None) -> argparse.Namespace:
Returns
-------
parsed argument namespace
:
Parsed argument namespace
"""
parser = argparse.ArgumentParser("Bluemira Neutronics data downloader")

Expand Down
Loading

0 comments on commit 3de496a

Please sign in to comment.