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
[SUPPORT] How to Check Test files by Mypy CI #15
Comments
Try adding this to your setup.cfg: [mypy]
warn_unused_configs = True
pretty = True
files = src
check_untyped_defs = True I don't think you need the files selection in the MyPy hook above. The important line is the last one, I bet that will start showing a few errors. Normally MyPy only looks inside functions with at least one annotation. |
Also note that when MyPy runs, it will be in a custom environment, so if you want any things added to the environment, you will have to list them. Probably won't need anything. special, though, at least until boost-histogram provides external typing. |
You will need to ignore missing imports for now, such as: [mypy-boost_histogram]
ignore_missing_imports = True |
@henryiii Thx! After I modify the I conducted an experiment to testify its functionality. I used the wrong type in test_name.py like h = NamedHist(axis.Regular("10", 0, 1, name="x")).fill(x=[0.35, 0.35, 0.45]) # bin should be int and added function annotations for Regular axis def __init__(
self,
bins: int,
start: int,
stop: int,
....
): But this error escapes from the check of mypy pre-commit check. Do U have any idea why it could? |
We could pass the pre-commit, if it doesn't contain other errors, without missing imports currently (BH's type hints seem not to be considered by mypy right now). So I am not sure about the usage of this line. Nevertheless, it doesn't hurt and I have added it :) |
We don't run MyPy on the tests. Generally, units tests may test things that are not allowed by a type checker. For example, you may test passing a float or a string to bins to see what error is thrown (and an exact float might be supported instead of an int), but the type checker will request a user put an int here. We probably could run the type checker on examples, but I think we have to add "py.typed" files in all directories in src/hist to get that to work (that tells python that this package supports type checking by things outside this package). |
Break your assumption of |
Maybe I'm doing the right thing, but have no idea how to make some counterexamples to test the functionality of mypy CI. |
* NamedHist init * black reformat * allow Hist axes not to have names * ToDo: forbid non-named NamedHist * Update named.py * better-styled derive * forbid no-named/duplic axes for NamedHist * force names everywhere * add mypy to pre-commit * Update NamedHist.ipynb * Update dev-environment.yml * add tests of NamedHist * Update setup.cfg * Update dev-environment.yml * Update mypy CI check in #15 * rm py3.6 for annotations * solved #13 (comment) * typing hints added * add basic_tests for StrCategory * add py3.6 * numpy to core.py * rm __future__.annotations * correct regular expression of valid Py identifier * add tests for exceptions
Looks good, currently. |
Describe your questions
I have used mypy according to https://scikit-hep.org/developer/style#type-checking-new. My pre-commit profig file is like this:
I deliberately put a type error in a test file, but pre-commit did not find it. How to make mypy CI work for unit tests?
The text was updated successfully, but these errors were encountered: