Skip to content

Commit b3b8f64

Browse files
authored
Gradually introduce type checking (#50)
* set up type checking pre-commit * set up type checks for pgscatalog.core * add mypy action * don't use poetry for mypy * fix is_complex check * delete redundant functions
1 parent d5dd802 commit b3b8f64

File tree

10 files changed

+167
-46
lines changed

10 files changed

+167
-46
lines changed

.github/workflows/pytest.yaml

+18-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Run pytest
1+
name: Run pytest and mypy
22

33
on:
44
workflow_call:
@@ -62,3 +62,20 @@ jobs:
6262
fail_ci_if_error: true
6363
slug: PGScatalog/pygscatalog
6464
flags: ${{ inputs.package-directory }}
65+
66+
mypy:
67+
runs-on: ubuntu-latest
68+
69+
steps:
70+
- uses: actions/checkout@v4
71+
72+
- name: Install Python
73+
uses: actions/setup-python@v5
74+
with:
75+
python-version: ${{ inputs.python-version }}
76+
cache: 'pip'
77+
78+
- run: pip install mypy
79+
80+
- run: mypy # import to run in top level directory
81+

.pre-commit-config.yaml

+5
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,8 @@ repos:
55
- id: ruff
66
args: [ --fix ]
77
- id: ruff-format
8+
- repo: https://github.com/pre-commit/mirrors-mypy
9+
rev: 'v1.11.2' # Use the sha / tag you want to point at
10+
hooks:
11+
- id: mypy
12+
args: [--config-file, mypy.ini]

mypy.ini

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[mypy]
2+
files = pgscatalog.core/**/*.py
3+
exclude = [pgscatalog.calc, pgscatalog.match]
4+
5+
warn_unused_configs = True
6+
ignore_missing_imports = true
7+
follow_imports = silent
8+
disallow_untyped_calls = false
9+
disallow_incomplete_defs = true
10+

pgscatalog.core/mypy.ini

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../mypy.ini

pgscatalog.core/poetry.lock

+61-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pgscatalog.core/pyproject.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ pydantic = "^2.9.0"
2828
pytest = "^7.4.4"
2929
sphinx-autoapi = "^3.0.0"
3030
pytest-cov = "^4.1.0"
31+
mypy = "^1.11.2"
3132

3233
[build-system]
3334
requires = ["poetry-core"]
@@ -39,4 +40,4 @@ addopts = "-ra -q --doctest-modules"
3940
filterwarnings = ["error"]
4041

4142
[tool.coverage.run]
42-
source = ['src/pgscatalog/core']
43+
source = ['src/pgscatalog/core']

pgscatalog.core/src/pgscatalog/core/__init__.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
""" Public interface to the Polygenic Score Catalog core package """
1+
"""Public interface to the Polygenic Score Catalog core package"""
2+
23
import logging
34
import importlib.metadata
45

pgscatalog.core/src/pgscatalog/core/lib/_read.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
These functions aren't really meant to be imported outside corelib"""
33

44
import logging
5+
from typing import Generator, Iterator
56

67
from xopen import xopen
78

@@ -11,8 +12,13 @@
1112

1213

1314
def read_rows_lazy(
14-
*, csv_reader, fields: list[str], name: str, wide: bool, row_nr: int
15-
):
15+
*,
16+
csv_reader: Iterator[list[str]],
17+
fields: list[str],
18+
name: str,
19+
wide: bool,
20+
row_nr: int,
21+
) -> Generator[ScoreVariant, None, None]:
1622
"""Read rows from an open scoring file and instantiate them as ScoreVariants"""
1723
for row in csv_reader:
1824
variant = dict(zip(fields, row))

pgscatalog.core/src/pgscatalog/core/lib/_sortpaths.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
""" This module assumes you're working with paths that follow the format:
1+
"""This module assumes you're working with paths that follow the format:
22
33
{sampleset}_{chrom}_{effect_type}_{n}
44
"""
5+
56
from natsort import natsort_keygen, ns
67

78

0 commit comments

Comments
 (0)