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

Switch to mypy part0 #6470

Merged
merged 27 commits into from
Oct 19, 2020
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
4900944
remove pytype and setup mypy
m-vdb Aug 21, 2020
661ab0b
fix wrong type annotations
m-vdb Aug 21, 2020
0d35a59
update mypy config to ignore current errors
m-vdb Aug 26, 2020
684df65
Merge branch 'master' into switch-to-mypy
m-vdb Aug 26, 2020
ee42c23
Merge branch 'master' into switch-to-mypy
m-vdb Aug 31, 2020
1b553ab
Merge branch 'master' into switch-to-mypy
m-vdb Sep 2, 2020
17f125d
keep pytype around during transition
m-vdb Sep 3, 2020
199f7b9
Merge branch 'master' into switch-to-mypy
m-vdb Sep 3, 2020
c559a9f
Merge branch 'master' into switch-to-mypy
m-vdb Sep 28, 2020
077d5df
Merge branch 'master' into switch-to-mypy
m-vdb Oct 12, 2020
cef6a96
fix typing annotation
m-vdb Oct 12, 2020
85c785d
disable error codes one by one
m-vdb Oct 12, 2020
e232d1a
remove pytype completely
m-vdb Oct 14, 2020
cbb6182
Update CONTRIBUTING.md to refer to `mypy`
m-vdb Oct 14, 2020
3d0bf71
Fix type hint in DIET classifier
m-vdb Oct 14, 2020
5ffd764
Fix type hint in TED policy
m-vdb Oct 14, 2020
059dd54
explain why we ignore missing imports
m-vdb Oct 14, 2020
f1f1c01
Merge branch 'master' into switch-to-mypy
m-vdb Oct 14, 2020
7fa00f4
remove pytype annotations
m-vdb Oct 14, 2020
a7cb682
remove pytype related comments + code
m-vdb Oct 14, 2020
c6a3ec3
add changelog fragment
m-vdb Oct 14, 2020
a36d598
Revert "remove pytype annotations"
m-vdb Oct 16, 2020
8980e04
remove pytype annotations
m-vdb Oct 16, 2020
90597cc
Merge branch 'master' into switch-to-mypy
m-vdb Oct 16, 2020
4067a4b
remove more pytype comments
m-vdb Oct 19, 2020
df3b79f
Merge branch 'master' into switch-to-mypy
m-vdb Oct 19, 2020
7114fb8
remove unnecessary new lines
m-vdb Oct 19, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/continous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ jobs:
- name: Check Types 📚
run: make types

- name: Check Types (old) 📚
m-vdb marked this conversation as resolved.
Show resolved Hide resolved
run: make types-old

- name: Test CLI 🖥
# makes sure we catch any dependency error early. they will create strange
# errors during the docs build, so easier to catch them early on by
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ venv
.ruby-version
.tox
.pytype
.mypy_cache/
dist/
pip-wheel-metadata
server/
Expand Down
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,15 @@ If your PR is greater than 500 lines, please consider splitting it into multiple

#### Code style

To ensure a standardized code style we recommend using formatter black. To ensure our type annotations are correct we also suggest using the type checker pytype.
To ensure a standardized code style we recommend using formatter black. To ensure our type annotations are correct we also suggest using the type checker `mypy`.

#### Formatting and Type Checking

If you want to automatically format your code on every commit, you can use pre-commit. Just install it via `pip install pre-commit` and execute `pre-commit install` in the root folder. This will add a hook to the repository, which reformats files on every commit.

If you want to set it up manually, install black via `pip install -r requirements-dev.txt.` To reformat files execute `make formatter`.

If you want to check types on the codebase, install pytype using `pip install -r requirements-dev.txt`. To check the types execute `make types`.
If you want to check types on the codebase, install `mypy` using `pip install -r requirements-dev.txt`. To check the types execute `make types`.
m-vdb marked this conversation as resolved.
Show resolved Hide resolved

The CI/CD tests that we run can be found in the [continous-integration.yml](https://github.com/RasaHQ/rasa/blob/master/.github/workflows/continous-integration.yml) file.

Expand Down
28 changes: 26 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ help:
@echo " lint"
@echo " Lint code with flake8, and check if black formatter should be applied."
@echo " types"
@echo " Check for type errors using pytype."
@echo " Check for type errors using mypy."
@echo " prepare-tests-ubuntu"
@echo " Install system requirements for running tests on Ubuntu and Debian based systems."
@echo " prepare-tests-macos"
Expand All @@ -37,7 +37,7 @@ clean:
find . -name '*.pyo' -exec rm -f {} +
find . -name '*~' -exec rm -f {} +
rm -rf build/
rm -rf .pytype/
rm -rf .mypy_cache/
rm -rf dist/
rm -rf docs/build
rm -rf docs/.docusaurus
Expand All @@ -63,6 +63,30 @@ lint:
poetry run black --check rasa tests

types:
# FIXME: working our way towards removing these
# see https://github.com/RasaHQ/rasa/pull/6470
# the list below is sorted by the number of errors for each error code, in decreasing order
poetry run mypy rasa --disable-error-code arg-type \
--disable-error-code assignment \
--disable-error-code var-annotated \
--disable-error-code return-value \
--disable-error-code union-attr \
--disable-error-code override \
--disable-error-code operator \
--disable-error-code attr-defined \
--disable-error-code index \
--disable-error-code misc \
--disable-error-code return \
--disable-error-code call-arg \
--disable-error-code type-var \
--disable-error-code list-item \
--disable-error-code has-type \
--disable-error-code valid-type \
--disable-error-code dict-item \
--disable-error-code no-redef \
--disable-error-code func-returns-value

types-old:
poetry run pytype --keep-going rasa -j 16

prepare-tests-files:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ make formatter

#### Type Checking

If you want to check types on the codebase, install `pytype` using `poetry install`.
If you want to check types on the codebase, install `mypy` using `poetry install`.
m-vdb marked this conversation as resolved.
Show resolved Hide resolved
To check the types execute
```
make types
Expand Down
62 changes: 59 additions & 3 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@ fakeredis = "^1.4.0"
mongomock = "^3.18.0"
black = "^19.10b0"
flake8 = "^3.8.3"
pytype = "^2020.6.1"
google-cloud-storage = "^1.29.0"
azure-storage-blob = "<12.6.0"
coveralls = "^2.0.0"
Expand All @@ -152,6 +151,8 @@ toml = "^0.10.0"
pep440-version-utils = "^0.3.0"
pydoc-markdown = "^3.5.0"
pytest-timeout = "^1.4.2"
pytype = "^2020.6.1"
m-vdb marked this conversation as resolved.
Show resolved Hide resolved
mypy = "^0.790"

[tool.poetry.extras]
spacy = [ "spacy",]
Expand Down
3 changes: 2 additions & 1 deletion rasa/core/policies/ted_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,8 @@ def __init__(
self.action_acc = tf.keras.metrics.Mean(name="acc")
self.metrics_to_log += ["loss", "acc"]

self.all_labels_embed = None # needed for efficient prediction
# needed for efficient prediction
self.all_labels_embed: Optional[Tuple[tf.Tensor, tf.Tensor]] = None
m-vdb marked this conversation as resolved.
Show resolved Hide resolved

self._prepare_layers()

Expand Down
4 changes: 3 additions & 1 deletion rasa/nlu/classifiers/diet_classifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -1115,7 +1115,9 @@ def __init__(
self._create_metrics()
self._update_metrics_to_log()

self.all_labels_embed = None # needed for efficient prediction
# needed for efficient prediction
self.all_labels_embed: Optional[Tuple[tf.Tensor, tf.Tensor]] = None
m-vdb marked this conversation as resolved.
Show resolved Hide resolved

self._prepare_layers()

@staticmethod
Expand Down
2 changes: 1 addition & 1 deletion rasa/utils/tensorflow/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -666,7 +666,7 @@ def __init__(
)

# set up tf layers
self._tf_layers: Dict[Text : tf.keras.layers.Layer] = {}
self._tf_layers: Dict[Text, tf.keras.layers.Layer] = {}
wochinge marked this conversation as resolved.
Show resolved Hide resolved

def _check_data(self) -> None:
raise NotImplementedError
Expand Down
7 changes: 7 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,10 @@ log_cli_level = WARNING
[flake8]
max-line-length = 88
ignore = W503, E121, E126, E211, E225, E501, E203, E402, F401, F811, E231

[mypy]
ignore_missing_imports = True
m-vdb marked this conversation as resolved.
Show resolved Hide resolved
show_error_codes = True
warn_redundant_casts = True
warn_unused_ignores = True
# FIXME: more configuration using the --disable-error-code CLI argument (see types directive in Makefile)