Skip to content

unittest.case: Further stub improvements - #8077

Merged
srittau merged 10 commits into
masterfrom
unittest
Jun 20, 2022
Merged

unittest.case: Further stub improvements#8077
srittau merged 10 commits into
masterfrom
unittest

Conversation

@AlexWaygood

@AlexWaygoodAlexWaygood commented Jun 14, 2022

Copy link
Copy Markdown
Member

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.

Comment threadstdlib/unittest/case.pyi Outdated
Comment threadstdlib/builtins.pyi Outdated
@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

AlexWaygood commented Jun 14, 2022

Copy link
Copy Markdown
MemberAuthor

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.

Comment threadstdlib/unittest/case.pyi Outdated
@github-actions

This comment has been minimized.

1 similar comment
@github-actions

Copy link
Copy Markdown
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
Copy Markdown
Collaborator

Thanks!

@srittau
srittau merged commit 538621e into masterJun 20, 2022
@srittau
srittau deleted the unittest branch June 20, 2022 16:49
@hauntsaninjahauntsaninja mentioned this pull request Jul 8, 2022
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 fixespython/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 freeto 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

@AlexWaygood@srittau