Skip to content

Commit

Permalink
Typing adjustments
Browse files Browse the repository at this point in the history
  • Loading branch information
thvitt committed Mar 27, 2020
1 parent fbc4388 commit 33e484c
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/macrogen/datings.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
logger = config.getLogger(__name__)


def parse_datestr(datestr: str) -> date:
def parse_datestr(datestr: str) -> Optional[date]:
"""
Parses a date str like 1799-01-01 to a date.
Expand Down Expand Up @@ -80,7 +80,7 @@ def add_to_graph(self, G: nx.MultiDiGraph):
...


def _firstattr(object, *args: Tuple[str]) -> Optional[Tuple[str, Any]]:
def _firstattr(object: Any, *args: str) -> Tuple[Optional[str], Optional[Any]]:
"""
Returns the first of the given attributes together with its value. E.g., when an object o has the attributes bar=1
and baz=2 and none else and you call ``_firstattr(o, 'foo', 'bar', 'baz')`` it will return ``'bar', 1``
Expand Down Expand Up @@ -215,7 +215,7 @@ def add_to_graph(self, G: nx.MultiDiGraph) -> None:
ignore=self.ignore)


def _parse_file(filename: str) -> Generator[_AbstractDating, None, None]:
def _parse_file(filename: Union[Path, str]) -> Generator[_AbstractDating, None, None]:
"""
Parses the given macrogenesis XML file and returns the datings from there.
Args:
Expand Down
2 changes: 2 additions & 0 deletions src/macrogen/fes.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ def _exhaust_sinks(self, sink: bool = True):
"""
sink_method = self.graph.out_degree if sink else self.graph.in_degree
while True:
# noinspection PyCallingNonCallable
sinks = [u for (u, d) in sink_method() if d == 0]
if sinks:
yield from sinks
Expand Down Expand Up @@ -140,6 +141,7 @@ def solve(self) -> List[Tuple[V, V]]:
for v in self._exhaust_sources():
self.to_start(v)
if self.graph:
# noinspection PyCallingNonCallable
u = max(self.graph.nodes, key=lambda v: self.graph.out_degree(v, weight='weight')
- self.graph.in_degree(v, weight='weight'))
self.to_start(u)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_fes.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def test_eades_ff():
result = Eades(g).solve()
assert set(result) == {(2, 3)}

solver = Eades(g, [(4,5), (2, 3)])
solver = Eades(g, [(4, 5), (2, 3)])
result = set(solver.solve())
assert set(result) == {(3, 2)}

Expand Down

0 comments on commit 33e484c

Please sign in to comment.