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

Enforce type checking in tests and CI #885

Merged
merged 3 commits into from
Jun 18, 2019
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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ dist/
.tags*
.noseids
.pytest_cache

.mypy_cache
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

### 34.2.7 [#886](https://github.com/openfisca/openfisca-core/pull/885)

#### Minor change

- Enforce type checking in tests and Continuous Integration

### 34.2.6 [#886](https://github.com/openfisca/openfisca-core/pull/886)

#### Minor change
Expand Down
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ clean:
check-syntax-errors:
python -m compileall -q .

check-types:
mypy openfisca_core && mypy openfisca_web_api

check-style:
@# Do not analyse .gitignored files.
@# `make` needs `$$` to output `$`. Ref: http://stackoverflow.com/questions/2382764.
Expand All @@ -24,7 +27,7 @@ format-style:
@# `make` needs `$$` to output `$`. Ref: http://stackoverflow.com/questions/2382764.
autopep8 `git ls-files | grep "\.py$$"`

test: clean check-syntax-errors check-style
test: clean check-syntax-errors check-style check-types
env PYTEST_ADDOPTS="$$PYTEST_ADDOPTS --cov=openfisca_core" pytest

api:
Expand Down
5 changes: 3 additions & 2 deletions openfisca_core/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import sys
import logging
import traceback
from typing import Iterable, Optional

import yaml
import numpy as np
Expand All @@ -26,7 +27,7 @@
except ImportError:
log.warning(
"libyaml is not installed in your environment. This can make OpenFisca slower to start. Once you have installed libyaml, run 'pip uninstall pyyaml && pip install pyyaml --no-cache-dir' so that it is used in your Python environment." + os.linesep)
from yaml import Loader
from yaml import Loader # type: ignore # (see https://github.com/python/mypy/issues/1153#issuecomment-455802270)


FILE_EXTENSIONS = {'.yaml', '.yml'}
Expand Down Expand Up @@ -325,7 +326,7 @@ class ParameterNode(object):
A node in the legislation `parameter tree <https://openfisca.org/doc/coding-the-legislation/legislation_parameters.html>`_.
"""

_allowed_keys = None # By default, no restriction on the keys
_allowed_keys: Optional[Iterable[str]] = None # By default, no restriction on the keys

def __init__(self, name = "", directory_path = None, data = None, file_path = None):
"""
Expand Down
5 changes: 3 additions & 2 deletions openfisca_core/periods.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import datetime
import re
from os import linesep
from typing import Dict


DAY = 'day'
Expand All @@ -26,8 +27,8 @@ def N_(message):
return message


date_by_instant_cache = {}
str_by_instant_cache = {}
date_by_instant_cache: Dict = {}
str_by_instant_cache: Dict = {}
year_or_month_or_day_re = re.compile(r'(18|19|20)\d{2}(-(0?[1-9]|1[0-2])(-([0-2]?\d|3[0-1]))?)?$')


Expand Down
8 changes: 4 additions & 4 deletions openfisca_core/populations.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,10 @@ def members_position(self):

return self._members_position

@members_position.setter
def members_position(self, members_position):
self._members_position = members_position

@property
def members_entity_id(self):
return self._members_entity_id
Expand Down Expand Up @@ -274,10 +278,6 @@ def ordered_members_map(self):
def get_role(self, role_name):
return next((role for role in self.entity.flattened_roles if role.key == role_name), None)

@members_position.setter
def members_position(self, members_position):
self._members_position = members_position

# Aggregation persons -> entity

@projectable
Expand Down
3 changes: 2 additions & 1 deletion openfisca_core/tools/test_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import os
import traceback
import textwrap
from typing import Dict

import pytest

Expand Down Expand Up @@ -34,7 +35,7 @@ def import_yaml():

yaml, Loader = import_yaml()

_tax_benefit_system_cache = {}
_tax_benefit_system_cache: Dict = {}


def run_tests(tax_benefit_system, paths, options = None):
Expand Down
6 changes: 6 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,9 @@ in-place = true
addopts = --showlocals --doctest-modules --disable-pytest-warnings
testpaths = tests
python_files = **/*.py

[mypy]
ignore_missing_imports = True

[mypy-openfisca_core.scripts.*]
ignore_errors = True
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,14 @@
'flake8-bugbear >= 19.3.0, < 20.0.0',
'flake8-print >= 3.1.0, < 4.0.0',
'pytest-cov >= 2.6.1, < 3.0.0',
'mypy >= 0.701, < 0.800',
'openfisca-country-template >= 3.6.0rc0, < 4.0.0',
'openfisca-extension-template >= 1.2.0rc0, < 2.0.0'
] + api_requirements

setup(
name = 'OpenFisca-Core',
version = '34.2.6',
version = '34.2.7',
author = 'OpenFisca Team',
author_email = 'contact@openfisca.org',
classifiers = [
Expand Down