Skip to content

Commit

Permalink
Scattered updated for Mypy 1.6
Browse files Browse the repository at this point in the history
  • Loading branch information
mattwthompson committed Oct 11, 2023
1 parent d296ade commit f96d210
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 48 deletions.
27 changes: 10 additions & 17 deletions openff/toolkit/topology/molecule.py
Original file line number Diff line number Diff line change
Expand Up @@ -2091,7 +2091,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
)
Expand Down Expand Up @@ -2703,16 +2703,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()
Expand Down Expand Up @@ -3159,18 +3157,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
Expand Down Expand Up @@ -3766,7 +3758,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"
Expand Down Expand Up @@ -5047,7 +5039,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
Expand All @@ -5056,8 +5048,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]:
Expand Down Expand Up @@ -5088,7 +5081,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.
Expand Down
6 changes: 3 additions & 3 deletions openff/toolkit/topology/topology.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)}.")

Expand Down
8 changes: 4 additions & 4 deletions openff/toolkit/typing/engines/smirnoff/forcefield.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
24 changes: 12 additions & 12 deletions openff/toolkit/typing/engines/smirnoff/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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(
Expand All @@ -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(
Expand All @@ -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(
Expand Down Expand Up @@ -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(
Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -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"
Expand All @@ -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(
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion openff/toolkit/utils/openeye_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion openff/toolkit/utils/rdkit_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
11 changes: 1 addition & 10 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

0 comments on commit f96d210

Please sign in to comment.