Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable mypy with minimal checks #260

Merged
merged 1 commit into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading