Skip to content

Conversation

donBarbos
Copy link
Contributor

Closes: #14701

@brianschubert
Copy link
Member

Another approach suggested by @srittau is having _ANY inherit from Any (#14701 (comment)). Any thoughts on which approach is preferable?

This comment has been minimized.

Copy link
Collaborator

@hauntsaninja hauntsaninja left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Open to exploring subclass with Any! Might be better, but only real world code examples I can think of where it matters are a little contrived.

@@ -513,7 +513,8 @@ class _ANY:
def __ne__(self, other: object) -> Literal[False]: ...
__hash__: ClassVar[None] # type: ignore[assignment]

ANY: _ANY
# See https://github.com/python/typeshed/issues/14701
ANY: Any
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need class _Any above?

@tungol
Copy link
Contributor

tungol commented Sep 14, 2025

if it's a working solution, I think a subclass of Any is preferable, given that:

>>> type(ANY)
<class 'unittest.mock._ANY'>

This comment has been minimized.

@srittau
Copy link
Collaborator

srittau commented Sep 14, 2025

LGTM, although we could add some tests to ensure that the problem mentioned in #14701 is fixed. Also, the example from the docs seems worthwhile to add as a test.

@brianschubert brianschubert changed the title [unittest] Revert mock.ANY changes Make type of unitest.mock.Any a subclass of Any Sep 14, 2025
I think this is my first attempt at writing type tests, don't judge

This comment has been minimized.

Copy link
Contributor

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

@srittau srittau merged commit 0d100b9 into python:main Sep 14, 2025
63 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Changes to unittest.mock.ANY make it harder to use
6 participants