]> git.madduck.net Git - etc/vim.git/commitdiff

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

Use strict mypy checking (#3222)
authorShantanu <12621235+hauntsaninja@users.noreply.github.com>
Wed, 31 Aug 2022 03:46:46 +0000 (20:46 -0700)
committerGitHub <noreply@github.com>
Wed, 31 Aug 2022 03:46:46 +0000 (20:46 -0700)
Co-authored-by: Richard Si <63936253+ichard26@users.noreply.github.com>
.pre-commit-config.yaml
mypy.ini
scripts/fuzz.py
src/blackd/middlewares.py
src/blib2to3/pytree.py
tests/optional.py
tests/test_blackd.py

index 87bb6e62987f853cf072ab8b324f32751341a6e4..0be8dc4289090ef97f4aa96fef83471b837016a8 100644 (file)
@@ -49,6 +49,8 @@ repos:
           - types-typed-ast >= 1.4.1
           - click >= 8.1.0
           - platformdirs >= 2.1.0
           - types-typed-ast >= 1.4.1
           - click >= 8.1.0
           - platformdirs >= 2.1.0
+          - pytest
+          - hypothesis
 
   - repo: https://github.com/pre-commit/mirrors-prettier
     rev: v2.7.1
 
   - repo: https://github.com/pre-commit/mirrors-prettier
     rev: v2.7.1
index 244e8ae92f528ecd1b1ea095c4beef56bfdae246..4811cc0be76f86accfe95a035e24a0ee464e1a8b 100644 (file)
--- a/mypy.ini
+++ b/mypy.ini
@@ -7,33 +7,40 @@ python_version=3.6
 mypy_path=src
 
 show_column_numbers=True
 mypy_path=src
 
 show_column_numbers=True
-
-# show error messages from unrelated files
-follow_imports=normal
-
-# suppress errors about unsatisfied imports
-ignore_missing_imports=True
+show_error_codes=True
 
 # be strict
 
 # be strict
-disallow_untyped_calls=True
-warn_return_any=True
-strict_optional=True
-warn_no_return=True
-warn_redundant_casts=True
-warn_unused_ignores=True
-disallow_any_generics=True
-no_implicit_optional=True
+strict=True
+
+# except for...
+no_implicit_reexport = False
 
 # Unreachable blocks have been an issue when compiling mypyc, let's try
 # to avoid 'em in the first place.
 warn_unreachable=True
 
 
 # Unreachable blocks have been an issue when compiling mypyc, let's try
 # to avoid 'em in the first place.
 warn_unreachable=True
 
-# The following are off by default.  Flip them on if you feel
-# adventurous.
-disallow_untyped_defs=True
-check_untyped_defs=True
-
 [mypy-black]
 # The following is because of `patch_click()`. Remove when
 # we drop Python 3.6 support.
 warn_unused_ignores=False
 [mypy-black]
 # The following is because of `patch_click()`. Remove when
 # we drop Python 3.6 support.
 warn_unused_ignores=False
+
+[mypy-blib2to3.driver.*]
+ignore_missing_imports = True
+
+[mypy-IPython.*]
+ignore_missing_imports = True
+
+[mypy-colorama.*]
+ignore_missing_imports = True
+
+[mypy-pathspec.*]
+ignore_missing_imports = True
+
+[mypy-tokenize_rt.*]
+ignore_missing_imports = True
+
+[mypy-uvloop.*]
+ignore_missing_imports = True
+
+[mypy-_black_version.*]
+ignore_missing_imports = True
index 83e02f4515294b0b79dd633d9898b4f90521aa28..25362c927d49f93664d0f3b89a3c36212db2cc9d 100644 (file)
@@ -85,5 +85,8 @@ if __name__ == "__main__":
         pass
     else:
         test = test_idempotent_any_syntatically_valid_python
         pass
     else:
         test = test_idempotent_any_syntatically_valid_python
-        atheris.Setup(sys.argv, test.hypothesis.fuzz_one_input)
+        atheris.Setup(
+            sys.argv,
+            test.hypothesis.fuzz_one_input,  # type: ignore[attr-defined]
+        )
         atheris.Fuzz()
         atheris.Fuzz()
index 7abde525bfdc0bf3297ac3bee67e08f284b59d18..e71f5082686aff52dfe545f3a7f323b32a5b3416 100644 (file)
@@ -9,7 +9,7 @@ Middleware = Callable[[Request, Handler], Awaitable[StreamResponse]]
 
 
 def cors(allow_headers: Iterable[str]) -> Middleware:
 
 
 def cors(allow_headers: Iterable[str]) -> Middleware:
-    @middleware
+    @middleware  # type: ignore[misc]
     async def impl(request: Request, handler: Handler) -> StreamResponse:
         is_options = request.method == "OPTIONS"
         is_preflight = is_options and "Access-Control-Request-Method" in request.headers
     async def impl(request: Request, handler: Handler) -> StreamResponse:
         is_options = request.method == "OPTIONS"
         is_preflight = is_options and "Access-Control-Request-Method" in request.headers
@@ -32,4 +32,4 @@ def cors(allow_headers: Iterable[str]) -> Middleware:
 
         return resp
 
 
         return resp
 
-    return impl  # type: ignore
+    return impl  # type: ignore[no-any-return]
index 10b4690218e50209b5b00cce54195cd76112bb44..15a1420ef7d6f3c3c6054bfbbbf90040d9aa6f4b 100644 (file)
@@ -10,7 +10,7 @@ even the comments and whitespace between tokens.
 There's also a pattern matching implementation here.
 """
 
 There's also a pattern matching implementation here.
 """
 
-# mypy: allow-untyped-defs
+# mypy: allow-untyped-defs, allow-incomplete-defs
 
 from typing import (
     Any,
 
 from typing import (
     Any,
@@ -291,7 +291,7 @@ class Node(Base):
         """
         return "".join(map(str, self.children))
 
         """
         return "".join(map(str, self.children))
 
-    def _eq(self, other) -> bool:
+    def _eq(self, other: Base) -> bool:
         """Compare two nodes for equality."""
         return (self.type, self.children) == (other.type, other.children)
 
         """Compare two nodes for equality."""
         return (self.type, self.children) == (other.type, other.children)
 
@@ -326,7 +326,7 @@ class Node(Base):
         return self.children[0].prefix
 
     @prefix.setter
         return self.children[0].prefix
 
     @prefix.setter
-    def prefix(self, prefix) -> None:
+    def prefix(self, prefix: Text) -> None:
         if self.children:
             self.children[0].prefix = prefix
 
         if self.children:
             self.children[0].prefix = prefix
 
@@ -439,7 +439,7 @@ class Leaf(Base):
         """
         return self._prefix + str(self.value)
 
         """
         return self._prefix + str(self.value)
 
-    def _eq(self, other) -> bool:
+    def _eq(self, other: "Leaf") -> bool:
         """Compare two nodes for equality."""
         return (self.type, self.value) == (other.type, other.value)
 
         """Compare two nodes for equality."""
         return (self.type, self.value) == (other.type, other.value)
 
@@ -472,7 +472,7 @@ class Leaf(Base):
         return self._prefix
 
     @prefix.setter
         return self._prefix
 
     @prefix.setter
-    def prefix(self, prefix) -> None:
+    def prefix(self, prefix: Text) -> None:
         self.changed()
         self._prefix = prefix
 
         self.changed()
         self._prefix = prefix
 
@@ -618,7 +618,7 @@ class LeafPattern(BasePattern):
         self.content = content
         self.name = name
 
         self.content = content
         self.name = name
 
-    def match(self, node: NL, results=None):
+    def match(self, node: NL, results=None) -> bool:
         """Override match() to insist on a leaf node."""
         if not isinstance(node, Leaf):
             return False
         """Override match() to insist on a leaf node."""
         if not isinstance(node, Leaf):
             return False
@@ -678,7 +678,7 @@ class NodePattern(BasePattern):
                 if isinstance(item, WildcardPattern):  # type: ignore[unreachable]
                     self.wildcards = True  # type: ignore[unreachable]
         self.type = type
                 if isinstance(item, WildcardPattern):  # type: ignore[unreachable]
                     self.wildcards = True  # type: ignore[unreachable]
         self.type = type
-        self.content = newcontent
+        self.content = newcontent  # TODO: this is unbound when content is None
         self.name = name
 
     def _submatch(self, node, results=None) -> bool:
         self.name = name
 
     def _submatch(self, node, results=None) -> bool:
@@ -920,7 +920,7 @@ class WildcardPattern(BasePattern):
 
 
 class NegatedPattern(BasePattern):
 
 
 class NegatedPattern(BasePattern):
-    def __init__(self, content: Optional[Any] = None) -> None:
+    def __init__(self, content: Optional[BasePattern] = None) -> None:
         """
         Initializer.
 
         """
         Initializer.
 
@@ -941,7 +941,7 @@ class NegatedPattern(BasePattern):
         # We only match an empty sequence of nodes in its entirety
         return len(nodes) == 0
 
         # We only match an empty sequence of nodes in its entirety
         return len(nodes) == 0
 
-    def generate_matches(self, nodes) -> Iterator[Tuple[int, _Results]]:
+    def generate_matches(self, nodes: List[NL]) -> Iterator[Tuple[int, _Results]]:
         if self.content is None:
             # Return a match if there is an empty sequence
             if len(nodes) == 0:
         if self.content is None:
             # Return a match if there is an empty sequence
             if len(nodes) == 0:
index 853ecaa2a43d5424492fc3c741975c0c05430e32..8a39cc440a6cdf7aa602704b8124c18c97f32edb 100644 (file)
@@ -26,7 +26,7 @@ try:
     from pytest import StashKey
 except ImportError:
     # pytest < 7
     from pytest import StashKey
 except ImportError:
     # pytest < 7
-    from _pytest.store import StoreKey as StashKey
+    from _pytest.store import StoreKey as StashKey  # type: ignore[no-redef]
 
 log = logging.getLogger(__name__)
 
 
 log = logging.getLogger(__name__)
 
index 8e739063f6e50c908105cfab832df1b7c2dc4445..1da4ab702d2360faeb3159a6f3fb9921d5cb8c8f 100644 (file)
@@ -1,6 +1,6 @@
 import re
 import sys
 import re
 import sys
-from typing import Any
+from typing import TYPE_CHECKING, Any, Callable, TypeVar
 from unittest.mock import patch
 
 import pytest
 from unittest.mock import patch
 
 import pytest
@@ -19,16 +19,22 @@ if LESS_THAN_311:  # noqa: C901
     except ImportError as e:
         raise RuntimeError("Please install Black with the 'd' extra") from e
 
     except ImportError as e:
         raise RuntimeError("Please install Black with the 'd' extra") from e
 
-    try:
-        from aiohttp.test_utils import unittest_run_loop
-    except ImportError:
-        # unittest_run_loop is unnecessary and a no-op since aiohttp 3.8, and aiohttp 4
-        # removed it. To maintain compatibility we can make our own no-op decorator.
-        def unittest_run_loop(func: Any, *args: Any, **kwargs: Any) -> Any:
-            return func
+    if TYPE_CHECKING:
+        F = TypeVar("F", bound=Callable[..., Any])
+
+        unittest_run_loop: Callable[[F], F] = lambda x: x
+    else:
+        try:
+            from aiohttp.test_utils import unittest_run_loop
+        except ImportError:
+            # unittest_run_loop is unnecessary and a no-op since aiohttp 3.8, and
+            # aiohttp 4 removed it. To maintain compatibility we can make our own
+            # no-op decorator.
+            def unittest_run_loop(func, *args, **kwargs):
+                return func
 
     @pytest.mark.blackd
 
     @pytest.mark.blackd
-    class BlackDTestCase(AioHTTPTestCase):
+    class BlackDTestCase(AioHTTPTestCase):  # type: ignore[misc]
         def test_blackd_main(self) -> None:
             with patch("blackd.web.run_app"):
                 result = CliRunner().invoke(blackd.main, [])
         def test_blackd_main(self) -> None:
             with patch("blackd.web.run_app"):
                 result = CliRunner().invoke(blackd.main, [])