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

fix: compatibility with mypy 0.900 #232

Merged
merged 16 commits into from
Jun 21, 2021
Merged

Conversation

alexander-held
Copy link
Member

@alexander-held alexander-held commented Jun 9, 2021

With the release of mypy 0.900, third party type stubs need to be separately installed. This affects PyYAML and tabulate in the case of cabinetry. The new mypy version also revealed a small typing issue in the CLI that is fixed here.

pyhf 0.6.1 caps click to version below 8.0, which means types-click would temporarily be required until the release of pyhf 0.6.2 when running mypy outside of pre-commit.

The solution adopted here for compatibility with mypy 0.900+ is instead to move mypy to only run via pre-commit. It is still possible to run it directly manually by installing click 8.0+ (manual installation will no longer be required in pyhf 0.6.2, where the cap will be removed).

mypy runs in pre-commit with python-version set to both 3.7 and 3.8, following this example. The environment includes click 8.0 alongside the required types-* packages.

click>=8 is incompatible with typeguard ("object has no attribute '__code__'"), fixed in typeguard version 2.12.1. However, typeguard versions beyond 2.10.0 are incompatible with NamedTuple in Python 3.7 (see #199). At the moment the pyhf pin to click~=7 restricts that from becoming an issue, but the next pyhf release will make this issue evident. It is therefore fixed here already: the typeguard pin is removed, and typeguard is used in CI only for Python 3.8+.

List of changes:

  • mypy now runs via pre-commit, and the corresponding action in CI
  • typeguard pin removed, now runs in CI only for Python 3.8+
  • switched mypy config to use pyproject.toml instead of setup.cfg, allowing for simpler ignore_missing_imports configuration, example: style: simpler mypy toml config hist#230
  • applied suggested pyupgrade modification for list comprehension
  • small typing fix in CLI

@alexander-held alexander-held changed the title chore: compatibility with mypy 0.900 fix: compatibility with mypy 0.900 Jun 9, 2021
@codecov
Copy link

codecov bot commented Jun 9, 2021

Codecov Report

Merging #232 (bc74ab7) into master (10571e8) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##            master      #232   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           15        15           
  Lines         1727      1727           
  Branches       268       268           
=========================================
  Hits          1727      1727           
Impacted Files Coverage Δ
src/cabinetry/visualize.py 100.00% <ø> (ø)
src/cabinetry/cli/__init__.py 100.00% <100.00%> (ø)
src/cabinetry/configuration.py 100.00% <100.00%> (ø)
src/cabinetry/contrib/matplotlib_visualize.py 100.00% <100.00%> (ø)
src/cabinetry/fit.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 10571e8...bc74ab7. Read the comment docs.

@alexander-held alexander-held merged commit e773941 into master Jun 21, 2021
@alexander-held alexander-held deleted the chore/mypy-type-stubs branch June 21, 2021 16:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant