Skip to content

Fix pylint mypy issues - #413

Merged
chbricout merged 1 commit into
april-tools:mainfrom
IrwinChay:fix-pylint-mypy
Jul 14, 2026
Merged

Fix pylint mypy issues#413
chbricout merged 1 commit into
april-tools:mainfrom
IrwinChay:fix-pylint-mypy

Conversation

@IrwinChay

@IrwinChay IrwinChay commented Jun 25, 2026

Copy link
Copy Markdown
Collaborator

This PR fixes all the existing linting and typing issues outputted by pylint and mypy.

Currently mypy found no issues, and all issues found by pylint are of missing class or function docstrings, since some files (e.g. cirkit/backend/torch/rules/parameters.py ) have no docstrings at all

The reasonings for some changes are shown below (in the conversation)

I think we should write the missing docstrings in another PR, which might not be in near future and might requires further discussions (since it affects the documentation). Noted down in Issue #414

def outputs(self) -> Iterator[LogicalCircuitNode]:
return (cast(LogicalCircuitNode, node) for node in super().outputs)
def outputs(self) -> Sequence[LogicalCircuitNode]:
return super().outputs

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

inputs and outputs are already defined in super class Graph and DiAcyclicGraph in algorithms.py, and outputs should be a Sequence, not Iterator, similar to lines 142-148 in here

in_nodes = self._in_nodes
in_nodes: dict[LogicalCircuitNode, list[LogicalCircuitNode]] = {
node: list(inputs) for node, inputs in self.nodes_inputs.items()
}

@IrwinChay IrwinChay Jun 25, 2026

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

original in_nodes has type Mapping[LogicalCircuitNode, Sequence[LogicalCircuitNode]], but this function has dict and list operations (extend, append…) on it

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we ever use an immutable mapping or have a need for one ? Maybe we can just switch Mapping to MutableMapping in the parent class ? @loreloc

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we ever use immutable mapping, but I failed to see how this is related to immutable mapping?

The new in_nodes creates a mutable local copy with type dict[LogicalCircuitNode, list[LogicalCircuitNode]] instead of the original type Mapping[LogicalCircuitNode, Sequence[LogicalCircuitNode]] in the parent

So the parent is generic and the local is specific. (If we use MutableMapping in the parent class, we will also need MutableSequence in the parent class, so MutableMapping[NodeT, MutableSequence[NodeT]] , too restrictive?)

Fix these

cirkit/templates/logic/graph.py:209: error: Unsupported target for indexed assignment ("Mapping[LogicalCircuitNode, Sequence[LogicalCircuitNode]]")  [index]
cirkit/templates/logic/graph.py:220: error: "Sequence[LogicalCircuitNode]" has no attribute "extend"  [attr-defined]
cirkit/templates/logic/graph.py:223: error: Unsupported target for indexed assignment ("Mapping[LogicalCircuitNode, Sequence[LogicalCircuitNode]]")  [index]
cirkit/templates/logic/graph.py:224: error: "Sequence[LogicalCircuitNode]" has no attribute "append"  [attr-defined]
cirkit/templates/logic/graph.py:227: error: "Sequence[LogicalCircuitNode]" has no attribute "remove"  [attr-defined]
cirkit/templates/logic/graph.py:229: error: "Sequence[LogicalCircuitNode]" has no attribute "insert"  [attr-defined]

Comment thread cirkit/templates/logic/graph.py
pic_net = self # Capture reference to self

def forward_hook(module, input, output):
def forward_hook(_module, _input, _output):

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix these
cirkit/backend/torch/parameters/pic.py:262:25: W0613: Unused argument 'module' (unused-argument) cirkit/backend/torch/parameters/pic.py:262:33: W0613: Unused argument 'input' (unused-argument) cirkit/backend/torch/parameters/pic.py:262:40: W0613: Unused argument 'output' (unused-argument)

@IrwinChay IrwinChay changed the title Fix pylint mypy issues (except docstrings) Fix pylint mypy issues Jun 25, 2026

@chbricout chbricout left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good PR! I just have this one question regarding MutableMapping, not sure if we intended to have an immutable structure as the code is not necessarily oriented towards that (in place operations and all).
I would like to have a quick opinion from Lorenzo and/or @arranger1044

Comment thread cirkit/templates/logic/graph.py
@chbricout
chbricout merged commit a637b44 into april-tools:main Jul 14, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants