Skip to content

Commit

Permalink
feat: Add typehints to pyhf.tensor (#1940)
Browse files Browse the repository at this point in the history
* Add typehints to the NumPy backend.
* Add .coveragerc file with configuration to ignore pyhf/typing.py.
  - ref: https://coverage.readthedocs.io/en/6.4.3/excluding.html#advanced-exclusion
  - Reverts part of PR #1942.
* Ignore pyhf/typing.py in Codecov.
  • Loading branch information
kratsg authored Aug 26, 2022
1 parent f01dcf5 commit 3ac885e
Show file tree
Hide file tree
Showing 7 changed files with 166 additions and 92 deletions.
3 changes: 3 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[report]
omit =
src/pyhf/typing.py
12 changes: 10 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,18 @@ repos:

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.971
# check the oldest and newest supported Pythons
hooks:
- id: mypy
- &mypy
id: mypy
name: mypy with Python 3.7
files: src
args: []
additional_dependencies:
['numpy', 'types-tqdm', 'click', 'types-jsonpatch', 'types-pyyaml', 'types-jsonschema', 'importlib_metadata', 'packaging']
args: ["--python-version=3.7"]
- <<: *mypy
name: mypy with Python 3.10
args: ["--python-version=3.10"]

- repo: https://github.com/nbQA-dev/nbQA
rev: 1.4.0
Expand Down
3 changes: 3 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@ coverage:
project:
default:
threshold: 0.2%

ignore:
- "**/typing.py"
19 changes: 10 additions & 9 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -108,24 +108,19 @@ warn_unreachable = true

[[tool.mypy.overrides]]
module = [
'matplotlib.*',
'jax.*',
'click.*',
'click_completion.*',
'numpy.*',
'matplotlib.*',
'scipy.*',
'jsonpatch.*',
'tensorflow.*',
'tensorflow_probability.*',
'torch.*',
'uproot.*',
'yaml.*',
'jsonschema.*',
'tqdm.*',
]
ignore_missing_imports = true

[[tool.mypy.overrides]]
module = [
'pyhf',
'pyhf.tensor.*',
'pyhf.optimize.*',
'pyhf.contrib.*',
'pyhf.infer.*',
Expand All @@ -146,5 +141,11 @@ module = [
'pyhf.pdf',
'pyhf.simplemodels',
'pyhf.probability',
'pyhf.tensor.common.*',
'pyhf.tensor.manager.*',
'pyhf.tensor',
'pyhf.tensor.jax_backend.*',
'pyhf.tensor.tensorflow_backend.*',
'pyhf.tensor.pytorch_backend.*',
]
ignore_errors = true
2 changes: 1 addition & 1 deletion src/pyhf/readxml.py
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ def parse(
mounts = mounts or []
toplvl = ET.parse(configfile)
inputs = tqdm.tqdm(
[x.text for x in toplvl.findall('Input')],
[x.text for x in toplvl.findall('Input') if x.text],
unit='channel',
disable=not (track_progress),
)
Expand Down
Loading

0 comments on commit 3ac885e

Please sign in to comment.