Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unittest.case: Further stub improvements #8077

Merged
merged 10 commits into from
Jun 20, 2022
Merged

unittest.case: Further stub improvements #8077

merged 10 commits into from
Jun 20, 2022

Conversation

AlexWaygood
Copy link
Member

@AlexWaygood AlexWaygood commented Jun 14, 2022

Fixes several things I noticed while preparing #8066.

  • Use object instead of Any where literally any argument can be safely passed in.
  • Where the runtime uses assignments for method aliases, do the same thing in the stub.
  • Give a more precise type for assertGreater, assertLess, assertGreaterEqual and assertLessEqual.
  • Correct the outdated type for assert(Not)IsInstance.

stdlib/unittest/case.pyi Outdated Show resolved Hide resolved
stdlib/builtins.pyi Outdated Show resolved Hide resolved
@github-actions

This comment has been minimized.

1 similar comment
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

1 similar comment
@github-actions

This comment has been minimized.

@AlexWaygood
Copy link
Member Author

AlexWaygood commented Jun 14, 2022

Diff from mypy_primer, showing the effect of this PR on open source code:

tornado (https://github.com/tornadoweb/tornado)
+ tornado/test/httpclient_test.py:693: error: Argument 1 to "assertGreaterEqual" of "TestCase" has incompatible type "Optional[float]"; expected "Union[SupportsDunderGE, SupportsDunderLE]"
+ tornado/test/httpclient_test.py:694: error: Argument 1 to "assertLess" of "TestCase" has incompatible type "Optional[float]"; expected "Union[SupportsDunderLT, SupportsDunderGT]"

psycopg (https://github.com/psycopg/psycopg)
+ tests/test_psycopg_dbapi20.py:43: error: Unused "type: ignore" comment
+ tests/test_psycopg_dbapi20.py:44: error: Unused "type: ignore" comment

These all look good to me.

stdlib/unittest/case.pyi Outdated Show resolved Hide resolved
@github-actions

This comment has been minimized.

1 similar comment
@github-actions
Copy link
Contributor

Diff from mypy_primer, showing the effect of this PR on open source code:

poetry (https://github.com/python-poetry/poetry)
- src/poetry/packages/locker.py:316: error: Returning Any from function declared to return "Union[SupportsDunderLT, SupportsDunderGT]"  [no-any-return]
+ src/poetry/packages/locker.py:316: error: Returning Any from function declared to return "Union[SupportsDunderLT[Any], SupportsDunderGT[Any]]"  [no-any-return]
- src/poetry/packages/locker.py:508: error: Returning Any from function declared to return "Union[SupportsDunderLT, SupportsDunderGT]"  [no-any-return]
+ src/poetry/packages/locker.py:508: error: Returning Any from function declared to return "Union[SupportsDunderLT[Any], SupportsDunderGT[Any]]"  [no-any-return]
- src/poetry/puzzle/solver.py:138: error: Returning Any from function declared to return "Union[SupportsDunderLT, SupportsDunderGT]"  [no-any-return]
+ src/poetry/puzzle/solver.py:138: error: Returning Any from function declared to return "Union[SupportsDunderLT[Any], SupportsDunderGT[Any]]"  [no-any-return]
- src/poetry/console/commands/show.py:395: error: Returning Any from function declared to return "Union[SupportsDunderLT, SupportsDunderGT]"  [no-any-return]
+ src/poetry/console/commands/show.py:395: error: Returning Any from function declared to return "Union[SupportsDunderLT[Any], SupportsDunderGT[Any]]"  [no-any-return]
- src/poetry/console/commands/show.py:439: error: Returning Any from function declared to return "Union[SupportsDunderLT, SupportsDunderGT]"  [no-any-return]
+ src/poetry/console/commands/show.py:439: error: Returning Any from function declared to return "Union[SupportsDunderLT[Any], SupportsDunderGT[Any]]"  [no-any-return]

freqtrade (https://github.com/freqtrade/freqtrade)
- freqtrade/persistence/pairlock_middleware.py:90: error: Argument "key" to "sorted" has incompatible type "Callable[[PairLock], Column]"; expected "Callable[[PairLock], Union[SupportsDunderLT, SupportsDunderGT]]"
+ freqtrade/persistence/pairlock_middleware.py:90: error: Argument "key" to "sorted" has incompatible type "Callable[[PairLock], Column]"; expected "Callable[[PairLock], Union[SupportsDunderLT[Any], SupportsDunderGT[Any]]]"
- freqtrade/persistence/pairlock_middleware.py:90: error: Incompatible return value type (got "Column", expected "Union[SupportsDunderLT, SupportsDunderGT]")
+ freqtrade/persistence/pairlock_middleware.py:90: error: Incompatible return value type (got "Column", expected "Union[SupportsDunderLT[Any], SupportsDunderGT[Any]]")

core (https://github.com/home-assistant/core)
- homeassistant/components/zwave_js/device_condition.py:225: error: Returning Any from function declared to return "Union[SupportsDunderLT, SupportsDunderGT]"  [no-any-return]
+ homeassistant/components/zwave_js/device_condition.py:225: error: Returning Any from function declared to return "Union[SupportsDunderLT[Any], SupportsDunderGT[Any]]"  [no-any-return]
- homeassistant/components/zwave_js/device_action.py:330: error: Returning Any from function declared to return "Union[SupportsDunderLT, SupportsDunderGT]"  [no-any-return]
+ homeassistant/components/zwave_js/device_action.py:330: error: Returning Any from function declared to return "Union[SupportsDunderLT[Any], SupportsDunderGT[Any]]"  [no-any-return]
- homeassistant/components/zwave_js/device_trigger.py:538: error: Returning Any from function declared to return "Union[SupportsDunderLT, SupportsDunderGT]"  [no-any-return]
+ homeassistant/components/zwave_js/device_trigger.py:538: error: Returning Any from function declared to return "Union[SupportsDunderLT[Any], SupportsDunderGT[Any]]"  [no-any-return]

tornado (https://github.com/tornadoweb/tornado)
+ tornado/test/httpclient_test.py:693: error: Argument 1 to "assertGreaterEqual" of "TestCase" has incompatible type "Optional[float]"; expected "SupportsDunderGE[int]"
+ tornado/test/httpclient_test.py:694: error: Argument 1 to "assertLess" of "TestCase" has incompatible type "Optional[float]"; expected "SupportsDunderLT[float]"

streamlit (https://github.com/streamlit/streamlit)
- lib/tests/streamlit/watcher/local_sources_watcher_test.py:375:47: error: Returning Any from function declared to return "Union[SupportsDunderLT, SupportsDunderGT]"  [no-any-return]
+ lib/tests/streamlit/watcher/local_sources_watcher_test.py:375:47: error: Returning Any from function declared to return "Union[SupportsDunderLT[Any], SupportsDunderGT[Any]]"  [no-any-return]

paasta (https://github.com/yelp/paasta)
- paasta_tools/metrics/metastatus_lib.py:672: error: Argument "key" to "sorted" has incompatible type "Callable[[Any], Sequence[Tuple[str, str]]]"; expected "Callable[[_SlaveT], Union[SupportsDunderLT, SupportsDunderGT]]"
+ paasta_tools/metrics/metastatus_lib.py:672: error: Argument "key" to "sorted" has incompatible type "Callable[[Any], Sequence[Tuple[str, str]]]"; expected "Callable[[_SlaveT], Union[SupportsDunderLT[Any], SupportsDunderGT[Any]]]"
- paasta_tools/metrics/metastatus_lib.py:672: error: Argument "key" to "sorted" has incompatible type "Callable[[Any], Sequence[Tuple[str, str]]]"; expected "Callable[[Any], Union[SupportsDunderLT, SupportsDunderGT]]"
+ paasta_tools/metrics/metastatus_lib.py:672: error: Argument "key" to "sorted" has incompatible type "Callable[[Any], Sequence[Tuple[str, str]]]"; expected "Callable[[Any], Union[SupportsDunderLT[Any], SupportsDunderGT[Any]]]"

psycopg (https://github.com/psycopg/psycopg)
+ tests/test_psycopg_dbapi20.py:43: error: Unused "type: ignore" comment
+ tests/test_psycopg_dbapi20.py:44: error: Unused "type: ignore" comment

@srittau
Copy link
Collaborator

srittau commented Jun 20, 2022

Thanks!

@srittau srittau merged commit 538621e into master Jun 20, 2022
@srittau srittau deleted the unittest branch June 20, 2022 16:49
DMRobertson pushed a commit to matrix-org/synapse that referenced this pull request Sep 28, 2022
DMRobertson pushed a commit to matrix-org/synapse that referenced this pull request Sep 30, 2022
DMRobertson pushed a commit to matrix-org/synapse that referenced this pull request Sep 30, 2022
* Update mypy and mypy-zope

* Unignore assigning to LogRecord attributes

Presumably python/typeshed#8064 makes this ok

Cherry-picked from #13521

* Remove unused ignores due to mypy ParamSpec fixes

python/mypy#12668

Cherry-picked from #13521

* Remove additional unused ignores

* Fix new mypy complaints related to `assertGreater`

Presumably due to python/typeshed#8077

* Changelog

* Reword changelog

Co-authored-by: Patrick Cloke <clokep@users.noreply.github.com>

Co-authored-by: Patrick Cloke <clokep@users.noreply.github.com>
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.

2 participants