diff --git a/docs/releasehistory.md b/docs/releasehistory.md index 3400b4ca1..248b5b1f1 100644 --- a/docs/releasehistory.md +++ b/docs/releasehistory.md @@ -14,14 +14,15 @@ Releases follow the `major.minor.micro` scheme recommended by [PEP440](https://w ### Bugfixes +- [PR #1740](https://github.com/openforcefield/openff-toolkit/pull/1740): Updates for Mypy 1.6. + ### New features -### Improved documentation and warnings +- [PR #1731](https://github.com/openforcefield/openff-toolkit/pull/1731): Suppot SMIRNOFF vdW version 0.5. -## Current development +### Improved documentation and warnings - [PR #1747](https://github.com/openforcefield/openff-toolkit/pull/1747): Warns if a SMILES with full atom mappings is passed to `Moleucle.from_smiles`, which does not use the atom map for atom ordering (`Molecule.from_mapped_smiles` does). -- [PR #1731](https://github.com/openforcefield/openff-toolkit/pull/1731): Suppot SMIRNOFF vdW version 0.5. ## 0.14.4 diff --git a/openff/toolkit/topology/molecule.py b/openff/toolkit/topology/molecule.py index 30ed926a7..a59b292ab 100644 --- a/openff/toolkit/topology/molecule.py +++ b/openff/toolkit/topology/molecule.py @@ -2103,7 +2103,7 @@ def to_networkx(data: Union[FrozenMolecule, nx.Graph]) -> nx.Graph: # Molecule class instance if strip_pyrimidal_n_atom_stereo: # Make a copy of the molecule so we don't modify the original - data: FrozenMolecule = deepcopy(data) + data = deepcopy(data) data.strip_atom_stereochemistry( SMARTS, toolkit_registry=toolkit_registry ) @@ -2715,16 +2715,14 @@ def assign_fractional_bond_orders( f"Expected ToolkitRegistry or ToolkitWrapper. Got {type(toolkit_registry)}." ) - def _invalidate_cached_properties(self): + def _invalidate_cached_properties(self) -> None: """ Indicate that the chemical entity has been altered. """ - # if hasattr(self, '_cached_properties'): - # delattr(self, '_cached_properties') self._conformers = None self._partial_charges = None - self._propers = None - self._impropers = None + self._propers: set[tuple[Atom, Atom, Atom, Atom]] = set() + self._impropers: set[tuple[Atom, Atom, Atom, Atom]] = set() self._hill_formula = None self._cached_smiles = dict() @@ -3171,18 +3169,12 @@ def n_angles(self) -> int: def n_propers(self) -> int: """Number of proper torsions in the molecule.""" self._construct_torsions() - assert ( - self._propers is not None - ), "_construct_torsions always sets _propers to a set" return len(self._propers) @property def n_impropers(self) -> int: """Number of possible improper torsions in the molecule.""" self._construct_torsions() - assert ( - self._impropers is not None - ), "_construct_torsions always sets _impropers to a set" return len(self._impropers) @property @@ -3778,7 +3770,7 @@ def from_file( if file_format is None: if isinstance(file_path, pathlib.Path): - file_path: str = file_path.as_posix() + file_path: str = file_path.as_posix() # type: ignore[no-redef] if not isinstance(file_path, str): raise ValueError( "If providing a file-like object for reading molecules, the format must be specified" @@ -5065,7 +5057,7 @@ def _construct_angles(self): else: self._angles.add((atom3, atom2, atom1)) - def _construct_torsions(self): + def _construct_torsions(self) -> None: """ Construct sets containing the atoms improper and proper torsions @@ -5074,8 +5066,9 @@ def _construct_torsions(self): if not hasattr(self, "_torsions"): self._construct_bonded_atoms_list() - self._propers: set[tuple[Atom]] = set() - self._impropers: set[tuple[Atom]] = set() + self._propers = set() + self._impropers = set() + for atom1 in self._atoms: for atom2 in self._bonded_atoms[atom1]: for atom3 in self._bonded_atoms[atom2]: @@ -5106,7 +5099,7 @@ def _construct_torsions(self): self._torsions = self._propers | self._impropers - def _construct_bonded_atoms_list(self): + def _construct_bonded_atoms_list(self) -> None: """ Construct list of all atoms each atom is bonded to. diff --git a/openff/toolkit/topology/topology.py b/openff/toolkit/topology/topology.py index 19d243bb7..6175c9a8c 100644 --- a/openff/toolkit/topology/topology.py +++ b/openff/toolkit/topology/topology.py @@ -2011,13 +2011,13 @@ def to_file( # Get positions in OpenMM format if isinstance(positions, openmm.unit.Quantity): - openmm_positions = positions + openmm_positions: openmm.unit.Quantity = positions elif isinstance(positions, Quantity): - openmm_positions: openmm.unit.Quantity = positions.to_openmm() + openmm_positions = positions.to_openmm() elif isinstance(positions, np.ndarray): openmm_positions = openmm.unit.Quantity(positions, openmm.unit.angstroms) elif positions is None: - openmm_positions: openmm.unit.Quantity = self.get_positions().to_openmm() # type: ignore[union-attr] + openmm_positions = self.get_positions().to_openmm() # type: ignore[union-attr] else: raise ValueError(f"Could not process positions of type {type(positions)}.") diff --git a/openff/toolkit/typing/engines/smirnoff/forcefield.py b/openff/toolkit/typing/engines/smirnoff/forcefield.py index 13a407fed..4e43e327f 100644 --- a/openff/toolkit/typing/engines/smirnoff/forcefield.py +++ b/openff/toolkit/typing/engines/smirnoff/forcefield.py @@ -224,12 +224,12 @@ class ForceField: def __init__( self, *sources, - aromaticity_model=DEFAULT_AROMATICITY_MODEL, + aromaticity_model: str = DEFAULT_AROMATICITY_MODEL, parameter_handler_classes=None, parameter_io_handler_classes=None, - disable_version_check=False, - allow_cosmetic_attributes=False, - load_plugins=False, + disable_version_check: bool = False, + allow_cosmetic_attributes: bool = False, + load_plugins: bool = False, ): """Create a new :class:`ForceField` object from one or more SMIRNOFF parameter definition files. diff --git a/openff/toolkit/typing/engines/smirnoff/parameters.py b/openff/toolkit/typing/engines/smirnoff/parameters.py index 7dd7a4897..231409b4f 100644 --- a/openff/toolkit/typing/engines/smirnoff/parameters.py +++ b/openff/toolkit/typing/engines/smirnoff/parameters.py @@ -1794,7 +1794,7 @@ class ParameterHandler(_ParameterAttributeHandler): version = ParameterAttribute() - @version.converter + @version.converter # type: ignore[no-redef] def version(self, attr, new_version): """ Raise a parsing exception if the given section version is unsupported. @@ -2855,7 +2855,7 @@ def __init__(self, **kwargs): # TODO: Use _allow_only when ParameterAttribute will support multiple converters # (it'll be easy when we switch to use the attrs library) - @scale12.converter + @scale12.converter # type: ignore[no-redef] def scale12(self, attrs, new_scale12): if new_scale12 != 0.0: raise SMIRNOFFSpecError( @@ -2864,7 +2864,7 @@ def scale12(self, attrs, new_scale12): ) return new_scale12 - @scale13.converter + @scale13.converter # type: ignore[no-redef] def scale13(self, attrs, new_scale13): if new_scale13 != 0.0: raise SMIRNOFFSpecError( @@ -2873,7 +2873,7 @@ def scale13(self, attrs, new_scale13): ) return new_scale13 - @scale15.converter + @scale15.converter # type: ignore[no-redef] def scale15(self, attrs, new_scale15): if new_scale15 != 1.0: raise SMIRNOFFSpecError( @@ -2963,7 +2963,7 @@ class ElectrostaticsHandler(_NonbondedHandler): # TODO: Use _allow_only when ParameterAttribute will support multiple converters # (it'll be easy when we switch to use the attrs library) - @scale12.converter + @scale12.converter # type: ignore[no-redef] def scale12(self, attrs, new_scale12): if new_scale12 != 0.0: raise SMIRNOFFSpecError( @@ -2972,7 +2972,7 @@ def scale12(self, attrs, new_scale12): ) return new_scale12 - @scale13.converter + @scale13.converter # type: ignore[no-redef] def scale13(self, attrs, new_scale13): if new_scale13 != 0.0: raise SMIRNOFFSpecError( @@ -2981,7 +2981,7 @@ def scale13(self, attrs, new_scale13): ) return new_scale13 - @scale15.converter + @scale15.converter # type: ignore[no-redef] def scale15(self, attrs, new_scale15): if new_scale15 != 1.0: raise SMIRNOFFSpecError( @@ -2990,7 +2990,7 @@ def scale15(self, attrs, new_scale15): ) return new_scale15 - @switch_width.converter + @switch_width.converter # type: ignore[no-redef] def switch_width(self, attr, new_switch_width): if new_switch_width not in [0.0 * unit.angstrom, None, "None", "none"]: raise SMIRNOFFSpecUnimplementedError( @@ -3000,7 +3000,7 @@ def switch_width(self, attr, new_switch_width): "important to you, please raise an issue at https://github.com/openforcefield/openff-toolkit/issues." ) - @periodic_potential.converter + @periodic_potential.converter # type: ignore[no-redef] def periodic_potential(self, attr, new_value): if new_value in ["PME", "Ewald3D-ConductingBoundary"]: return "Ewald3D-ConductingBoundary" @@ -3013,7 +3013,7 @@ def periodic_potential(self, attr, new_value): "Failed to process unexpected periodic potential value: {new_value}" ) - @solvent_dielectric.converter + @solvent_dielectric.converter # type: ignore[no-redef] def solvent_dielectric(self, attr, new_value): if new_value is not None: raise SMIRNOFFSpecUnimplementedError( @@ -3440,7 +3440,7 @@ def type_to_parent_index(cls, type_: _VirtualSiteType) -> int: raise NotImplementedError() - @outOfPlaneAngle.converter + @outOfPlaneAngle.converter # type: ignore[no-redef] def outOfPlaneAngle(self, attr, value): if value == "None": return @@ -3456,7 +3456,7 @@ def outOfPlaneAngle(self, attr, value): return value - @inPlaneAngle.converter + @inPlaneAngle.converter # type: ignore[no-redef] def inPlaneAngle(self, attr, value): if value == "None": return diff --git a/openff/toolkit/utils/openeye_wrapper.py b/openff/toolkit/utils/openeye_wrapper.py index 24574e0a9..dc618c431 100644 --- a/openff/toolkit/utils/openeye_wrapper.py +++ b/openff/toolkit/utils/openeye_wrapper.py @@ -472,7 +472,7 @@ def from_file( from openeye import oechem if isinstance(file_path, pathlib.Path): - file_path: str = file_path.as_posix() + file_path: str = file_path.as_posix() # type: ignore[no-redef] oeformat = get_oeformat(file_format) ifs = oechem.oemolistream(file_path) diff --git a/openff/toolkit/utils/rdkit_wrapper.py b/openff/toolkit/utils/rdkit_wrapper.py index 46ead2c06..4e2fb3b2c 100644 --- a/openff/toolkit/utils/rdkit_wrapper.py +++ b/openff/toolkit/utils/rdkit_wrapper.py @@ -1065,7 +1065,7 @@ def from_file( from rdkit import Chem if isinstance(file_path, pathlib.Path): - file_path: str = file_path.as_posix() + file_path: str = file_path.as_posix() # type: ignore[no-redef] file_format = normalize_file_format(file_format) diff --git a/setup.cfg b/setup.cfg index 7569d9ec5..76ad4517e 100644 --- a/setup.cfg +++ b/setup.cfg @@ -76,7 +76,7 @@ parentdir_prefix = openff-toolkit- plugins = numpy.typing.mypy_plugin warn_unused_configs = True show_error_codes = True -disable_error_code = no-redef +exclude = openff/toolkit/_tests/ [mypy-openff.units] ignore_missing_imports = True @@ -174,14 +174,5 @@ ignore_missing_imports = True [mypy-CifFile] ignore_missing_imports = True -[mypy-mendeleev] -ignore_missing_imports = True - -[mypy-mendeleev.models] -ignore_missing_imports = True - -[mypy-mendeleev.fetch] -ignore_missing_imports = True - [mypy-constraint] ignore_missing_imports = True