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

Add type checking #35402

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
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
19 changes: 19 additions & 0 deletions .github/workflows/check-type-hints.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Check type hints

on:
pull_request:
branches:
- master

jobs:
mypy:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: actions/setup-python@v4
with:
python-version: 3.9
- run: pip install mypy
- run: mypy --install-types --non-interactive --explicit-package-bases @mypy_modules.txt
12 changes: 10 additions & 2 deletions corehq/apps/app_manager/xform_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@


"""
from __future__ import annotations

import re
import uuid
from typing import Optional

from lxml import etree
from lxml.builder import E
Expand Down Expand Up @@ -424,13 +427,18 @@ def get_input_question_node(name_, groups_=None, choices_=None, **params_):

class Question(object):

def __init__(self, name, xform, groups=None):
def __init__(
self,
name: str,
xform: XFormBuilder,
groups: Optional[list[str]] = None,
) -> None:
self.name = name
self.xform = xform
self.groups = groups

@property
def form(self) -> "XFormBuilder":
def form(self) -> XFormBuilder:
return self.xform


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def setUpClass(cls):

def tearDown(self) -> None:
manager.cluster_routing(enabled=True)
return super().tearDown()
super().tearDown()

def test_invalid_index_canonical_raises(self):
with self.assertRaises(CommandError):
Expand Down
2 changes: 2 additions & 0 deletions corehq/apps/userreports/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,8 @@ def is_this_data_source(rebuild_task):
return args[0] == data_source_config_id

def iter_tasks():
if not flower_url:
return
task_names = (
'corehq.apps.userreports.tasks.rebuild_indicators',
'corehq.apps.userreports.tasks.rebuild_indicators_in_place',
Expand Down
2 changes: 1 addition & 1 deletion corehq/apps/userreports/tests/test_data_source_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def setUpClass(cls) -> None:
"type": "property_name"
}
cls.config = DataSourceConfiguration.wrap(cls.config)
return super().setUpClass()
super().setUpClass()

def test_raises_when_domain_has_no_permission(self):
self.config.domain = 'domain_nopermission'
Expand Down
5 changes: 4 additions & 1 deletion corehq/messaging/smsbackends/twilio/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,10 @@ def send(self, msg, orig_phone_number=None, *args, **kwargs):
msg.backend_message_id = message.sid
msg.save()

def from_or_messaging_service_sid(self, phone_number: str) -> (Optional[str], Optional[str]):
def from_or_messaging_service_sid(
self,
phone_number: str,
) -> tuple[Optional[str], Optional[str]]:
if self.phone_number_is_messaging_service_sid(phone_number):
return None, phone_number
else:
Expand Down
20 changes: 20 additions & 0 deletions mypy.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[mypy]
python_version = 3.9

# Check configuration
warn_unused_configs = True
warn_redundant_casts = True

# Type checking
disallow_any_generics = True
check_untyped_defs = True
warn_unused_ignores = True
warn_return_any = True
strict_equality = True

# Parse but don't check imported libraries
follow_imports = silent
ignore_missing_imports = True

# Reporting
pretty = True
16 changes: 16 additions & 0 deletions mypy_modules.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
corehq/apps/app_manager/xform_builder.py
corehq/apps/case_search/xpath_functions/subcase_functions.py
corehq/apps/commtrack/fixtures.py
corehq/apps/domain/tests/test_forms.py
corehq/apps/es/tests/test_elastic_sync_multiplexed_command.py
corehq/apps/events/tests/test_tasks.py
corehq/apps/linked_domain/tests/test_migrate_feature_flag_domains.py
corehq/apps/reports/tests/test_case_data.py
corehq/apps/sms/forms.py
corehq/apps/userreports/models.py
corehq/apps/userreports/tests/test_data_source_config.py
corehq/apps/users/management/commands/add_data_dict_permissions.py
corehq/messaging/smsbackends/twilio/forms.py
corehq/messaging/smsbackends/twilio/models.py
corehq/motech/serializers.py
custom/onse/models.py
Loading