Skip to content

Commit

Permalink
Update some inherited method signatures flagged by mypy 1.11 (#1919)
Browse files Browse the repository at this point in the history
* update some method signatures that don't agree with inherited base class

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
j-wags and pre-commit-ci[bot] authored Aug 1, 2024
1 parent 1feb83d commit c036e7b
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 3 deletions.
5 changes: 5 additions & 0 deletions openff/toolkit/_tests/test_parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -856,6 +856,11 @@ def test_index(self):
with pytest.raises(ValueError, match="is not in list"):
parameters.index(p4)

with pytest.raises(TypeError, match="non-None values for start"):
parameters.index("[*:1]", start=1)
with pytest.raises(TypeError, match="non-None values for stop"):
parameters.index("[*:1]", stop=-1)

def test_index_duplicates(self):
"""Test ParameterList.index when multiple parameters have identical SMIRKS"""
p1 = ParameterType(smirks="[*:1]")
Expand Down
4 changes: 4 additions & 0 deletions openff/toolkit/_tests/test_utils_collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,10 @@ def is_positive(value):
d.update((("moe", 2), ("larry", 3), ("curly", -4)))
with pytest.raises(TypeError, match="value is not positive"):
d.update({"moe": 2, "larry": 3, "curly": -4})
with pytest.raises(TypeError, match="exactly one positional"):
d.update({"moe": 2}, {"larry": 3}, {"curly": -4})
with pytest.raises(TypeError, match="not accept named"):
d.update({"moe": 2}, moe=2, larry=3, curly=-4)

def test_converters(self):
"""Custom converters of ValidatedDict are called correctly."""
Expand Down
14 changes: 13 additions & 1 deletion openff/toolkit/typing/engines/smirnoff/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -1488,7 +1488,7 @@ def extend(self, other):
# TODO: Check if other ParameterList contains the same ParameterTypes?
super().extend(other)

def index(self, item):
def index(self, item, start=None, stop=None):
"""
Get the numerical index of a ParameterType object or SMIRKS in this ParameterList.
Raises ParameterLookupError if the item is not found.
Expand All @@ -1497,6 +1497,10 @@ def index(self, item):
----------
item
The parameter or SMIRKS to look up in this ParameterList
start
Unsupported, added to align method signature with list.index
stop
Unsupported, added to align method signature with list.index
Returns
-------
Expand All @@ -1508,6 +1512,14 @@ def index(self, item):
ParameterLookupError if SMIRKS pattern is passed in but not found
"""
if start is not None:
raise TypeError(
"ParameterList.index does not support non-None values for start."
)
if stop is not None:
raise TypeError(
"ParameterList.index does not support non-None values for stop."
)
if isinstance(item, ParameterType):
return super().index(item)
else:
Expand Down
12 changes: 10 additions & 2 deletions openff/toolkit/utils/collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,16 @@ def __init__(self, mapping, converter=None, validator=None):
mapping = self._convert_and_validate(mapping)
super().__init__(mapping)

def update(self, other):
other = self._convert_and_validate(dict(other))
def update(self, *args, **kwargs):
if len(args) != 1:
raise TypeError(
f"ValidatedDict.update expected exactly one positional argument, got {len(args)} instead."
)
if len(kwargs) != 0:
raise TypeError(
f"ValidatedDict.update does not accept named arguments, got {kwargs} instead."
)
other = self._convert_and_validate(dict(args[0]))
super().update(other)

def copy(self):
Expand Down

0 comments on commit c036e7b

Please sign in to comment.