Skip to content

Commit

Permalink
Centralize some type checking suppressions
Browse files Browse the repository at this point in the history
  • Loading branch information
MSK61 committed Jul 16, 2024
1 parent 97f805d commit 91e83ec
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 21 deletions.
6 changes: 3 additions & 3 deletions src/processor_sim.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@ def run(processor_file: IO[str], program_file: IO[str]) -> None:
"""
with processor_file, program_file:
ResultWriter(
sys.stdout # type: ignore[reportArgumentType]
).print_sim_res(_get_sim_res(processor_file, program_file))
type_checking.call(ResultWriter, sys.stdout).print_sim_res(
_get_sim_res(processor_file, program_file)
)


@frozen
Expand Down
15 changes: 4 additions & 11 deletions src/processor_utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
from errors import UndefElemError
from str_utils import ICaseString
import type_checking
from type_checking import call
from . import _checks, _optimization, _port_defs, units
from .exception import BadEdgeError, BadWidthError, DupElemError
from .units import (
Expand Down Expand Up @@ -466,12 +467,7 @@ def _get_proc_units(graph: DiGraph) -> Generator[FuncUnit, None, None]:
unit: _get_unit_entry(unit, graph.nodes[unit]) for unit in graph
}
return (
FuncUnit(
unit_map[name],
_get_preds(
graph, name, unit_map
), # type: ignore[reportArgumentType]
)
call(FuncUnit, unit_map[name], _get_preds(graph, name, unit_map))
for name in graph
)

Expand Down Expand Up @@ -737,11 +733,8 @@ def _make_processor(proc_graph: DiGraph) -> ProcessorDesc:
case _:
in_out_ports.append(unit.model)

return ProcessorDesc(
in_ports, # type: ignore[reportArgumentType]
out_ports, # type: ignore[reportArgumentType]
in_out_ports, # type: ignore[reportArgumentType]
internal_units, # type: ignore[reportArgumentType]
return call(
ProcessorDesc, in_ports, out_ports, in_out_ports, internal_units
)


Expand Down
8 changes: 3 additions & 5 deletions src/program_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
from errors import UndefElemError
from program_defs import HwInstruction, ProgInstruction
from str_utils import ICaseString
import type_checking

_T = typing.TypeVar("_T")

Expand Down Expand Up @@ -162,11 +163,8 @@ def _create_instr(
"""
src_line_info = _get_line_parts(line_num, line_txt)
dst, *sources = _get_operands(src_line_info, line_num, reg_registry)
return ProgInstruction(
sources, # type: ignore[reportArgumentType]
dst,
src_line_info.instruction,
line_num,
return type_checking.call(
ProgInstruction, sources, dst, src_line_info.instruction, line_num
)


Expand Down
14 changes: 12 additions & 2 deletions src/type_checking.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
#
############################################################

import collections.abc
from collections import abc
from typing import Any, cast, TypeVar

import fastcore.foundation
Expand All @@ -50,6 +50,16 @@
_T = TypeVar("_T")


def call(func: abc.Callable[..., _T], *args: object) -> _T:
"""Call the given functor with arguments.
`func` is the function to call.
`args` are the arguments to call the function with.
"""
return func(*args)


def map_ex(seq: Any, map_func: Any, _: type[_T]) -> "map[_T]":
"""Map an iterable using a mapping function.
Expand Down Expand Up @@ -79,7 +89,7 @@ def nodes(
return graph.nodes(cast(bool, data)) # type: ignore[reportArgumentType]


def sorted_lst(seq: collections.abc.Iterable[_AnyT]) -> list[_AnyT]:
def sorted_lst(seq: abc.Iterable[_AnyT]) -> list[_AnyT]:
"""Create a sorted list of the given iterable.
`seq` is the iterable to sort.
Expand Down

0 comments on commit 91e83ec

Please sign in to comment.