Skip to content

Commit acc736a

Browse files
drop python 3.9 support (#119)
Category: other JIRA issue: MIC-5489 Changes and notes Drop Python 3.9 support. Use built in list, dicts, and tuples Use pipe syntax instead of Union or Optional. Testing Built templates and compared to current templates.
1 parent 8c46ed5 commit acc736a

19 files changed

+139
-117
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
build:
1515
strategy:
1616
matrix:
17-
python-version: ["3.9", "3.10", "3.11"]
17+
python-version: ["3.10", "3.11"]
1818
uses:
1919
ihmeuw/vivarium_build_utils/.github/workflows/build.yml@main
2020
with:

CHANGELOG.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
**4.1.0 - 11/06/24**
2+
3+
- Drop support for Python 3.9
4+
- Modernize type hints
5+
- Update imports written by builders to be isort compliant
6+
17
**4.0.0 - 05/20/24**
28

39
- Rebuild with GBD 2021 data

docs/source/conf.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
"sphinx.ext.mathjax",
6161
"sphinx.ext.napoleon",
6262
"sphinx.ext.viewcode",
63+
"sphinx_autodoc_typehints",
6364
]
6465

6566
# Add any paths that contain templates here, relative to this directory.

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
doc_requirements = [
3737
"sphinx>=6.2.1, <7.0",
3838
"sphinx-rtd-theme",
39+
"sphinx-autodoc-typehints",
3940
]
4041

4142
lint_requirements = [

src/gbd_mapping/base_template.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
55
Any manual changes will be lost.
66
"""
7-
from typing import Tuple, Union
8-
97
from .id import c_id, cov_id, hs_id, me_id, rei_id, s_id, scalar
108

119

@@ -19,7 +17,7 @@ def to_dict(self):
1917
attr = getattr(self, item)
2018
if isinstance(attr, GbdRecord):
2119
out[item] = attr.to_dict()
22-
elif isinstance(attr, Tuple) and attr:
20+
elif isinstance(attr, tuple) and attr:
2321
if isinstance(attr[0], GbdRecord):
2422
out[item] = tuple(r.to_dict() for r in attr)
2523
elif attr is not None:
@@ -70,7 +68,8 @@ class ModelableEntity(GbdRecord):
7068
def __init__(self,
7169
name: str,
7270
kind: str,
73-
gbd_id: Union[c_id, s_id, hs_id, me_id, cov_id, rei_id, None], ):
71+
gbd_id: c_id | s_id | hs_id | me_id | cov_id | rei_id | None,
72+
):
7473
super().__init__()
7574
self.name = name
7675
self.kind = kind

src/gbd_mapping/cause_template.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
55
Any manual changes will be lost.
66
"""
7-
from typing import Tuple, Union
7+
from __future__ import annotations
88

99
from .base_template import GbdRecord, ModelableEntity, Restrictions
1010
from .etiology_template import Etiology
@@ -21,14 +21,14 @@ def __init__(self,
2121
name: str,
2222
kind: str,
2323
gbd_id: c_id,
24-
me_id: Union[me_id, Unknown],
24+
me_id: me_id | Unknown,
2525
most_detailed: bool,
2626
level: int,
2727
restrictions: Restrictions,
28-
parent: "Cause" = None,
29-
sub_causes: Tuple["Cause", ...] = None,
30-
sequelae: Tuple[Sequela, ...] = None,
31-
etiologies: Tuple[Etiology, ...] = None, ):
28+
parent: Cause | None = None,
29+
sub_causes: tuple[Cause, ...] | None = None,
30+
sequelae: tuple[Sequela, ...] | None = None,
31+
etiologies: tuple[Etiology, ...] | None = None, ):
3232
super().__init__(name=name,
3333
kind=kind,
3434
gbd_id=gbd_id)

src/gbd_mapping/covariate_template.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
55
Any manual changes will be lost.
66
"""
7-
from typing import Union
8-
97
from .base_template import GbdRecord, ModelableEntity
108
from .id import cov_id
119

@@ -17,7 +15,7 @@ class Covariate(ModelableEntity):
1715
def __init__(self,
1816
name: str,
1917
kind: str,
20-
gbd_id: Union[cov_id, None],
18+
gbd_id: cov_id | None,
2119
by_age: bool,
2220
by_sex: bool,
2321
dichotomous: bool, ):

src/gbd_mapping/etiology_template.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
55
Any manual changes will be lost.
66
"""
7-
from typing import Union
8-
97
from .base_template import GbdRecord, ModelableEntity
108
from .id import rei_id
119

@@ -17,7 +15,7 @@ class Etiology(ModelableEntity):
1715
def __init__(self,
1816
name: str,
1917
kind: str,
20-
gbd_id: Union[rei_id, None], ):
18+
gbd_id: rei_id | None, ):
2119
super().__init__(name=name,
2220
kind=kind,
2321
gbd_id=gbd_id)

src/gbd_mapping/risk_factor_template.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
55
Any manual changes will be lost.
66
"""
7-
from typing import Tuple, Union
7+
from __future__ import annotations
88

99
from .base_template import Categories, GbdRecord, ModelableEntity, Restrictions, Tmred
1010
from .cause_template import Cause
@@ -24,14 +24,14 @@ def __init__(self,
2424
gbd_id: rei_id,
2525
level: int,
2626
most_detailed: bool,
27-
distribution: Union[str, None],
27+
distribution: str | None,
2828
population_attributable_fraction_calculation_type: str,
2929
restrictions: Restrictions,
30-
affected_causes: Tuple[Cause, ...],
31-
population_attributable_fraction_of_one_causes: Tuple[Cause, ...],
32-
parent: Union["RiskFactor", None] = None,
33-
sub_risk_factors: Tuple["RiskFactor", ...] = None,
34-
affected_risk_factors: Tuple["RiskFactor", ...] = None,
30+
affected_causes: tuple[Cause, ...],
31+
population_attributable_fraction_of_one_causes: tuple[Cause, ...],
32+
parent: RiskFactor | None = None,
33+
sub_risk_factors: tuple[RiskFactor, ...] = None,
34+
affected_risk_factors: tuple[RiskFactor, ...] = None,
3535
categories: Categories = None,
3636
tmred: Tmred = None,
3737
relative_risk_scalar: scalar = None, ):

src/gbd_mapping_generator/base_template_builder.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from .util import SPACING, make_import, make_module_docstring, make_record
1+
from .util import DOUBLE_SPACING, make_import, make_module_docstring, make_record
22

33
IMPORTABLES_DEFINED = ("GbdRecord", "ModelableEntity", "Restrictions", "Tmred", "Categories")
44

@@ -7,7 +7,7 @@
77
modelable_entity_attrs = (
88
("name", "str"),
99
("kind", "str"),
10-
("gbd_id", "Union[c_id, s_id, hs_id, me_id, cov_id, rei_id, None]"),
10+
("gbd_id", "c_id | s_id | hs_id | me_id | cov_id | rei_id | None"),
1111
)
1212
restrictions_attrs = (
1313
("male_only", "bool"),
@@ -64,7 +64,7 @@ def to_dict(self):
6464
attr = getattr(self, item)
6565
if isinstance(attr, GbdRecord):
6666
out[item] = attr.to_dict()
67-
elif isinstance(attr, Tuple) and attr:
67+
elif isinstance(attr, tuple) and attr:
6868
if isinstance(attr[0], GbdRecord):
6969
out[item] = tuple(r.to_dict() for r in attr)
7070
elif attr is not None:
@@ -121,7 +121,6 @@ def build_mapping() -> str:
121121
122122
"""
123123
templates = make_module_docstring("Template classes for GBD entities", __file__)
124-
templates += make_import("typing", ["Union", "Tuple"])
125124
templates += (
126125
make_import(
127126
".id",
@@ -135,12 +134,12 @@ def build_mapping() -> str:
135134
"scalar",
136135
],
137136
)
138-
+ SPACING
137+
+ DOUBLE_SPACING
139138
)
140139
templates += make_gbd_record()
141140

142141
for entity, info in get_base_types().items():
143-
templates += SPACING
142+
templates += DOUBLE_SPACING
144143
templates += make_record(entity, **info)
145144

146145
return templates

0 commit comments

Comments
 (0)