8000 gh-104050: Run mypy on `clinic.py` in CI by AlexWaygood · Pull Request #104421 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-104050: Run mypy on clinic.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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
May 15, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Make the type check pass
  • Loading branch information
AlexWaygood committed May 12, 2023
commit 4bdd409fc64f3a584128e0828fad1108f8aa43b4
7 changes: 3 additions & 4 deletions Tools/clinic/clinic.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

from collections.abc import Callable
from types import *
from typing import NamedTuple, TypeVar, Type
from typing import Any, NamedTuple, Type

# TODO:
#
Expand Down Expand Up @@ -1924,8 +1924,7 @@ def dump(self):
# maps strings to Language objects.
# "languages" maps the name of the language ("C", "Python").
# "extensions" maps the file extension ("c", "py").
L = TypeVar('L', bound=Language)
LangDict = dict[str, L]
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() }
Expand Down Expand Up @@ -2589,7 +2588,7 @@ class CConverter(metaclass=CConverterAutoRegister):

# If not None, default must be isinstance() of this type.
# (You can also specify a tuple of types.)
default_type: Type | tuple[Type, ...] | None = None
default_type: Type[Any] | tuple[Type[Any], ...] | None = None

# "default" converted into a C value, as a string.
# Or None if there is no default.
Expand Down
3 changes: 2 additions & 1 deletion Tools/clinic/cpp.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ class Monitor:
Anyway this implementation seems to work well enough for the CPython sources.
"""

is_a_simple_defined: Callable = re.compile(r'^defined\s*\(\s*[A-Za-z0-9_]+\s*\)$').match
is_a_simple_defined: Callable[[str], re.Match[str] | None]
is_a_simple_defined = re.compile(r'^defined\s*\(\s*[A-Za-z0-9_]+\s*\)$').match

def __init__(self, filename=None, *, verbose: bool = False):
self.stack: TokenStack = []
Expand Down
0