Skip to content

Conversation

@JukkaL
Copy link
Contributor

@JukkaL JukkaL commented Nov 22, 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 python/mypy#11572. I encountered the issue in several
places when testing recent typeshed against an internal repo.

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.
@github-actions
Copy link
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 JukkaL merged commit 25649bc into python:master Nov 22, 2021
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.
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.

3 participants