Skip to content

Commit

Permalink
chore: reformat all python files
Browse files Browse the repository at this point in the history
  • Loading branch information
mirkolenz committed Oct 18, 2024
1 parent fac9a9a commit d37c881
Show file tree
Hide file tree
Showing 46 changed files with 257 additions and 301 deletions.
26 changes: 13 additions & 13 deletions arguebuf/cli/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def translate(
target_lang: str,
auth_key: str,
input_glob: str,
output_folder: t.Optional[Path] = None,
output_folder: Path | None = None,
output_format: ag.dump.Format = ag.dump.Format.ARGUEBUF,
clean: bool = False,
overwrite: bool = False,
Expand Down Expand Up @@ -51,7 +51,7 @@ def translate(


def node_label_formatter(
strip_labels: bool, strip_labels_char: t.Optional[str]
strip_labels: bool, strip_labels_char: str | None
) -> t.Callable[[ag.AbstractNode], str] | None:
_replace_char = "–" if strip_labels_char is None else strip_labels_char

Expand All @@ -68,22 +68,22 @@ def _node_label(node: ag.AbstractNode) -> str:
def render(
input_folder: Path,
input_glob: str,
output_folder: t.Optional[Path] = None,
output_folder: Path | None = None,
output_format: str = ".pdf",
strip_scheme_nodes: bool = False,
strip_node_labels: bool = False,
strip_node_labels_char: t.Optional[str] = None,
edge_style: t.Optional[ag.schemas.graphviz.EdgeStyle] = None,
nodesep: t.Optional[float] = None,
ranksep: t.Optional[float] = None,
node_wrap_col: t.Optional[int] = None,
strip_node_labels_char: str | None = None,
edge_style: ag.schemas.graphviz.EdgeStyle | None = None,
nodesep: float | None = None,
ranksep: float | None = None,
node_wrap_col: int | None = None,
node_margin: tuple[float, float] = (0, 0),
font_name: t.Optional[str] = None,
font_size: t.Optional[float] = None,
font_name: str | None = None,
font_size: float | None = None,
clean: bool = False,
overwrite: bool = False,
start: int = 1,
max_nodes: t.Optional[int] = None,
max_nodes: int | None = None,
prog: str = "dot",
dpi: int = 300,
monochrome: bool = False,
Expand Down Expand Up @@ -141,12 +141,12 @@ def render(
def convert(
input_folder: Path,
input_glob: str,
output_folder: t.Optional[Path] = None,
output_folder: Path | None = None,
output_format: ag.dump.Format = ag.dump.Format.ARGUEBUF,
clean: bool = False,
overwrite: bool = False,
start: int = 1,
text_folder: t.Optional[Path] = None,
text_folder: Path | None = None,
text_suffix: str = ".txt",
) -> None:
if not output_folder:
Expand Down
4 changes: 2 additions & 2 deletions arguebuf/cli/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ def create(
cls,
path_in: Path,
path_out: Path,
input_glob: t.Optional[str],
output_suffix: t.Optional[str],
input_glob: str | None,
output_suffix: str | None,
) -> list["PathPair"]:
pairs: list[PathPair] = []

Expand Down
3 changes: 2 additions & 1 deletion arguebuf/cli/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from pathlib import Path

import typer

from arguebuf.cli.translator import Translator

from . import model
Expand All @@ -18,7 +19,7 @@ def translate(
auth_key: str,
input_glob: str,
output_suffix: str,
output_folder: t.Optional[Path] = None,
output_folder: Path | None = None,
clean: bool = False,
overwrite: bool = False,
start: int = 1,
Expand Down
4 changes: 1 addition & 3 deletions arguebuf/cli/translator.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ def __init__(self, auth_key: str, source_lang: str, target_lang: str):
self.target_lang = target_lang
self.translator = DeepLTranslator(auth_key)

def _deepl_translate(
self, text: t.Union[str, t.Iterable[str]]
) -> t.Union[str, list[str]]:
def _deepl_translate(self, text: str | t.Iterable[str]) -> str | list[str]:
result = self.translator.translate_text(
text,
source_lang=self.source_lang,
Expand Down
10 changes: 3 additions & 7 deletions arguebuf/dt.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,19 @@
import typing as t

import pendulum
from google.protobuf import timestamp_pb2


def from_format(text: t.Optional[str], format: str) -> t.Optional[pendulum.DateTime]:
def from_format(text: str | None, format: str) -> pendulum.DateTime | None:
return pendulum.from_format(text, format) if text else None


def to_format(dt: t.Optional[pendulum.DateTime], format: str) -> str:
def to_format(dt: pendulum.DateTime | None, format: str) -> str:
return dt.format(format) if dt else ""


def from_protobuf(dt: timestamp_pb2.Timestamp) -> pendulum.DateTime:
return pendulum.instance(dt.ToDatetime()) if dt else pendulum.now()


def to_protobuf(
dt: t.Optional[pendulum.DateTime], obj: timestamp_pb2.Timestamp
) -> None:
def to_protobuf(dt: pendulum.DateTime | None, obj: timestamp_pb2.Timestamp) -> None:
if dt:
obj.FromDatetime(dt)
12 changes: 6 additions & 6 deletions arguebuf/dump/_dump_d2.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@

def dump_d2(
graph: Graph,
atom_label: t.Optional[t.Callable[[AtomNode], str]] = None,
scheme_label: t.Optional[t.Callable[[SchemeNode], str]] = None,
max_nodes: t.Optional[int] = None,
atom_label: t.Callable[[AtomNode], str] | None = None,
scheme_label: t.Callable[[SchemeNode], str] | None = None,
max_nodes: int | None = None,
monochrome: bool = False,
) -> t.Optional[D2Graph]:
) -> D2Graph | None:
if len(graph.nodes) > (max_nodes or 1000):
return None

Expand Down Expand Up @@ -50,7 +50,7 @@ def _dump_atom(
g: D2Graph,
major_claim: bool,
monochrome: bool,
label_func: t.Optional[t.Callable[[AtomNode], str]] = None,
label_func: t.Callable[[AtomNode], str] | None = None,
) -> None:
label: str = label_func(node) if label_func else node.label
color = node.color(major_claim, monochrome)
Expand Down Expand Up @@ -78,7 +78,7 @@ def _dump_scheme(
g: D2Graph,
major_claim: bool,
monochrome: bool,
label_func: t.Optional[t.Callable[[SchemeNode], str]] = None,
label_func: t.Callable[[SchemeNode], str] | None = None,
) -> None:
label: str = label_func(node) if label_func else node.label
color = node.color(False, monochrome)
Expand Down
32 changes: 16 additions & 16 deletions arguebuf/dump/_dump_graphviz.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,21 @@ def add_gv_edge(graph, *args, **kwargs): # type: ignore

def dump_graphviz(
graph: Graph,
nodesep: t.Optional[float] = None,
ranksep: t.Optional[float] = None,
wrap_col: t.Optional[int] = None,
margin: t.Optional[t.Tuple[float, float]] = None,
font_name: t.Optional[str] = None,
font_size: t.Optional[float] = None,
atom_label: t.Optional[t.Callable[[AtomNode], str]] = None,
scheme_label: t.Optional[t.Callable[[SchemeNode], str]] = None,
graph_attr: t.Optional[t.Mapping[str, str]] = None,
node_attr: t.Optional[t.Mapping[str, str]] = None,
edge_attr: t.Optional[t.Mapping[str, str]] = None,
edge_style: t.Optional[EdgeStyle] = None,
max_nodes: t.Optional[int] = None,
nodesep: float | None = None,
ranksep: float | None = None,
wrap_col: int | None = None,
margin: tuple[float, float] | None = None,
font_name: str | None = None,
font_size: float | None = None,
atom_label: t.Callable[[AtomNode], str] | None = None,
scheme_label: t.Callable[[SchemeNode], str] | None = None,
graph_attr: t.Mapping[str, str] | None = None,
node_attr: t.Mapping[str, str] | None = None,
edge_attr: t.Mapping[str, str] | None = None,
edge_style: EdgeStyle | None = None,
max_nodes: int | None = None,
monochrome: bool = False,
) -> t.Optional[GraphvizGraph]:
) -> GraphvizGraph | None:
"""Transform a Graph instance into an instance of GraphViz directed graph. Make sure that a GraphViz Executable path is set on your machine for visualization. Refer to the GraphViz library for additional information."""

if len(graph.nodes) > (max_nodes or 1000):
Expand Down Expand Up @@ -127,7 +127,7 @@ def _dump_atom(
major_claim: bool,
wrap_col: int,
monochrome: bool,
label_func: t.Optional[t.Callable[[AtomNode], str]] = None,
label_func: t.Callable[[AtomNode], str] | None = None,
) -> None:
"""Submethod used to export Graph object g into GV Graph format."""
color = node.color(major_claim, monochrome)
Expand All @@ -150,7 +150,7 @@ def _dump_scheme(
node: SchemeNode,
g: GraphvizGraph,
monochrome: bool,
label_func: t.Optional[t.Callable[[SchemeNode], str]] = None,
label_func: t.Callable[[SchemeNode], str] | None = None,
) -> None:
"""Submethod used to export Graph object g into GV Graph format."""

Expand Down
14 changes: 6 additions & 8 deletions arguebuf/dump/_dump_networkx.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,10 @@

def dump_networkx(
graph: Graph,
graph_attrs: t.Optional[t.MutableMapping[str, t.Callable[[Graph], t.Any]]] = None,
atom_attrs: t.Optional[t.MutableMapping[str, t.Callable[[AtomNode], t.Any]]] = None,
scheme_attrs: t.Optional[
t.MutableMapping[str, t.Callable[[SchemeNode], t.Any]]
] = None,
edge_attrs: t.Optional[t.MutableMapping[str, t.Callable[[Edge], t.Any]]] = None,
graph_attrs: t.MutableMapping[str, t.Callable[[Graph], t.Any]] | None = None,
atom_attrs: t.MutableMapping[str, t.Callable[[AtomNode], t.Any]] | None = None,
scheme_attrs: t.MutableMapping[str, t.Callable[[SchemeNode], t.Any]] | None = None,
edge_attrs: t.MutableMapping[str, t.Callable[[Edge], t.Any]] | None = None,
) -> nx.DiGraph:
"""Transform the argument graph for use with the library `NetworkX`
Expand Down Expand Up @@ -69,7 +67,7 @@ def dump_networkx(
def edge_to_nx(
edge: Edge,
g: nx.DiGraph,
attrs: t.Optional[t.MutableMapping[str, t.Callable[[Edge], t.Any]]] = None,
attrs: t.MutableMapping[str, t.Callable[[Edge], t.Any]] | None = None,
) -> None:
"""Submethod used to export Graph object g into NX Graph format."""

Expand All @@ -86,7 +84,7 @@ def edge_to_nx(
def node_to_nx(
node: AbstractNode,
g: nx.DiGraph,
attrs: t.Optional[t.MutableMapping[str, t.Callable[[AbstractNode], t.Any]]] = None,
attrs: t.MutableMapping[str, t.Callable[[AbstractNode], t.Any]] | None = None,
) -> None:
"""Submethod used to export Graph object g into NX Graph format."""
if attrs is None:
Expand Down
5 changes: 1 addition & 4 deletions arguebuf/dump/_dump_path.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import typing as t
from pathlib import Path

from arguebuf.model import Graph
Expand All @@ -9,9 +8,7 @@
__all__ = ("dump_file",)


def dump_file(
graph: Graph, path: t.Union[Path, str], config: Config = DefaultConfig
) -> None:
def dump_file(graph: Graph, path: Path | str, config: Config = DefaultConfig) -> None:
"""Export structure of Graph instance into structure of File/Folder format."""
if isinstance(path, str):
path = Path(path)
Expand Down
2 changes: 1 addition & 1 deletion arguebuf/load/_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

@dataclass
class Config(t.Generic[TextType]):
nlp: t.Optional[t.Callable[[str], TextType]] = None
nlp: t.Callable[[str], TextType] | None = None
GraphClass: type[Graph] = Graph
AtomNodeClass: type[AtomNode] = AtomNode
SchemeNodeClass: type[SchemeNode] = SchemeNode
Expand Down
10 changes: 6 additions & 4 deletions arguebuf/load/_load_aif.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import typing as t
from arguebuf.load._preprocess_aif import process_hanging_nodes

import pendulum

from arguebuf import dt
from arguebuf.load._preprocess_aif import process_hanging_nodes
from arguebuf.model import Graph, utils
from arguebuf.model.edge import Edge, warn_missing_nodes
from arguebuf.model.node import AbstractNode, AtomNode, SchemeNode
Expand All @@ -15,7 +17,7 @@

def load_aif(
obj: aif.Graph,
name: t.Optional[str] = None,
name: str | None = None,
config: Config = DefaultConfig,
reconstruct_dialog: bool = False,
) -> Graph:
Expand Down Expand Up @@ -57,7 +59,7 @@ def atom_from_aif(obj: aif.Node, config: Config) -> AtomNode:
)


def scheme_from_aif(obj: aif.Node, config: Config) -> t.Optional[SchemeNode]:
def scheme_from_aif(obj: aif.Node, config: Config) -> SchemeNode | None:
"""Generate SchemeNode object from AIF Node object."""

aif_type = obj["type"]
Expand Down Expand Up @@ -87,7 +89,7 @@ def scheme_from_aif(obj: aif.Node, config: Config) -> t.Optional[SchemeNode]:

def edge_from_aif(
obj: aif.Edge, nodes: t.Mapping[str, AbstractNode], config: Config
) -> t.Optional[Edge]:
) -> Edge | None:
"""Generate Edge object from AIF Edge format."""
source_id = obj.get("fromID")
target_id = obj.get("toID")
Expand Down
2 changes: 1 addition & 1 deletion arguebuf/load/_load_aml.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@


def load_aml(
obj: t.IO, name: t.Optional[str] = None, config: Config = DefaultConfig
obj: t.IO, name: str | None = None, config: Config = DefaultConfig
) -> Graph:
"""
Generate Graph structure from AML argument graph file
Expand Down
6 changes: 3 additions & 3 deletions arguebuf/load/_load_argdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

def load_argdown(
obj: argdown.Graph,
name: t.Optional[str] = None,
name: str | None = None,
config: Config = DefaultConfig,
) -> Graph:
"""Generate Graph structure from JSON Argdown argument graph file
Expand Down Expand Up @@ -60,7 +60,7 @@ def edge_from_argdown(
obj: argdown.Edge,
nodes: t.Mapping[str, AbstractNode],
edge_class: type[Edge] = Edge,
) -> t.Optional[Edge]:
) -> Edge | None:
"""Generate Edge object from Argdown JSON Edge format."""

source_id = obj.get("from", obj.get("source"))
Expand All @@ -81,7 +81,7 @@ def edge_from_argdown(

def atom_from_argdown(
obj: argdown.Node,
nlp: t.Optional[t.Callable[[str], t.Any]] = None,
nlp: t.Callable[[str], t.Any] | None = None,
node_class: type[AtomNode] = AtomNode,
) -> AtomNode:
"""Generate AtomNode object from Argdown JSON Node object."""
Expand Down
2 changes: 1 addition & 1 deletion arguebuf/load/_load_brat.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

def load_brat(
obj: t.TextIO,
name: t.Optional[str] = None,
name: str | None = None,
config: Config = DefaultConfig,
) -> Graph:
"""Generate Graph structure from BRAT argument graph file (reference: https://brat.nlplab.org/)"""
Expand Down
12 changes: 6 additions & 6 deletions arguebuf/load/_load_casebase.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ def from_path(cls, path: Path) -> "FilesystemFilter":

class CasebaseFilter:
name: re.Pattern
cases: t.Optional[re.Pattern]
cases: re.Pattern | None
kwargs: dict[str, re.Pattern]

def __init__(self, name: str, cases: t.Optional[str] = None, **kwargs: str):
def __init__(self, name: str, cases: str | None = None, **kwargs: str):
self.name = re.compile(name)
self.cases = re.compile(cases) if cases is not None else None
self.kwargs = {}
Expand All @@ -87,7 +87,7 @@ def from_protobuf(cls, filter: CasebaseFilterProto) -> "CasebaseFilter":


def convert_filters(
filters: t.Union[CasebaseFilterType, t.Iterable[CasebaseFilterType], None],
filters: CasebaseFilterType | t.Iterable[CasebaseFilterType] | None,
) -> list[CasebaseFilter]:
if filters is None:
return []
Expand All @@ -106,9 +106,9 @@ def convert_filters(


def load_casebase(
include: t.Union[CasebaseFilterType, t.Iterable[CasebaseFilterType]],
exclude: t.Union[CasebaseFilterType, t.Iterable[CasebaseFilterType], None] = None,
basepath: t.Union[Path, str] = ".",
include: CasebaseFilterType | t.Iterable[CasebaseFilterType],
exclude: CasebaseFilterType | t.Iterable[CasebaseFilterType] | None = None,
basepath: Path | str = ".",
glob: str = "*/*",
config: Config = DefaultConfig,
strict_equal: bool = False,
Expand Down
Loading

0 comments on commit d37c881

Please sign in to comment.