Repository navigation
Update mypy to 2.4.0 - #16502
Update mypy to 2.4.0#16502
Conversation
Add date.__rsub__ Add allowlist entries
This comment has been minimized.
This comment has been minimized.
Fix str.__mod__ argument (Any -> object)
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
This was more complicated than expected, but finally ready for a final review. |
| # The following reverse operators are present in the C implementation | ||
| # (probably incidental), but missing from the Python implementation. |
There was a problem hiding this comment.
I would still personally lean towards just following the C implementation here, since it's the only one that will be relevant to the vast majority of type-checker users. And I think that's what we've done elsewhere in a few other places. But don't feel strongly; this is fine for now. And as you say, these aren't particularly useful, so it probably just doesn't really matter for users.
There was a problem hiding this comment.
I prefer to support only what's supported by both versions.
| @overload | ||
| def __rand__(self, value: set[_S], /) -> set[_S]: ... | ||
| @overload | ||
| def __rand__(self, value: frozenset[_S], /) -> frozenset[_S]: ... |
There was a problem hiding this comment.
not an issue to be fixed in this PR, but we might want to revisit the annotations for set.__and__. They look incorrect -- it doesn't seem like set.__and__ really takes any abstract set for its second argument. It seems like it might also only take sets and frozensets, similar to set.__rand__:
>>> from collections.abc import Set
>>> class Foo(Set):
... __contains__ = __iter__ = __len__ = lambda *args: ...
...
>>> {1, 2}.__and__(Foo())
NotImplementedPossibly the same also goes for other set dunders?
There was a problem hiding this comment.
I'll actually fix this here, since I've also fixed a few other dunder annotations.
Similar to the other builtins, set checks explicitly for set or frozenset (or derived classes) using PyAnySet_Check:
static PyObject *
set_and(PyObject *self, PyObject *other)
{
if (!PyAnySet_Check(self) || !PyAnySet_Check(other))
Py_RETURN_NOTIMPLEMENTED;
/* ... */
}| @@ -1490,9 +1518,33 @@ class frozenset(AbstractSet[_T_co]): | |||
| def __contains__(self, o: object, /) -> bool: ... | |||
| def __iter__(self) -> Iterator[_T_co]: ... | |||
| def __and__(self, value: AbstractSet[object], /) -> frozenset[_T_co]: ... | |||
There was a problem hiding this comment.
I think the nonreflected frozenset dunders have the same issue:
>>> from collections.abc import Set
>>> class Foo(Set):
... __contains__ = __iter__ = __len__ = lambda *args: ...
...
>>> frozenset({1, 2}).__and__(Foo())
NotImplementedThere was a problem hiding this comment.
Good catch, they would have.
There was a problem hiding this comment.
That said, I'm going to revert the last two commits for now and commit. This seems to open a whole new can of worms.
This comment has been minimized.
This comment has been minimized.
|
Diff from mypy_primer, showing the effect of this PR on open source code: scipy-stubs (https://github.com/scipy/scipy-stubs)
- tests/misc/test_submodules_empty.pyi:3: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
|
No description provided.