Skip to content

Commit

Permalink
Fix some new-MyPy typing lints.
Browse files Browse the repository at this point in the history
In one case MyPy got smarter in a way we hoped it one, while in two
others it started complaining differently about a case where we were
deliberately playing fast and loose with types.
  • Loading branch information
TallJimbo committed Nov 10, 2023
1 parent 05cef86 commit 78ba1f0
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
4 changes: 2 additions & 2 deletions python/lsst/daf/butler/_named.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ def freeze(self) -> NamedKeyMapping[K, V]:
to a new variable (and considering any previous references
invalidated) should allow for more accurate static type checking.
"""
if not isinstance(self._dict, MappingProxyType):
if not isinstance(self._dict, MappingProxyType): # type: ignore
self._dict = MappingProxyType(self._dict) # type: ignore
return self

Expand Down Expand Up @@ -592,7 +592,7 @@ def freeze(self) -> NamedValueAbstractSet[K]:
to a new variable (and considering any previous references
invalidated) should allow for more accurate static type checking.
"""
if not isinstance(self._mapping, MappingProxyType):
if not isinstance(self._mapping, MappingProxyType): # type: ignore
self._mapping = MappingProxyType(self._mapping) # type: ignore
return self

Expand Down
8 changes: 3 additions & 5 deletions python/lsst/daf/butler/persistence_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import uuid
from collections.abc import Callable, Hashable
from contextvars import Context, ContextVar, Token, copy_context
from typing import TYPE_CHECKING, ParamSpec, TypeVar, cast
from typing import TYPE_CHECKING, ParamSpec, TypeVar

if TYPE_CHECKING:
from ._dataset_ref import DatasetRef
Expand Down Expand Up @@ -194,8 +194,6 @@ def run(self, function: Callable[_Q, _T], *args: _Q.args, **kwargs: _Q.kwargs) -
"""
self._ctx = copy_context()
# Type checkers seem to have trouble with a second layer nesting of
# parameter specs in callables, so ignore the call here and explicitly
# cast the result as we know this is exactly what the return type will
# be.
# parameter specs in callables, so ignore the call here.
result = self._ctx.run(self._functionRunner, function, *args, **kwargs) # type: ignore
return cast(_T, result)
return result

Check warning on line 199 in python/lsst/daf/butler/persistence_context.py

View check run for this annotation

Codecov / codecov/patch

python/lsst/daf/butler/persistence_context.py#L199

Added line #L199 was not covered by tests

0 comments on commit 78ba1f0

Please sign in to comment.