From 7cfdfaf728394fd92d9572e5eef5e6c77500fe29 Mon Sep 17 00:00:00 2001 From: Forest Belton <65484+forestbelton@users.noreply.github.com> Date: Mon, 21 Jun 2021 23:34:56 -0400 Subject: [PATCH] Run mypy on project --- .gitignore | 1 + mypy.ini | 3 ++ paircd/handle.py | 9 ++++- paircd/handler/privmsg.py | 6 +-- paircd/main.py | 5 ++- paircd/message.py | 2 +- poetry.lock | 81 ++++++++++++++++++++++++++++++++++++++- pyproject.toml | 1 + 8 files changed, 99 insertions(+), 9 deletions(-) create mode 100644 mypy.ini diff --git a/.gitignore b/.gitignore index c18dd8d..0a44e3c 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ __pycache__/ +.mypy_cache/ \ No newline at end of file diff --git a/mypy.ini b/mypy.ini new file mode 100644 index 0000000..f331e92 --- /dev/null +++ b/mypy.ini @@ -0,0 +1,3 @@ +[mypy] +python_version = 3.9 +disallow_untyped_defs = True \ No newline at end of file diff --git a/paircd/handle.py b/paircd/handle.py index 6431c5d..f2a08f1 100644 --- a/paircd/handle.py +++ b/paircd/handle.py @@ -1,5 +1,5 @@ import logging -from typing import Any, Dict +from typing import Any, Awaitable, Callable, Dict from paircd.client import Client from paircd.log import log_client @@ -9,8 +9,13 @@ from paircd.server import Server CMD_HANDLERS: Dict[str, Any] = {} CMD_EXPECTED_ARGC: Dict[str, int] = {} +CmdHandler = Callable[ + [Server, Client, Message], + Awaitable[None], +] -def register_cmd_handler(cmd: str, argc: int, handler) -> None: + +def register_cmd_handler(cmd: str, argc: int, handler: CmdHandler) -> None: CMD_EXPECTED_ARGC[cmd] = argc CMD_HANDLERS[cmd] = handler diff --git a/paircd/handler/privmsg.py b/paircd/handler/privmsg.py index 26375f7..21cc144 100644 --- a/paircd/handler/privmsg.py +++ b/paircd/handler/privmsg.py @@ -10,16 +10,16 @@ async def handle_privmsg(server: Server, client: Client, msg: Message) -> None: recipient = msg.args[0] raw_msg = msg.args[1] - msg = Message("PRIVMSG", [recipient, f":{raw_msg}"], prefix=client.id()).encode() + out = Message("PRIVMSG", [recipient, f":{raw_msg}"], prefix=client.id()).encode() for name, other_client in server.clients_by_nick.items(): if name == recipient: - other_client.msg_queue.put_nowait(msg) + other_client.msg_queue.put_nowait(out) return for name, channel in server.channels_by_name.items(): if name == recipient: - channel.msg_queue.put_nowait(msg) + channel.msg_queue.put_nowait(out) return log_client(client, "unknown recipient", level=logging.WARN) diff --git a/paircd/main.py b/paircd/main.py index 2a26710..f8f0f60 100644 --- a/paircd/main.py +++ b/paircd/main.py @@ -1,4 +1,5 @@ import asyncio +from asyncio.streams import StreamReader, StreamWriter import logging import os @@ -25,7 +26,7 @@ async def read_forever(server: Server, client: Client) -> None: await handle_cmd(server, client, msg) -async def main(): +async def main() -> None: bind_addr = os.getenv("BIND_ADDR") or "0.0.0.0" port = os.getenv("PORT") or 6667 @@ -36,7 +37,7 @@ async def main(): irc_server = Server() - async def register_client(reader, writer): + async def register_client(reader: StreamReader, writer: StreamWriter) -> None: client = Client( hostname=writer.get_extra_info("peername")[0], reader=reader, diff --git a/paircd/message.py b/paircd/message.py index 8808329..c53aa82 100644 --- a/paircd/message.py +++ b/paircd/message.py @@ -12,7 +12,7 @@ EXPECTED_ARG_COUNT = { class ParsingError(Exception): - message: str + message: Optional[str] def __init__(self, message: Optional[str] = None) -> None: self.message = message diff --git a/poetry.lock b/poetry.lock index d72045a..d436c56 100644 --- a/poetry.lock +++ b/poetry.lock @@ -36,6 +36,31 @@ category = "dev" optional = false python-versions = ">=3.5" +[[package]] +name = "mypy" +version = "0.902" +description = "Optional static typing for Python" +category = "dev" +optional = false +python-versions = ">=3.5" + +[package.dependencies] +mypy-extensions = ">=0.4.3,<0.5.0" +toml = "*" +typing-extensions = ">=3.7.4" + +[package.extras] +dmypy = ["psutil (>=4.0)"] +python2 = ["typed-ast (>=1.4.0,<1.5.0)"] + +[[package]] +name = "mypy-extensions" +version = "0.4.3" +description = "Experimental type system extensions for programs checked with the mypy typechecker." +category = "dev" +optional = false +python-versions = "*" + [[package]] name = "packaging" version = "20.9" @@ -96,6 +121,22 @@ wcwidth = "*" checkqa-mypy = ["mypy (==v0.761)"] testing = ["argcomplete", "hypothesis (>=3.56)", "mock", "nose", "requests", "xmlschema"] +[[package]] +name = "toml" +version = "0.10.2" +description = "Python Library for Tom's Obvious, Minimal Language" +category = "dev" +optional = false +python-versions = ">=2.6, !=3.0.*, !=3.1.*, !=3.2.*" + +[[package]] +name = "typing-extensions" +version = "3.10.0.0" +description = "Backported and Experimental Type Hints for Python 3.5+" +category = "dev" +optional = false +python-versions = "*" + [[package]] name = "wcwidth" version = "0.2.5" @@ -107,7 +148,7 @@ python-versions = "*" [metadata] lock-version = "1.1" python-versions = "^3.9" -content-hash = "4d1de49710d78bd295469a572576efe3d5b96e6e8760458e870affe880e8d10e" +content-hash = "b7373aa2ce21a21024a85a334e30808811ff99b915797db9fde12478e6815c9f" [metadata.files] atomicwrites = [ @@ -126,6 +167,35 @@ more-itertools = [ {file = "more-itertools-8.8.0.tar.gz", hash = "sha256:83f0308e05477c68f56ea3a888172c78ed5d5b3c282addb67508e7ba6c8f813a"}, {file = "more_itertools-8.8.0-py3-none-any.whl", hash = "sha256:2cf89ec599962f2ddc4d568a05defc40e0a587fbc10d5989713638864c36be4d"}, ] +mypy = [ + {file = "mypy-0.902-cp35-cp35m-macosx_10_9_x86_64.whl", hash = "sha256:3f12705eabdd274b98f676e3e5a89f247ea86dc1af48a2d5a2b080abac4e1243"}, + {file = "mypy-0.902-cp35-cp35m-manylinux1_x86_64.whl", hash = "sha256:2f9fedc1f186697fda191e634ac1d02f03d4c260212ccb018fabbb6d4b03eee8"}, + {file = "mypy-0.902-cp35-cp35m-manylinux2010_x86_64.whl", hash = "sha256:0756529da2dd4d53d26096b7969ce0a47997123261a5432b48cc6848a2cb0bd4"}, + {file = "mypy-0.902-cp35-cp35m-win_amd64.whl", hash = "sha256:68a098c104ae2b75e946b107ef69dd8398d54cb52ad57580dfb9fc78f7f997f0"}, + {file = "mypy-0.902-cp36-cp36m-macosx_10_9_x86_64.whl", hash = "sha256:cd01c599cf9f897b6b6c6b5d8b182557fb7d99326bcdf5d449a0fbbb4ccee4b9"}, + {file = "mypy-0.902-cp36-cp36m-manylinux1_x86_64.whl", hash = "sha256:e89880168c67cf4fde4506b80ee42f1537ad66ad366c101d388b3fd7d7ce2afd"}, + {file = "mypy-0.902-cp36-cp36m-manylinux2010_x86_64.whl", hash = "sha256:ebe2bc9cb638475f5d39068d2dbe8ae1d605bb8d8d3ff281c695df1670ab3987"}, + {file = "mypy-0.902-cp36-cp36m-win_amd64.whl", hash = "sha256:f89bfda7f0f66b789792ab64ce0978e4a991a0e4dd6197349d0767b0f1095b21"}, + {file = "mypy-0.902-cp37-cp37m-macosx_10_9_x86_64.whl", hash = "sha256:746e0b0101b8efec34902810047f26a8c80e1efbb4fc554956d848c05ef85d76"}, + {file = "mypy-0.902-cp37-cp37m-manylinux1_x86_64.whl", hash = "sha256:0190fb77e93ce971954c9e54ea61de2802065174e5e990c9d4c1d0f54fbeeca2"}, + {file = "mypy-0.902-cp37-cp37m-manylinux2010_x86_64.whl", hash = "sha256:b5dfcd22c6bab08dfeded8d5b44bdcb68c6f1ab261861e35c470b89074f78a70"}, + {file = "mypy-0.902-cp37-cp37m-win_amd64.whl", hash = "sha256:b5ba1f0d5f9087e03bf5958c28d421a03a4c1ad260bf81556195dffeccd979c4"}, + {file = "mypy-0.902-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:9ef5355eaaf7a23ab157c21a44c614365238a7bdb3552ec3b80c393697d974e1"}, + {file = "mypy-0.902-cp38-cp38-manylinux1_x86_64.whl", hash = "sha256:517e7528d1be7e187a5db7f0a3e479747307c1b897d9706b1c662014faba3116"}, + {file = "mypy-0.902-cp38-cp38-manylinux2010_x86_64.whl", hash = "sha256:fd634bc17b1e2d6ce716f0e43446d0d61cdadb1efcad5c56ca211c22b246ebc8"}, + {file = "mypy-0.902-cp38-cp38-win_amd64.whl", hash = "sha256:fc4d63da57ef0e8cd4ab45131f3fe5c286ce7dd7f032650d0fbc239c6190e167"}, + {file = "mypy-0.902-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:353aac2ce41ddeaf7599f1c73fed2b75750bef3b44b6ad12985a991bc002a0da"}, + {file = "mypy-0.902-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:ae94c31bb556ddb2310e4f913b706696ccbd43c62d3331cd3511caef466871d2"}, + {file = "mypy-0.902-cp39-cp39-manylinux1_x86_64.whl", hash = "sha256:8be7bbd091886bde9fcafed8dd089a766fa76eb223135fe5c9e9798f78023a20"}, + {file = "mypy-0.902-cp39-cp39-manylinux2010_x86_64.whl", hash = "sha256:4efc67b9b3e2fddbe395700f91d5b8deb5980bfaaccb77b306310bd0b9e002eb"}, + {file = "mypy-0.902-cp39-cp39-win_amd64.whl", hash = "sha256:9f1d74eeb3f58c7bd3f3f92b8f63cb1678466a55e2c4612bf36909105d0724ab"}, + {file = "mypy-0.902-py3-none-any.whl", hash = "sha256:a26d0e53e90815c765f91966442775cf03b8a7514a4e960de7b5320208b07269"}, + {file = "mypy-0.902.tar.gz", hash = "sha256:9236c21194fde5df1b4d8ebc2ef2c1f2a5dc7f18bcbea54274937cae2e20a01c"}, +] +mypy-extensions = [ + {file = "mypy_extensions-0.4.3-py2.py3-none-any.whl", hash = "sha256:090fedd75945a69ae91ce1303b5824f428daf5a028d2f6ab8a299250a846f15d"}, + {file = "mypy_extensions-0.4.3.tar.gz", hash = "sha256:2d82818f5bb3e369420cb3c4060a7970edba416647068eb4c5343488a6c604a8"}, +] packaging = [ {file = "packaging-20.9-py2.py3-none-any.whl", hash = "sha256:67714da7f7bc052e064859c05c595155bd1ee9f69f76557e21f051443c20947a"}, {file = "packaging-20.9.tar.gz", hash = "sha256:5b327ac1320dc863dca72f4514ecc086f31186744b84a230374cc1fd776feae5"}, @@ -146,6 +216,15 @@ pytest = [ {file = "pytest-5.4.3-py3-none-any.whl", hash = "sha256:5c0db86b698e8f170ba4582a492248919255fcd4c79b1ee64ace34301fb589a1"}, {file = "pytest-5.4.3.tar.gz", hash = "sha256:7979331bfcba207414f5e1263b5a0f8f521d0f457318836a7355531ed1a4c7d8"}, ] +toml = [ + {file = "toml-0.10.2-py2.py3-none-any.whl", hash = "sha256:806143ae5bfb6a3c6e736a764057db0e6a0e05e338b5630894a5f779cabb4f9b"}, + {file = "toml-0.10.2.tar.gz", hash = "sha256:b3bda1d108d5dd99f4a20d24d9c348e91c4db7ab1b749200bded2f839ccbe68f"}, +] +typing-extensions = [ + {file = "typing_extensions-3.10.0.0-py2-none-any.whl", hash = "sha256:0ac0f89795dd19de6b97debb0c6af1c70987fd80a2d62d1958f7e56fcc31b497"}, + {file = "typing_extensions-3.10.0.0-py3-none-any.whl", hash = "sha256:779383f6086d90c99ae41cf0ff39aac8a7937a9283ce0a414e5dd782f4c94a84"}, + {file = "typing_extensions-3.10.0.0.tar.gz", hash = "sha256:50b6f157849174217d0656f99dc82fe932884fb250826c18350e159ec6cdf342"}, +] wcwidth = [ {file = "wcwidth-0.2.5-py2.py3-none-any.whl", hash = "sha256:beb4802a9cebb9144e99086eff703a642a13d6a0052920003a230f3294bbe784"}, {file = "wcwidth-0.2.5.tar.gz", hash = "sha256:c4d647b99872929fdb7bdcaa4fbe7f01413ed3d98077df798530e5b04f116c83"}, diff --git a/pyproject.toml b/pyproject.toml index 851d73e..d7fcfef 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -9,6 +9,7 @@ python = "^3.9" [tool.poetry.dev-dependencies] pytest = "^5.2" +mypy = "^0.902" [build-system] requires = ["poetry-core>=1.0.0"]