Skip to content

Commit

Permalink
Apply extra Ruff rule
Browse files Browse the repository at this point in the history
  • Loading branch information
gerlero committed Nov 2, 2024
1 parent c993d28 commit 8a90b4c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 15 deletions.
24 changes: 14 additions & 10 deletions electrolytes/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from __future__ import annotations

import pkgutil
from collections.abc import Collection, Iterator, Mapping, Sequence
from contextlib import ContextDecorator, suppress
from functools import cached_property, singledispatchmethod
from pathlib import Path
from types import TracebackType
from typing import Annotated, Optional
from typing import TYPE_CHECKING, Annotated, Self
from warnings import warn

from filelock import FileLock
Expand All @@ -18,11 +19,14 @@
)
from typer import get_app_dir

if TYPE_CHECKING:
from types import TracebackType

Check warning on line 23 in electrolytes/__init__.py

View check run for this annotation

Codecov / codecov/patch

electrolytes/__init__.py#L23

Added line #L23 was not covered by tests

__version__ = "0.4.6"


class Constituent(BaseModel, populate_by_name=True, frozen=True):
id: Optional[int] = None
id: int | None = None
name: str
u_neg: Annotated[
list[float], Field(alias="uNeg")
Expand Down Expand Up @@ -112,7 +116,7 @@ def _pka_lengths(cls, v: list[float], info: ValidationInfo) -> list[float]:

@field_validator("neg_count", "pos_count", mode="before")
@classmethod
def _counts(cls, v: Optional[int], info: ValidationInfo) -> int:
def _counts(cls, v: int | None, info: ValidationInfo) -> int:
assert isinstance(info.field_name, str)
if v is None:
v = len(info.data[f"u_{info.field_name[:3]}"])
Expand All @@ -122,7 +126,7 @@ def _counts(cls, v: Optional[int], info: ValidationInfo) -> int:
return v

@model_validator(mode="after")
def _pkas_not_increasing(self) -> "Constituent":
def _pkas_not_increasing(self) -> Constituent:
pkas = [*self.pkas_neg, *self.pkas_pos]

if not all(x >= y for x, y in zip(pkas, pkas[1:])):
Expand All @@ -136,7 +140,7 @@ def _pkas_not_increasing(self) -> "Constituent":


def _load_constituents(
data: bytes, context: Optional[dict[str, str]] = None
data: bytes, context: dict[str, str] | None = None
) -> list[Constituent]:
return _StoredConstituents.validate_json(data, context=context)["constituents"]

Expand Down Expand Up @@ -194,7 +198,7 @@ def _save_user_constituents(self) -> None:
self._user_constituents_file.write_bytes(data)
self._user_constituents_dirty = False

def __enter__(self) -> "_Database":
def __enter__(self) -> Self:
if not self._user_constituents_lock.is_locked:
self._invalidate_user_constituents()
self._user_constituents_lock.acquire()
Expand All @@ -203,9 +207,9 @@ def __enter__(self) -> "_Database":

def __exit__(
self,
exc_type: Optional[type[BaseException]],
exc_value: Optional[BaseException],
traceback: Optional[TracebackType],
exc_type: type[BaseException] | None,
exc_value: BaseException | None,
traceback: TracebackType | None,
) -> None:
try:
if (
Expand Down
12 changes: 7 additions & 5 deletions electrolytes/__main__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from typing import Annotated, Optional
from __future__ import annotations

from typing import Annotated

import typer

Expand Down Expand Up @@ -135,7 +137,7 @@ def add(
@app.command()
def info(
names: Annotated[
Optional[list[str]],
list[str] | None,
typer.Argument(help="Component names", autocompletion=complete_name),
] = None,
) -> None:
Expand Down Expand Up @@ -192,7 +194,7 @@ def info(
def ls(
*,
user: Annotated[
Optional[bool],
bool | None,
typer.Option(
"--user/--default", help="List only user-defined/default components"
),
Expand All @@ -218,7 +220,7 @@ def rm(
],
*,
force: Annotated[
Optional[bool], typer.Option("-f", help="Ignore non-existent components")
bool | None, typer.Option("-f", help="Ignore non-existent components")
] = False,
) -> None:
"""Remove user-defined components from the database."""
Expand All @@ -243,7 +245,7 @@ def rm(
def search(
text: str,
user: Annotated[
Optional[bool],
bool | None,
typer.Option(
"--user/--default", help="Search only user-defined/default components"
),
Expand Down

0 comments on commit 8a90b4c

Please sign in to comment.