From 8167e1a1e9968cc7af9444206e1917f2a436d482 Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Fri, 17 May 2024 15:30:22 -0400 Subject: [PATCH] chore: bump pyright to 1.1.363 (#2232) ## Summary by CodeRabbit - **Chores** - Updated Pyright version in workflow from `1.1.308` to `1.1.363`. - **Refactor** - Enhanced code readability and maintainability by adding type annotations to internal methods in `_detect.py`. - Improved clarity in data handling by adding type hints in the table printing function in `_matrix.py`. - **Bug Fixes** - Ensured proper handling of molecule creation and manipulation without type annotations in the `convertSMILES` method of the `Path` class in `_path.py`. --------- Signed-off-by: Jinzhe Zeng Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- .github/workflows/pyright.yml | 2 +- reacnetgenerator/_detect.py | 18 +++++++++--------- reacnetgenerator/_matrix.py | 5 ++++- reacnetgenerator/_path.py | 8 ++++---- reacnetgenerator/py.typed | 0 5 files changed, 18 insertions(+), 15 deletions(-) create mode 100644 reacnetgenerator/py.typed diff --git a/.github/workflows/pyright.yml b/.github/workflows/pyright.yml index ba7f455e4..a6e049c3f 100644 --- a/.github/workflows/pyright.yml +++ b/.github/workflows/pyright.yml @@ -25,4 +25,4 @@ jobs: - run: uv pip install --system -e . - uses: jakebailey/pyright-action@v2 with: - version: 1.1.308 + version: 1.1.363 diff --git a/reacnetgenerator/_detect.py b/reacnetgenerator/_detect.py index 55a011990..619ec007a 100644 --- a/reacnetgenerator/_detect.py +++ b/reacnetgenerator/_detect.py @@ -173,11 +173,11 @@ def _compressvalue(self, x): return listtobytes(np.array(x)) @abstractmethod - def _readNfunc(self, f): + def _readNfunc(self, f) -> int: pass @abstractmethod - def _readstepfunc(self, item): + def _readstepfunc(self, item) -> Tuple[List[bytes], Tuple[int, int]]: pass def _connectmolecule(self, bond, level): @@ -207,7 +207,7 @@ def _writemoleculetempfile(self, d): @_Detect.register_subclass("bond") @_Detect.register_subclass("lammpsbondfile") class _DetectLAMMPSbond(_Detect): - def _readNfunc(self, f): + def _readNfunc(self, f) -> int: iscompleted = False N = None atomtype = None @@ -236,10 +236,10 @@ def _readNfunc(self, f): self.atomtype = atomtype return steplinenum - def _readstepfunc(self, item): + def _readstepfunc(self, item) -> Tuple[List[bytes], Tuple[int, int]]: step, lines = item - bond: list[Optional[Tuple[int]]] = [None] * self.N - level: list[Optional[Tuple[int]]] = [None] * self.N + bond: list[Optional[Tuple[int, ...]]] = [None] * self.N + level: list[Optional[Tuple[int, ...]]] = [None] * self.N timestep = None for line in lines: if line: @@ -390,7 +390,7 @@ def _readNfunc(self, f): self.atomtype = atomtype return steplinenum - def _readstepfunc(self, item): + def _readstepfunc(self, item) -> Tuple[List[bytes], Tuple[int, int]]: step, lines = item step_atoms = [] ss = [] @@ -439,7 +439,7 @@ def _readstepfunc(self, item): zhi = ss[2][1] boxsize = np.array( [ - [xhi - xlo, 0.0, 0.0], # type: ignore + [xhi - xlo, 0.0, 0.0], [xy, yhi - ylo, 0.0], [xz, yz, zhi - zlo], ] @@ -477,7 +477,7 @@ def _readNfunc(self, f): steplinenum = N + 2 return steplinenum - def _readstepfunc(self, item): + def _readstepfunc(self, item) -> Tuple[List[bytes], Tuple[int, int]]: step, lines = item timestep = step, step step_atoms = [] diff --git a/reacnetgenerator/_matrix.py b/reacnetgenerator/_matrix.py index 38927bcf9..3775172f2 100644 --- a/reacnetgenerator/_matrix.py +++ b/reacnetgenerator/_matrix.py @@ -124,8 +124,11 @@ def _printtable(self, allroute, timeaxis=None): if all(reactionnumber >= 0): table[tuple(reactionnumber)] = n_reaction + species_idx = pd.Index(species) df = pd.DataFrame( - table[: len(species), : len(species)], index=species, columns=species + table[: len(species), : len(species)], + index=species_idx, + columns=species_idx, ) df.to_csv( self.tablefilename diff --git a/reacnetgenerator/_path.py b/reacnetgenerator/_path.py index 8e6e57700..90a781284 100644 --- a/reacnetgenerator/_path.py +++ b/reacnetgenerator/_path.py @@ -258,13 +258,13 @@ def convertSMILES(self, atoms, bonds): ValueError (RDKit error) Maximum BFS search size exceeded. """ - m = Chem.RWMol(Chem.MolFromSmiles("")) # type: ignore + m = Chem.RWMol(Chem.MolFromSmiles("")) d = {} for name, number in zip(self.atomnames[atoms], atoms): - d[number] = m.AddAtom(Chem.Atom(name)) # type: ignore + d[number] = m.AddAtom(Chem.Atom(name)) for atom1, atom2, level in bonds: - m.AddBond(d[atom1], d[atom2], Chem.BondType(level)) # type: ignore - name = Chem.MolToSmiles(m) # type: ignore + m.AddBond(d[atom1], d[atom2], Chem.BondType(level)) + name = Chem.MolToSmiles(m) return self._re(name) def _getatomsandbonds(self, line): diff --git a/reacnetgenerator/py.typed b/reacnetgenerator/py.typed new file mode 100644 index 000000000..e69de29bb