Skip to content

Commit

Permalink
fix: improve typing
Browse files Browse the repository at this point in the history
  • Loading branch information
mirkolenz committed Nov 8, 2024
1 parent 12686fa commit 64c0a45
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 19 deletions.
2 changes: 1 addition & 1 deletion arguebuf/dump/_dump_dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ def dump_dict(graph: Graph, config: Config = DefaultConfig) -> dict[str, t.Any]:
elif config.format == Format.XAIF:
return t.cast(dict[str, t.Any], dump_xaif(graph))

return MessageToDict(dump_protobuf(graph), including_default_value_fields=False)
return MessageToDict(dump_protobuf(graph), including_default_value_fields=False) # type: ignore
5 changes: 4 additions & 1 deletion arguebuf/load/_load_casebase.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@ def __init__(self, name: str, cases: str | None = None, **kwargs: str):
for key, value in kwargs.items():
self.kwargs[key] = re.compile(value)

def __eq__(self, other: FilesystemFilter) -> bool:
def __eq__(self, other) -> bool:
if not isinstance(other, FilesystemFilter):
return False

return self.kwargs == other.kwargs and self >= other

def __ge__(self, other: FilesystemFilter) -> bool:
Expand Down
5 changes: 2 additions & 3 deletions arguebuf/model/edge.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import logging
import typing as t

from arguebuf.model import utils
from arguebuf.model.metadata import Metadata
Expand Down Expand Up @@ -59,8 +58,8 @@ def __init__(
def __post_init__(self):
pass

def __eq__(self, other: t.Optional["Edge"]) -> bool:
if other is None:
def __eq__(self, other) -> bool:
if other is None or not isinstance(other, Edge):
return False

return (
Expand Down
5 changes: 0 additions & 5 deletions arguebuf/model/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
class Metadata:
created: pendulum.DateTime
updated: pendulum.DateTime
# _analyst: t.Optional[Analyst] = None

def __init__(
self,
Expand All @@ -18,9 +17,5 @@ def __init__(
self.created = created or now
self.updated = updated or now

# @property
# def analyst(self) -> t.Optional[Analyst]:
# return self._analyst

def update(self) -> None:
self.updated = pendulum.now()
8 changes: 4 additions & 4 deletions arguebuf/model/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,11 @@ def __init__(

self.__post_init__()

def __post_init__(self):
def __post_init__(self): # noqa: B027
pass

def __eq__(self, other: "AbstractNode") -> bool:
if other is None:
def __eq__(self, other) -> bool:
if other is None or not isinstance(other, AbstractNode):
return False

return self.id == other.id
Expand Down Expand Up @@ -214,5 +214,5 @@ def color(self, major_claim: bool, monochrome: bool) -> Color:
return scheme2color[type(self.scheme)] if self.scheme else Color(bg="#009688")


AtomOrSchemeNode = t.Union[AtomNode, SchemeNode]
AtomOrSchemeNode = AtomNode | SchemeNode
NodeType = t.TypeVar("NodeType", AtomNode, SchemeNode, AbstractNode)
3 changes: 1 addition & 2 deletions arguebuf/model/scheme.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import typing as t
from enum import Enum

from arg_services.graph.v1 import graph_pb2
Expand Down Expand Up @@ -116,7 +115,7 @@ class Rephrase(str, Enum):
DEFAULT = "Default"


Scheme = t.Union[Support, Attack, Rephrase, Preference]
Scheme = Support | Attack | Rephrase | Preference

support2protobuf = {
item: graph_pb2.Support.Value(f"SUPPORT_{item.name}") for item in Support
Expand Down
2 changes: 1 addition & 1 deletion arguebuf/model/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def __len__(self) -> int:
def __getitem__(self, key: _T) -> _U:
return self._store.__getitem__(key)

def __contains__(self, key: _T) -> bool:
def __contains__(self, key) -> bool:
return self._store.__contains__(key)

def __iter__(self) -> t.Iterator:
Expand Down
4 changes: 2 additions & 2 deletions arguebuf/schemas/graphviz.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import typing as t
from enum import Enum
from typing import Any

from graphviz import Digraph

GraphvizGraph = t.Union[Digraph, t.Any]
GraphvizGraph = Digraph | Any


class EdgeStyle(str, Enum):
Expand Down

0 comments on commit 64c0a45

Please sign in to comment.