Skip to content

Commit

Permalink
Enable mypy with minimal checks (#260)
Browse files Browse the repository at this point in the history
Partial-Fix: #258
  • Loading branch information
ssbarnea authored Aug 15, 2024
1 parent 679f36f commit 53bf164
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 5 deletions.
33 changes: 30 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ repos:
hooks:
- id: shellcheck
- repo: https://github.com/streetsidesoftware/cspell-cli
rev: v8.13.1
rev: v8.13.3
hooks:
- id: cspell
- repo: https://github.com/pycqa/isort
Expand All @@ -36,8 +36,33 @@ repos:
hooks:
- id: black
language_version: python3
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.11.1
hooks:
- id: mypy
# empty args needed in order to match mypy cli behavior
args: []
additional_dependencies:
- aiohttp
- aiokafka
- ansible-core>=2.15
- asyncmock
- azure-servicebus
- dpath
- kafka-python-ng; python_version >= "3.12"
- kafka-python; python_version < "3.12"
- psycopg[binary,pool] # extras needed to avoid install failure on macos-aarch64
- pytest
- types-PyYAML
- types-aiobotocore[cloudtrail,sqs]
- types-botocore
- types-mock
- types-requests
- watchdog
- xxhash

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: "v0.5.6"
rev: "v0.5.7"
hooks:
- id: ruff
args: [
Expand All @@ -63,17 +88,19 @@ repos:
- aiobotocore
- aiohttp
- aiokafka
- ansible-core
- asyncmock
- azure-servicebus
- botocore
- dpath
- kafka-python
- psycopg
- pytest
- pyyaml
- requests
- types-aiobotocore
- watchdog
- xxhash
- ansible-core
- repo: local
hooks:
- id: ansible-test-sanity
Expand Down
2 changes: 1 addition & 1 deletion extensions/eda/plugins/event_source/aws_sqs_queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ async def main(queue: asyncio.Queue, args: dict[str, Any]) -> None:
)

if "Messages" in response:
for msg in response["Messages"]:
for msg in response["Messages"]: # type: ignore[typeddict-item]
meta = {"MessageId": msg["MessageId"]}
try:
msg_body = json.loads(msg["Body"])
Expand Down
2 changes: 1 addition & 1 deletion extensions/eda/plugins/event_source/webhook.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ async def webhook(request: web.Request) -> web.Response:
return web.Response(text=endpoint)


def _parse_token(request: web.Request) -> (str, str):
def _parse_token(request: web.Request) -> tuple[str, str]:
scheme, token = request.headers["Authorization"].strip().split(" ")
if scheme != "Bearer":
raise web.HTTPUnauthorized(text="Only Bearer type is accepted")
Expand Down
45 changes: 45 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,51 @@ use_parentheses = true
ensure_newline_before_comments = true
line_length = 120

[tool.mypy]
python_version = "3.9"
color_output = true
error_summary = true

# TODO: Remove temporary skips and close https://github.com/ansible/event-driven-ansible/issues/258
disable_error_code = [
"arg-type",
"assignment",
"attr-defined",
"index",
"misc",
"override",
"return",
"return-value",
"union-attr",
"var-annotated",
]
# strict = true
# disallow_untyped_calls = true
# disallow_untyped_defs = true
# disallow_any_generics = true
# disallow_any_unimported = True
# warn_redundant_casts = True
# warn_return_any = True
# warn_unused_configs = True

# site-packages is here to help vscode mypy integration getting confused
exclude = "(build|dist|test/local-content|site-packages|~/.pyenv|examples/playbooks/collections|plugins/modules)"
# https://github.com/python/mypy/issues/12664
incremental = false
namespace_packages = true
explicit_package_bases = true

[[tool.mypy.overrides]]
module = [
# Dependencies not following pep-561 yet:
"aiokafka.*", # https://github.com/aio-libs/aiokafka/issues/980
"ansible.*", # https://github.com/ansible/ansible/issues/83801
"asyncmock", # https://github.com/timsavage/asyncmock/issues/8
# "botocore.*", # https://github.com/boto/botocore/issues/2297
"kafka.*", # https://github.com/dpkp/kafka-python/issues/2446
]
ignore_missing_imports = true

[tool.pylint.MASTER]
# Temporary ignore until we are able to address issues on these:
ignore-paths = "^(demos/dynatrace-demo/fake_app.py|tests/|plugins/modules).*$"
Expand Down

0 comments on commit 53bf164

Please sign in to comment.