From 7d4d964bb65817c209741714467f4c0104e21c33 Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Mon, 30 Dec 2024 22:49:44 +0100 Subject: [PATCH 1/3] Fix typos discovered by codespell --- .pre-commit-config.yaml | 6 ++++++ docs/source/generics.rst | 2 +- docs/source/more_types.rst | 2 +- docs/source/runtime_troubles.rst | 2 +- mypy/argmap.py | 2 +- mypy/fastparse.py | 2 +- mypy/join.py | 2 +- mypy/messages.py | 2 +- mypy/semanal_namedtuple.py | 2 +- mypy/semanal_newtype.py | 2 +- mypy/stubgenc.py | 2 +- mypy/suggestions.py | 2 +- mypyc/codegen/emitfunc.py | 2 +- mypyc/doc/dev-intro.md | 4 ++-- mypyc/irbuild/prebuildvisitor.py | 2 +- pyproject.toml | 4 ++++ 16 files changed, 25 insertions(+), 15 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 1e53f084e675..42b14ace136e 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -20,6 +20,12 @@ repos: hooks: - id: check-dependabot - id: check-github-workflows + - repo: https://github.com/codespell-project/codespell + rev: v2.2.4 + hooks: + - id: codespell + additional_dependencies: + - tomli - repo: https://github.com/rhysd/actionlint rev: v1.7.4 hooks: diff --git a/docs/source/generics.rst b/docs/source/generics.rst index 731365d3789b..15538dea13bf 100644 --- a/docs/source/generics.rst +++ b/docs/source/generics.rst @@ -999,7 +999,7 @@ similarly supported via generics (Python 3.12 syntax): .. code-block:: python - from colletions.abc import Callable + from collections.abc import Callable from typing import Any def route[F: Callable[..., Any]](url: str) -> Callable[[F], F]: diff --git a/docs/source/more_types.rst b/docs/source/more_types.rst index cbf40d5dcaa5..0383c3448d06 100644 --- a/docs/source/more_types.rst +++ b/docs/source/more_types.rst @@ -390,7 +390,7 @@ program: The ``summarize([])`` call matches both variants: an empty list could be either a ``list[int]`` or a ``list[str]``. In this case, mypy will break the tie by picking the first matching variant: ``output`` -will have an inferred type of ``float``. The implementor is responsible +will have an inferred type of ``float``. The implementer is responsible for making sure ``summarize`` breaks ties in the same way at runtime. However, there are two exceptions to the "pick the first match" rule. diff --git a/docs/source/runtime_troubles.rst b/docs/source/runtime_troubles.rst index d039db30f3fa..24482e7c3be0 100644 --- a/docs/source/runtime_troubles.rst +++ b/docs/source/runtime_troubles.rst @@ -274,7 +274,7 @@ libraries if types are generic only in stubs. Using types defined in stubs but not at runtime ----------------------------------------------- -Sometimes stubs that you're using may define types you wish to re-use that do +Sometimes stubs that you're using may define types you wish to reuse that do not exist at runtime. Importing these types naively will cause your code to fail at runtime with ``ImportError`` or ``ModuleNotFoundError``. Similar to previous sections, these can be dealt with by using :ref:`typing.TYPE_CHECKING diff --git a/mypy/argmap.py b/mypy/argmap.py index c863844f90ad..8db78b5413e8 100644 --- a/mypy/argmap.py +++ b/mypy/argmap.py @@ -220,7 +220,7 @@ def expand_actual_type( self.tuple_index += 1 item = actual_type.items[self.tuple_index - 1] if isinstance(item, UnpackType) and not allow_unpack: - # An upack item that doesn't have special handling, use upper bound as above. + # An unpack item that doesn't have special handling, use upper bound as above. unpacked = get_proper_type(item.type) if isinstance(unpacked, TypeVarTupleType): fallback = get_proper_type(unpacked.upper_bound) diff --git a/mypy/fastparse.py b/mypy/fastparse.py index 6985fd567402..2a47a085874a 100644 --- a/mypy/fastparse.py +++ b/mypy/fastparse.py @@ -2185,7 +2185,7 @@ def visit_member_expr(self, e: MemberExpr) -> None: class FindYield(TraverserVisitor): - """Check if an AST contains yields or yield froms.""" + """Check if an AST contains yields or yield forms.""" def __init__(self) -> None: self.found = False diff --git a/mypy/join.py b/mypy/join.py index 166434f58f8d..11e0c88cca89 100644 --- a/mypy/join.py +++ b/mypy/join.py @@ -499,7 +499,7 @@ def join_tuples(self, s: TupleType, t: TupleType) -> list[Type] | None: return items return None if s_unpack_index is not None and t_unpack_index is not None: - # The most complex case: both tuples have an upack item. + # The most complex case: both tuples have an unpack item. s_unpack = s.items[s_unpack_index] assert isinstance(s_unpack, UnpackType) s_unpacked = get_proper_type(s_unpack.type) diff --git a/mypy/messages.py b/mypy/messages.py index 5fa4dc0c05ad..019ccceed451 100644 --- a/mypy/messages.py +++ b/mypy/messages.py @@ -210,7 +210,7 @@ def are_type_names_disabled(self) -> bool: def prefer_simple_messages(self) -> bool: """Should we generate simple/fast error messages? - If errors aren't shown to the user, we don't want to waste cyles producing + If errors aren't shown to the user, we don't want to waste cycles producing complex error messages. """ return self.errors.prefer_simple_messages() diff --git a/mypy/semanal_namedtuple.py b/mypy/semanal_namedtuple.py index a18d0591364c..b67747d16887 100644 --- a/mypy/semanal_namedtuple.py +++ b/mypy/semanal_namedtuple.py @@ -198,7 +198,7 @@ def check_namedtuple_classdef( # Something is incomplete. We need to defer this named tuple. return None types.append(analyzed) - # ...despite possible minor failures that allow further analyzis. + # ...despite possible minor failures that allow further analysis. if name.startswith("_"): self.fail( f"NamedTuple field name cannot start with an underscore: {name}", stmt diff --git a/mypy/semanal_newtype.py b/mypy/semanal_newtype.py index c9c0c46f7aee..0c717b5d9a0e 100644 --- a/mypy/semanal_newtype.py +++ b/mypy/semanal_newtype.py @@ -174,7 +174,7 @@ def analyze_newtype_declaration(self, s: AssignmentStmt) -> tuple[str | None, Ca def check_newtype_args( self, name: str, call: CallExpr, context: Context ) -> tuple[Type | None, bool]: - """Ananlyze base type in NewType call. + """Analyze base type in NewType call. Return a tuple (type, should defer). """ diff --git a/mypy/stubgenc.py b/mypy/stubgenc.py index 694be8e4beda..b5bb4f8f727b 100755 --- a/mypy/stubgenc.py +++ b/mypy/stubgenc.py @@ -341,7 +341,7 @@ def get_pos_default(i: int, _arg: str) -> Any | None: # Add *args if present if varargs: arglist.append(ArgSig(f"*{varargs}", get_annotation(varargs))) - # if we have keyword only args, then wee need to add "*" + # if we have keyword only args, then we need to add "*" elif kwonlyargs: arglist.append(ArgSig("*")) diff --git a/mypy/suggestions.py b/mypy/suggestions.py index 36dc7e8e2acd..16e630bf8c6e 100644 --- a/mypy/suggestions.py +++ b/mypy/suggestions.py @@ -454,7 +454,7 @@ def get_guesses_from_parent(self, node: FuncDef) -> list[CallableType]: pnode = parent.names.get(node.name) if pnode and isinstance(pnode.node, (FuncDef, Decorator)): typ = get_proper_type(pnode.node.type) - # FIXME: Doesn't work right with generic tyeps + # FIXME: Doesn't work right with generic types if isinstance(typ, CallableType) and len(typ.arg_types) == len(node.arguments): # Return the first thing we find, since it probably doesn't make sense # to grab things further up in the chain if an earlier parent has it. diff --git a/mypyc/codegen/emitfunc.py b/mypyc/codegen/emitfunc.py index 6088fb06dd32..ab397ccdab53 100644 --- a/mypyc/codegen/emitfunc.py +++ b/mypyc/codegen/emitfunc.py @@ -149,7 +149,7 @@ def generate_native_function( # generates them will add instructions between the branch and the # next label, causing the label to be wrongly removed. A better # solution would be to change the IR so that it adds a basic block - # inbetween the calls. + # in between the calls. is_problematic_op = isinstance(terminator, Branch) and any( isinstance(s, GetAttr) for s in terminator.sources() ) diff --git a/mypyc/doc/dev-intro.md b/mypyc/doc/dev-intro.md index 461a19d37121..37f506e2edaf 100644 --- a/mypyc/doc/dev-intro.md +++ b/mypyc/doc/dev-intro.md @@ -223,7 +223,7 @@ pretty-printed IR into `build/ops.txt`. This is the final IR that includes the output from exception and reference count handling insertion passes. -We also have tests that verify the generate IR +We also have tests that verify the generated IR (`mypyc/test-data/irbuild-*.text`). ## Type-checking Mypyc @@ -284,7 +284,7 @@ under `mypyc/lib-rt`. ## Inspecting Generated C -It's often useful to inspect the C code genenerate by mypyc to debug +It's often useful to inspect the C code generated by mypyc to debug issues. Mypyc stores the generated C code as `build/__native.c`. Compiled native functions have the prefix `CPyDef_`, while wrapper functions used for calling functions from interpreted Python code have diff --git a/mypyc/irbuild/prebuildvisitor.py b/mypyc/irbuild/prebuildvisitor.py index 17f907d42111..5f178a290138 100644 --- a/mypyc/irbuild/prebuildvisitor.py +++ b/mypyc/irbuild/prebuildvisitor.py @@ -73,7 +73,7 @@ def __init__( self.decorators_to_remove: dict[FuncDef, list[int]] = decorators_to_remove # A mapping of import groups (a series of Import nodes with - # nothing inbetween) where each group is keyed by its first + # nothing in between) where each group is keyed by its first # import node. self.module_import_groups: dict[Import, list[Import]] = {} self._current_import_group: Import | None = None diff --git a/pyproject.toml b/pyproject.toml index 5edbc8a75224..369074ebc6c2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -100,6 +100,10 @@ force-exclude = ''' ^/test-data ''' +[tool.codespell] +ignore-words-list = "ans,ccompiler,corus,fo,haa,hax,notin,ot,statics,whet,zar" +skip = "./mypyc/external/*,*.pyi,*.test" + [tool.ruff] line-length = 99 target-version = "py39" From d5984107d3c33ed67ab3f0d767ce1e841a428e53 Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Mon, 30 Dec 2024 23:19:08 +0100 Subject: [PATCH 2/3] Add froms to the ingore-words-list --- mypy/fastparse.py | 2 +- pyproject.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/mypy/fastparse.py b/mypy/fastparse.py index 2a47a085874a..6985fd567402 100644 --- a/mypy/fastparse.py +++ b/mypy/fastparse.py @@ -2185,7 +2185,7 @@ def visit_member_expr(self, e: MemberExpr) -> None: class FindYield(TraverserVisitor): - """Check if an AST contains yields or yield forms.""" + """Check if an AST contains yields or yield froms.""" def __init__(self) -> None: self.found = False diff --git a/pyproject.toml b/pyproject.toml index 369074ebc6c2..01df5a2095e8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -101,7 +101,7 @@ force-exclude = ''' ''' [tool.codespell] -ignore-words-list = "ans,ccompiler,corus,fo,haa,hax,notin,ot,statics,whet,zar" +ignore-words-list = "ans,ccompiler,corus,fo,froms,haa,hax,notin,ot,statics,whet,zar" skip = "./mypyc/external/*,*.pyi,*.test" [tool.ruff] From caa1a82a26edcc406ca8912d6aa272f04e7cf9ff Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Tue, 31 Dec 2024 01:07:30 +0100 Subject: [PATCH 3/3] Update .pre-commit-config.yaml Co-authored-by: Marc Mueller <30130371+cdce8p@users.noreply.github.com> --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 42b14ace136e..4a90963d1ae0 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -21,7 +21,7 @@ repos: - id: check-dependabot - id: check-github-workflows - repo: https://github.com/codespell-project/codespell - rev: v2.2.4 + rev: v2.3.0 hooks: - id: codespell additional_dependencies: