Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.7k
gh-104050: Run mypy onclinic.py in CI#104421
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
ca8532bd2ec2ef801af3800183ff4bdd409632843bf7e7a25510e08b773c2ba6c7ecb9717ee4762669d1ddd0843b7158db9fcd87f010f0ddFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| # Workflow to run mypy on select parts of the CPython repo | ||
| name: mypy | ||
| on: | ||
| push: | ||
| branches: | ||
| - main | ||
| pull_request: | ||
| paths: | ||
| - "Tools/clinic/**" | ||
| - ".github/workflows/mypy.yml" | ||
| workflow_dispatch: | ||
| permissions: | ||
| contents: read | ||
| env: | ||
| PIP_DISABLE_PIP_VERSION_CHECK: 1 | ||
| FORCE_COLOR: 1 | ||
| TERM: xterm-256color # needed for FORCE_COLOR to work on mypy on Ubuntu, see https://github.com/python/mypy/issues/13817 | ||
| concurrency: | ||
| group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} | ||
| cancel-in-progress: true | ||
| jobs: | ||
| mypy: | ||
| name: Run mypy on Tools/clinic/ | ||
| runs-on: ubuntu-latest | ||
| timeout-minutes: 10 | ||
| steps: | ||
| - uses: actions/checkout@v3 | ||
| - uses: actions/setup-python@v4 | ||
| with: | ||
| python-version: "3.x" | ||
| cache: pip | ||
| cache-dependency-path: Tools/clinic/requirements-dev.txt | ||
| - run: pip install -r Tools/clinic/requirements-dev.txt | ||
| - run: mypy --config-file Tools/clinic/mypy.ini |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -7,6 +7,7 @@ | ||
| import abc | ||
| import ast | ||
| import builtins as bltns | ||
| import collections | ||
| import contextlib | ||
| import copy | ||
| @@ -26,7 +27,9 @@ | ||
| import traceback | ||
| import types | ||
| from collections.abc import Callable | ||
| from types import * | ||
hugovk marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| from typing import Any, NamedTuple | ||
| # TODO: | ||
| # | ||
| @@ -78,19 +81,26 @@ def __repr__(self): | ||
| sig_end_marker = '--' | ||
| Appender = Callable[[str], None] | ||
AlexWaygood marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| Outputter = Callable[[None], str] | ||
| class _TextAccumulator(NamedTuple): | ||
| text: list[str] | ||
| append: Appender | ||
| output: Outputter | ||
| def _text_accumulator(): | ||
| text = [] | ||
| def output(): | ||
| s = ''.join(text) | ||
| text.clear() | ||
| return s | ||
| return_TextAccumulator(text, text.append, output) | ||
| class TextAccumulator(NamedTuple): | ||
AlexWaygood marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| text: list[str] | ||
| append: Appender | ||
| def text_accumulator(): | ||
| """ | ||
| @@ -104,7 +114,7 @@ def text_accumulator(): | ||
| empties the accumulator. | ||
| """ | ||
| text, append, output = _text_accumulator() | ||
| returnTextAccumulator(append, output) | ||
| def warn_or_fail(fail=False, *args, filename=None, line_number=None): | ||
| @@ -1925,8 +1935,10 @@ def dump(self): | ||
| # maps strings to Language objects. | ||
| # "languages" maps the name of the language ("C", "Python"). | ||
| # "extensions" maps the file extension ("c", "py"). | ||
| LangDict = dict[str, Callable[[str], Language]] | ||
| languages = { 'C': CLanguage, 'Python': PythonLanguage } | ||
| extensions: LangDict = { name: CLanguage for name in "c cc cpp cxx h hh hpp hxx".split() } | ||
| extensions['py'] = PythonLanguage | ||
| @@ -2558,15 +2570,15 @@ class CConverter(metaclass=CConverterAutoRegister): | ||
| """ | ||
| # The C name to use for this variable. | ||
| name: str | None = None | ||
Contributor
| ||
| # The Python name to use for this variable. | ||
| py_name: str | None = None | ||
| # The C type to use for this variable. | ||
| # 'type' should be a Python string specifying the type, e.g. "int". | ||
| # If this is a pointer type, the type string should end with ' *'. | ||
| type: str | None = None | ||
| # The Python default value for this parameter, as a Python value. | ||
| # Or the magic value "unspecified" if there is no default. | ||
| @@ -2577,15 +2589,15 @@ class CConverter(metaclass=CConverterAutoRegister): | ||
| # If not None, default must be isinstance() of this type. | ||
| # (You can also specify a tuple of types.) | ||
| default_type: bltns.type[Any] | tuple[bltns.type[Any], ...] | None = None | ||
| # "default" converted into a C value, as a string. | ||
| # Or None if there is no default. | ||
| c_default: str | None = None | ||
| # "default" converted into a Python value, as a string. | ||
| # Or None if there is no default. | ||
| py_default: str | None = None | ||
| # The default value used to initialize the C variable when | ||
| # there is no default, but not specifying a default may | ||
| @@ -2597,14 +2609,14 @@ class CConverter(metaclass=CConverterAutoRegister): | ||
| # | ||
| # This value is specified as a string. | ||
| # Every non-abstract subclass should supply a valid value. | ||
| c_ignored_default: str = 'NULL' | ||
| # If true, wrap with Py_UNUSED. | ||
| unused = False | ||
| # The C converter *function* to be used, if any. | ||
| # (If this is not None, format_unit must be 'O&'.) | ||
| converter: str | None = None | ||
| # Should Argument Clinic add a '&' before the name of | ||
| # the variable when passing it into the _impl function? | ||
| @@ -3432,7 +3444,7 @@ class robuffer: pass | ||
| def str_converter_key(types, encoding, zeroes): | ||
| return (frozenset(types), bool(encoding), bool(zeroes)) | ||
| str_converter_argument_map: dict[str, str] = {} | ||
| class str_converter(CConverter): | ||
| type = 'const char *' | ||
MemberAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. I usually put my mypy config in a |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| [mypy] | ||
| # make sure clinic can still be run on Python 3.10 | ||
AlexWaygood marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| python_version = 3.10 | ||
| pretty = True | ||
| enable_error_code = ignore-without-code | ||
| disallow_any_generics = True | ||
| strict_concatenate = True | ||
| warn_redundant_casts = True | ||
| warn_unused_ignores = True | ||
| warn_unused_configs = True | ||
| files = Tools/clinic/ | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| # Requirements file for external linters and checks we run on Tools/clinic/ in CI | ||
| mypy==1.2.0 | ||
MemberAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. We're deliberately pinning to an older version here, in order to test that dependabot updates are working on this file, as per@hugovk's suggestion in#104421 (comment) | ||