Skip to content

Commit

Permalink
Enable mypy with minimal checks
Browse files Browse the repository at this point in the history
Partial-Fix: #258
  • Loading branch information
ssbarnea committed Aug 15, 2024
1 parent 96579d5 commit 8b2b7cc
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 5 deletions.
31 changes: 27 additions & 4 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,31 @@ 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:
- aiobotocore
- 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-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 @@ -60,9 +83,9 @@ repos:
args:
- --output-format=colorized
additional_dependencies:
- aiobotocore
- aiohttp
- aiokafka
- ansible-core
- asyncmock
- azure-servicebus
- dpath
Expand All @@ -71,9 +94,9 @@ repos:
- 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/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
34 changes: 34 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,40 @@ 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", "index", "var-annotated","union-attr", "return-value", "attr-defined", "override", "assignment", "misc", "return"]
# 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 8b2b7cc

Please sign in to comment.