Skip to content

Commit

Permalink
Expand Mypy config for twisted.python.* to individual files and re-en…
Browse files Browse the repository at this point in the history
…able low-hanging-fruit checks for a bunch of files.
  • Loading branch information
wsanchez committed Oct 2, 2020
1 parent a9bf663 commit 5815ee4
Show file tree
Hide file tree
Showing 21 changed files with 376 additions and 126 deletions.
234 changes: 225 additions & 9 deletions mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -159,26 +159,242 @@ warn_return_any = False
[mypy-twisted.protocols.test.test_basic]
allow_incomplete_defs = True

[mypy-twisted.python.*]
[mypy-twisted.python._appdirs]
allow_untyped_defs = True

[mypy-twisted.python._inotify]
allow_untyped_defs = True

[mypy-twisted.python._pydoctor]
allow_untyped_defs = True

[mypy-twisted.python._release]
allow_untyped_defs = True
check_untyped_defs = False

[mypy-twisted.python._setup]
allow_incomplete_defs = True
warn_return_any = False
allow_untyped_defs = True

[mypy-twisted.python._shellcomp]
allow_untyped_defs = True

[mypy-twisted.python._textattributes]
allow_untyped_defs = True

[mypy-twisted.python._tzhelper]
allow_untyped_defs = True

[mypy-twisted.python.compat]
allow_incomplete_defs = True
warn_return_any = False
allow_untyped_defs = True

[mypy-twisted.python.components]
allow_untyped_defs = True

[mypy-twisted.python.context]
allow_untyped_defs = True

[mypy-twisted.python.deprecate]
allow_untyped_defs = True

[mypy-twisted.python.failure]
allow_untyped_defs = True
check_untyped_defs = False

[mypy-twisted.python.fakepwd]
allow_untyped_defs = True

[mypy-twisted.python.filepath]
allow_untyped_defs = True
check_untyped_defs = False

[mypy-twisted.python.formmethod]
allow_untyped_defs = True
check_untyped_defs = False

[mypy-twisted.python.htmlizer]
allow_untyped_defs = True

[mypy-twisted.python.lockfile]
allow_untyped_defs = True

[mypy-twisted.python.log]
allow_untyped_defs = True

[mypy-twisted.python.logfile]
allow_untyped_defs = True
check_untyped_defs = False

[mypy-twisted.python.modules]
warn_return_any = False
allow_untyped_defs = True
check_untyped_defs = False

[mypy-twisted.python.monkey]
allow_untyped_defs = True

[mypy-twisted.python.procutils]
allow_untyped_defs = True

[mypy-twisted.python.randbytes]
allow_untyped_defs = True

[mypy-twisted.python.rebuild]
allow_untyped_defs = True
check_untyped_defs = False

[mypy-twisted.python.reflect]
allow_untyped_defs = True
check_untyped_defs = False

[mypy-twisted.python.release]
allow_untyped_defs = True

[mypy-twisted.python.roots]
allow_untyped_defs = True

[mypy-twisted.python.runtime]
allow_untyped_defs = True

[mypy-twisted.python.sendmsg]
allow_untyped_defs = True

[mypy-twisted.python.shortcut]
allow_untyped_defs = True

[mypy-twisted.python.syslog]
allow_untyped_defs = True

[mypy-twisted.python.systemd]
allow_untyped_defs = True

[mypy-twisted.python.test.modules_helpers]
allow_untyped_defs = True
check_untyped_defs = False

[mypy-twisted.python.test.pullpipe]
allow_untyped_defs = True

[mypy-twisted.python.test.test_appdirs]
allow_untyped_defs = True

[mypy-twisted.python.test.test_components]
allow_untyped_defs = True
check_untyped_defs = False

[mypy-twisted.python.test.test_constants]
allow_untyped_defs = True
check_untyped_defs = False

[mypy-twisted.python.test.test_deprecate]
allow_untyped_defs = True
check_untyped_defs = False

[mypy-twisted.python.test.test_dist3]
allow_untyped_defs = True

[mypy-twisted.python.test.test_fakepwd]
allow_untyped_defs = True
check_untyped_defs = False

[mypy-twisted.python.test.test_htmlizer]
allow_untyped_defs = True

[mypy-twisted.python.test.test_inotify]
allow_untyped_defs = True
check_untyped_defs = False

[mypy-twisted.python.test.test_pydoctor]
allow_untyped_defs = True
check_untyped_defs = False

[mypy-twisted.python.test.test_release]
allow_untyped_defs = True
check_untyped_defs = False

[mypy-twisted.python.test.test_runtime]
allow_untyped_defs = True

[mypy-twisted.python.test.test_sendmsg]
allow_untyped_defs = True
check_untyped_defs = False

[mypy-twisted.python.test.test_setup]
allow_untyped_defs = True

[mypy-twisted.python.test.test_shellcomp]
allow_untyped_defs = True
check_untyped_defs = False

[mypy-twisted.python.test.test_syslog]
allow_untyped_defs = True
check_untyped_defs = False

[mypy-twisted.python.test.test_systemd]
allow_untyped_defs = True
check_untyped_defs = False

[mypy-twisted.python.test.test_textattributes]
allow_untyped_defs = True

[mypy-twisted.python.test.test_tzhelper]
allow_untyped_defs = True

[mypy-twisted.python.test.test_url]
allow_untyped_defs = True
check_untyped_defs = False

[mypy-twisted.python.test.test_urlpath]
allow_untyped_defs = True
check_untyped_defs = False

[mypy-twisted.python.test.test_util]
allow_untyped_defs = True
check_untyped_defs = False

[mypy-twisted.python.test.test_versions]
allow_untyped_defs = True

[mypy-twisted.python.test.test_win32]
allow_untyped_defs = True

[mypy-twisted.python.test.test_zippath]
allow_untyped_defs = True

[mypy-twisted.python.test.test_zipstream]
allow_untyped_defs = True
check_untyped_defs = False

[mypy-twisted.python.text]
allow_untyped_defs = True
check_untyped_defs = False

[mypy-twisted.python.threadable]
allow_untyped_defs = True
check_untyped_defs = False

[mypy-twisted.python.threadpool]
allow_untyped_defs = True

[mypy-twisted.python.urlpath]
warn_return_any = False
allow_untyped_defs = True
check_untyped_defs = False

[mypy-twisted.python.usage]
warn_return_any = False
allow_untyped_defs = True
check_untyped_defs = False

[mypy-twisted.python.util]
allow_untyped_defs = True
check_untyped_defs = False

[mypy-twisted.python.win32]
allow_untyped_defs = True
check_untyped_defs = False

[mypy-twisted.python.zippath]
allow_untyped_defs = True

[mypy-twisted.python.zipstream]
allow_untyped_defs = True
check_untyped_defs = False

[mypy-twisted.runner.*]
allow_untyped_defs = True
Expand Down
4 changes: 3 additions & 1 deletion src/twisted/python/_appdirs.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ def getDataDirectory(moduleName=None):
"""
if not moduleName:
caller = currentframe(1)
moduleName = inspect.getmodule(caller).__name__
module = inspect.getmodule(caller)
assert module is not None
moduleName = module.__name__

return appdirs.user_data_dir(moduleName)
3 changes: 2 additions & 1 deletion src/twisted/python/_pydoctor.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"""

import ast
from typing import Optional

from pydoctor import model, zopeinterface, astbuilder
from pydoctor.sphinx import SphinxInventory
Expand Down Expand Up @@ -59,7 +60,7 @@ def getLink(self, name):
if name == "zope.interface.adapter.AdapterRegistry":
# FIXME:
# https://github.com/zopefoundation/zope.interface/issues/41
relativeLink = "adapter.html"
relativeLink = "adapter.html" # type: Optional[str]
else:
# Not a known exception.
relativeLink = None
Expand Down
3 changes: 2 additions & 1 deletion src/twisted/python/_release.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import os
import sys
from typing import Dict

from zope.interface import Interface, implementer

Expand Down Expand Up @@ -217,7 +218,7 @@ def getVersion(self):
@return: A L{incremental.Version} specifying the version number of the
project based on live python modules.
"""
namespace = {}
namespace = {} # type: Dict[str, object]
directory = self.directory
while not namespace:
if directory.path == "/":
Expand Down
9 changes: 5 additions & 4 deletions src/twisted/python/_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import platform
import re
import sys
from typing import Any, Dict, cast

from distutils.command import build_ext
from distutils.errors import CompileError
Expand Down Expand Up @@ -68,7 +69,7 @@
"Programming Language :: Python :: 3.8",
],
python_requires=">=3.5",
)
) # type: Dict[str, Any]


_dev = [
Expand Down Expand Up @@ -323,7 +324,7 @@ def build_extensions(self):
Check to see which extension modules to build and then build them.
"""
self.prepare_extensions()
build_ext.build_ext.build_extensions(self)
build_ext.build_ext.build_extensions(self) # type: ignore[attr-defined]

def _remove_conftest(self):
for filename in ("conftest.c", "conftest.o", "conftest.obj"):
Expand Down Expand Up @@ -355,7 +356,7 @@ def _check_header(self, header_name):
return self._compile_helper("#include <{}>\n".format(header_name))


def _checkCPython(sys=sys, platform=platform) -> bool:
def _checkCPython(platform: Any = platform) -> bool:
"""
Checks if this implementation is CPython.
Expand All @@ -368,7 +369,7 @@ def _checkCPython(sys=sys, platform=platform) -> bool:
@return: C{False} if the implementation is definitely not CPython, C{True}
otherwise.
"""
return platform.python_implementation() == "CPython"
return cast(bool, platform.python_implementation() == "CPython")


_isCPython = _checkCPython() # type: bool
Expand Down
Loading

0 comments on commit 5815ee4

Please sign in to comment.