Skip to content

Commit

Permalink
Fix type hinting errors (#133)
Browse files Browse the repository at this point in the history
  • Loading branch information
LaurentAjdnik authored Jun 21, 2022
1 parent b10b1a7 commit d5ea6ef
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 38 deletions.
17 changes: 0 additions & 17 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -145,20 +145,3 @@ jobs:
branch: gh-pages
folder: docs/_build/html
if: ${{ github.event_name == 'push' }}
mypy:
runs-on: "ubuntu-20.04"
needs: build
steps:
- uses: actions/checkout@v2
with:
submodules: false

- name: Download Build Artifacts
uses: actions/download-artifact@v2
with:
name: manylinux-artifacts
path: target/wheels

- name: Check type annotations and mypy stub files
run: ./build.ps1 -t checkmypy
shell: pwsh
2 changes: 1 addition & 1 deletion eng/psakefile.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ task manylinux -depends build-manylinux-container-image, run-manylinux-container

task musllinux -depends build-musllinux-container-image, run-musllinux-container-image, run-examples-in-musl-containers

task checks -depends cargo-fmt, cargo-clippy
task checks -depends cargo-fmt, cargo-clippy, checkmypy

task rebuild -depends qirlib, generator, evaluator, parser

Expand Down
2 changes: 1 addition & 1 deletion pyqir-evaluator/pyqir/evaluator/_nonadaptiveevaluator.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Licensed under the MIT License.

from pyqir.evaluator._gateset import GateSet
from pyqir.evaluator._native import PyNonadaptiveJit
from pyqir.evaluator._native import PyNonadaptiveJit # type: ignore
from typing import List, Optional


Expand Down
37 changes: 18 additions & 19 deletions pyqir-parser/pyqir/parser/_parser.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.

from pyqir.parser._native import (
from pyqir.parser._native import ( # type: ignore
PyQirModule,
PyQirFunction,
PyQirParameter,
Expand All @@ -12,7 +12,7 @@
PyQirType,
module_from_bitcode
)
from typing import List, Optional, Tuple
from typing import cast, List, Optional, Tuple

__all__ = [
"QirType",
Expand Down Expand Up @@ -587,7 +587,7 @@ def __new__(cls, instr: PyQirInstruction):

def __init__(self, instr: PyQirInstruction):
self.instr = instr
self._type = None
self._type: Optional[QirType] = None

@property
def output_name(self) -> Optional[str]:
Expand All @@ -605,7 +605,7 @@ def type(self) -> QirType:
"""
if self._type == None:
self._type = QirType(self.instr.type)
return self._type
return cast(QirType, self._type)


class QirOpInstr(QirInstr):
Expand Down Expand Up @@ -917,9 +917,9 @@ class QirBlock:

def __init__(self, block: PyQirBasicBlock):
self.block = block
self._instructions = None
self._terminator = None
self._phi_nodes = None
self._instructions: Optional[List[QirInstr]] = None
self._terminator: Optional[QirTerminator] = None
self._phi_nodes: Optional[List[QirPhiInstr]] = None

@property
def name(self) -> str:
Expand All @@ -938,7 +938,7 @@ def instructions(self) -> List[QirInstr]:
"""
if self._instructions == None:
self._instructions = [QirInstr(i) for i in self.block.instructions]
return self._instructions
return cast(List[QirInstr], self._instructions)

@property
def terminator(self) -> QirTerminator:
Expand All @@ -948,7 +948,7 @@ def terminator(self) -> QirTerminator:
"""
if self._terminator == None:
self._terminator = QirTerminator(self.block.terminator)
return self._terminator
return cast(QirTerminator, self._terminator)

@property
def phi_nodes(self) -> List[QirPhiInstr]:
Expand All @@ -960,7 +960,7 @@ def phi_nodes(self) -> List[QirPhiInstr]:
"""
if self._phi_nodes == None:
self._phi_nodes = [QirPhiInstr(i) for i in self.block.phi_nodes]
return self._phi_nodes
return cast(List[QirPhiInstr], self._phi_nodes)

def get_phi_pairs_by_source_name(self, name: str) -> List[Tuple[str, QirOperand]]:
"""
Expand All @@ -979,7 +979,7 @@ class QirParameter:

def __init__(self, param: PyQirParameter):
self.param = param
self._type = None
self._type: Optional[QirType] = None

@property
def name(self) -> str:
Expand All @@ -996,7 +996,7 @@ def type(self) -> QirType:
"""
if self._type == None:
self._type = QirType(self.param.type)
return self._type
return cast(QirType, self._type)


class QirFunction:
Expand All @@ -1007,10 +1007,9 @@ class QirFunction:

def __init__(self, func: PyQirFunction):
self.func = func
self._parameters = None
self._parameters = None
self._return_type = None
self._blocks = None
self._parameters: Optional[List[QirParameter]] = None
self._return_type: Optional[QirType] = None
self._blocks: Optional[List[QirBlock]] = None

@property
def name(self) -> str:
Expand All @@ -1026,7 +1025,7 @@ def parameters(self) -> List[QirParameter]:
"""
if self._parameters == None:
self._parameters = [QirParameter(i) for i in self.func.parameters]
return self._parameters
return cast(List[QirParameter], self._parameters)

@property
def return_type(self) -> QirType:
Expand All @@ -1035,7 +1034,7 @@ def return_type(self) -> QirType:
"""
if self._return_type == None:
self._return_type = QirType(self.func.return_type)
return self._return_type
return cast(QirType, self._return_type)

@property
def blocks(self) -> List[QirBlock]:
Expand All @@ -1044,7 +1043,7 @@ def blocks(self) -> List[QirBlock]:
"""
if self._blocks == None:
self._blocks = [QirBlock(i) for i in self.func.blocks]
return self._blocks
return cast(List[QirBlock], self._blocks)

@property
def required_qubits(self) -> Optional[int]:
Expand Down

0 comments on commit d5ea6ef

Please sign in to comment.