Skip to content

Commit

Permalink
fix: More specific type annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
ewuerger committed Oct 29, 2024
1 parent 17298ab commit db5ae58
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 23 deletions.
24 changes: 7 additions & 17 deletions capellambse_context_diagrams/collectors/exchanges.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,7 @@ class ExchangeCollector(metaclass=abc.ABCMeta):

def __init__(
self,
diagram: (
context.InterfaceContextDiagram | context.FunctionalContextDiagram
),
diagram: (context.InterfaceContextDiagram | context.FunctionalContextDiagram),
data: _elkjs.ELKInputData,
params: dict[str, t.Any],
) -> None:
Expand Down Expand Up @@ -104,9 +102,7 @@ def collect(self) -> None:


def get_elkdata_for_exchanges(
diagram: (
context.InterfaceContextDiagram | context.FunctionalContextDiagram
),
diagram: (context.InterfaceContextDiagram | context.FunctionalContextDiagram),
collector_type: type[ExchangeCollector],
params: dict[str, t.Any],
) -> _elkjs.ELKInputData:
Expand Down Expand Up @@ -343,9 +339,7 @@ def get_owner_savely(self, attr_getter: t.Callable) -> m.ModelElement:
except AttributeError:
assert owner is None
# pylint: disable-next=raise-missing-from
raise errors.CapellambseError(
f"Port has no owner: '{self.obj.name}'"
)
raise errors.CapellambseError(f"Port has no owner: '{self.obj.name}'")

def get_left_and_right(self) -> None:
source = self.get_owner_savely(self.get_source)
Expand Down Expand Up @@ -391,13 +385,9 @@ def get_source_and_target_ports(
port_label_position = plp.name

assert self.left is not None
self.left.layoutOptions["portLabels.placement"] = (
port_label_position
)
self.left.layoutOptions["portLabels.placement"] = port_label_position
assert self.right is not None
self.right.layoutOptions["portLabels.placement"] = (
port_label_position
)
self.right.layoutOptions["portLabels.placement"] = port_label_position
return left_port, right_port

def collect(self) -> None:
Expand Down Expand Up @@ -437,13 +427,13 @@ def is_hierarchical(

def functional_context_collector(
diagram: context.FunctionalContextDiagram, pars: dict[str, t.Any]
):
) -> _elkjs.ELKInputData:
return get_elkdata_for_exchanges(diagram, FunctionalContextCollector, pars)


def interface_context_collector(
diagram: context.InterfaceContextDiagram, pars: dict[str, t.Any]
) -> _elkjs.ELKInputData | tuple[_elkjs.ELKInputData, _elkjs.ELKInputData]:
) -> _elkjs.ELKInputData:
collector: t.Type[ExchangeCollector]
if isinstance(diagram.target, cs.PhysicalLink):
collector = PhysicalLinkContextCollector
Expand Down
8 changes: 2 additions & 6 deletions capellambse_context_diagrams/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -449,9 +449,7 @@ def __init__(
default_render_parameters=default_render_parameters,
)
self.collector: cabc.Callable[
[InterfaceContextDiagram, dict[str, t.Any]],
_elkjs.ELKInputData
| tuple[_elkjs.ELKInputData, _elkjs.ELKInputData],
[InterfaceContextDiagram, dict[str, t.Any]], _elkjs.ELKInputData
] = exchanges.interface_context_collector

@property
Expand Down Expand Up @@ -480,9 +478,7 @@ def __init__(
)

self.collector: cabc.Callable[
[FunctionalContextDiagram, dict[str, t.Any]],
_elkjs.ELKInputData
| tuple[_elkjs.ELKInputData, _elkjs.ELKInputData],
[FunctionalContextDiagram, dict[str, t.Any]], _elkjs.ELKInputData
] = exchanges.functional_context_collector

@property
Expand Down

0 comments on commit db5ae58

Please sign in to comment.