Add getattr overload variants to help mypy type inference#6355
Merged
JukkaL merged 1 commit intopython:masterfrom Nov 22, 2021
Merged
Add getattr overload variants to help mypy type inference#6355JukkaL merged 1 commit intopython:masterfrom
JukkaL merged 1 commit intopython:masterfrom
Conversation
These silence errors about missing type annotations for calls
like these:
```
x = getattr(o, 'a', [])
y = getattr(o, 'b', {})
```
This is a generalization of python#5518.
srittau
approved these changes
Nov 22, 2021
ilevkivskyi
approved these changes
Nov 22, 2021
Contributor
|
Diff from mypy_primer, showing the effect of this PR on open source code: paasta (https://github.com/yelp/paasta.git)
- paasta_tools/kubernetes_tools.py:2106: error: Need type annotation for "stream_lines"
sphinx (https://github.com/sphinx-doc/sphinx.git)
- sphinx/util/requests.py: note: In function "is_ssl_error":
- sphinx/util/requests.py:54:16: error: Need type annotation for "args"
- sphinx/ext/napoleon/docstring.py: note: In member "_lookup_annotation" of class "GoogleDocstring":
- sphinx/ext/napoleon/docstring.py:864:31: error: Need type annotation for "localns"
- sphinx/ext/viewcode.py: note: In function "env_purge_doc":
- sphinx/ext/viewcode.py:161:15: error: Need type annotation for "modules"
flake8 (https://github.com/pycqa/flake8.git)
- src/flake8/plugins/manager.py:508: error: Need type annotation for "plugins"
- src/flake8/plugins/manager.py:517: error: Need type annotation for "plugins"
- src/flake8/plugins/manager.py:526: error: Need type annotation for "plugins"
pandas (https://github.com/pandas-dev/pandas.git)
- pandas/io/stata.py:2598: error: Need type annotation for "convert_strl" [var-annotated]
pylint (https://github.com/pycqa/pylint.git)
- pylint/pyreverse/inspector.py:184: error: Need type annotation for "specializations" [var-annotated]
- pylint/checkers/variables.py:1781: error: Need type annotation for "elements" [var-annotated]
- pylint/checkers/typecheck.py:1378: error: Need type annotation for "already_filled_keywords" [var-annotated]
freqtrade (https://github.com/freqtrade/freqtrade.git)
- freqtrade/strategy/informative_decorator.py:56: error: Need type annotation for "informative_pairs"
pytest (https://github.com/pytest-dev/pytest.git)
- src/_pytest/mark/structures.py:365: error: Need type annotation for "mark_list" [var-annotated]
- src/_pytest/fixtures.py:1323: note: (Skipping most remaining errors due to unresolved imports or missing stubs; fix these first)
+ src/_pytest/fixtures.py:1323: error: Unexpected keyword argument "params" for "FixtureFunctionMarker" [call-arg]
werkzeug (https://github.com/pallets/werkzeug.git)
- src/werkzeug/local.py:123: error: Need type annotation for "rv"
+ tests/test_wrappers.py:833: note: Use "-> None" if function does not return a value
- tests/test_wrappers.py:833: note: (Skipping most remaining errors due to unresolved imports or missing stubs; fix these first)
+ tests/test_wrappers.py:856: note: (Skipping most remaining errors due to unresolved imports or missing stubs; fix these first)
edgedb (https://github.com/edgedb/edgedb.git)
- edb/common/parametric.py:150:36: error: Need type annotation for "base_non_type_params"
- edb/edgeql/declarative.py:919:23: error: Need type annotation for "ast_subcommands"
- edb/pgsql/compiler/relctx.py:94:28: error: Need type annotation for "view_path_id_map"
- edb/server/connpool/pool.py:526:16: error: No overload variant of "get" of "Mapping" matches argument type "str"
- edb/server/connpool/pool.py:526:16: note: Possible overload variant:
- edb/server/connpool/pool.py:526:16: note: def get(self, key: <nothing>) -> None
- edb/server/connpool/pool.py:526:16: note: <1 more non-matching overload not shown>
pyppeteer (https://github.com/pyppeteer/pyppeteer.git)
- pyppeteer/network_manager.py:157: error: No overload variant of "get" of "Mapping" matches argument type "str"
- pyppeteer/network_manager.py:157: note: Possible overload variant:
- pyppeteer/network_manager.py:157: note: def get(self, key: <nothing>) -> None
- pyppeteer/network_manager.py:157: note: <1 more non-matching overload not shown>
- pyppeteer/network_manager.py:158: error: No overload variant of "get" of "Mapping" matches argument type "str"
- pyppeteer/network_manager.py:158: note: Possible overload variant:
- pyppeteer/network_manager.py:158: note: def get(self, key: <nothing>) -> None
- pyppeteer/network_manager.py:158: note: <1 more non-matching overload not shown>
|
JukkaL
added a commit
to python/mypy
that referenced
this pull request
Nov 23, 2021
These silence errors about missing type annotations for calls
like these:
```
x = getattr(o, 'a', [])
y = getattr(o, 'b', {})
```
This is basically a generalization of #5518 and other overloads we already
have.
This works around #11572. I encountered the issue in several
places when testing recent typeshed against an internal repo.
Manually cherry-picked from python/typeshed#6355.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
These silence errors about missing type annotations for calls
like these:
This is basically a generalization of #5518 and other overloads we already
have.
This works around python/mypy#11572. I encountered the issue in several
places when testing recent typeshed against an internal repo.