Skip to content

Commit

Permalink
drop python 3.9 changes (#540)
Browse files Browse the repository at this point in the history
Category: CI
JIRA issue: https://jira.ihme.washington.edu/browse/MIC-5536

Changes and notes
Modernize type hinting
Remove unnecessary "from future import annotation" imports

Testing
Ran pytest.
  • Loading branch information
hussain-jafari authored Nov 13, 2024
1 parent 881d6b8 commit 13c1fbd
Show file tree
Hide file tree
Showing 46 changed files with 206 additions and 232 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
**3.2.1 - TBD/TBD/TBD**
**3.2.1 - 11/13/24**

- Fix mypy errors in vivarium/framework/results/context.py
- Modernize type hinting
- Remove unnecessary "from future import annotation" imports

**3.2.0 - 11/12/24**

Expand Down
4 changes: 2 additions & 2 deletions docs/source/concepts/results.rst
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ to the existing number of people who have died from previous time steps.

.. testcode::

from typing import Any, Optional
from typing import Any

import pandas as pd

Expand All @@ -84,7 +84,7 @@ to the existing number of people who have died from previous time steps.
}

@property
def columns_required(self) -> Optional[list[str]]:
def columns_required(self) -> list[str] | None:
return ["age", "alive"]

def register_observations(self, builder: Builder) -> None:
Expand Down
34 changes: 16 additions & 18 deletions src/vivarium/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
import re
import warnings
from abc import ABC
from collections.abc import Sequence
from collections.abc import Callable, Sequence
from datetime import datetime, timedelta
from importlib import import_module
from inspect import signature
from numbers import Number
from typing import TYPE_CHECKING, Any, Callable, Dict, List, Optional, Union
from typing import TYPE_CHECKING, Any

import pandas as pd
from layered_config_tree import ConfigurationError, LayeredConfigTree
Expand Down Expand Up @@ -87,7 +87,7 @@ class Component(ABC):
"""

CONFIGURATION_DEFAULTS: Dict[str, Any] = {}
CONFIGURATION_DEFAULTS: dict[str, Any] = {}
"""A dictionary containing the defaults for any configurations managed by this
component. An empty dictionary indicates no managed configurations.
"""
Expand Down Expand Up @@ -187,7 +187,7 @@ def population_view(self) -> PopulationView:
return self._population_view

@property
def sub_components(self) -> List["Component"]:
def sub_components(self) -> list["Component"]:
"""Provide components managed by this component.
Returns
Expand All @@ -198,7 +198,7 @@ def sub_components(self) -> List["Component"]:
return self._sub_components

@property
def configuration_defaults(self) -> Dict[str, Any]:
def configuration_defaults(self) -> dict[str, Any]:
"""Provides a dictionary containing the defaults for any configurations
managed by this component.
Expand All @@ -213,7 +213,7 @@ def configuration_defaults(self) -> Dict[str, Any]:
return self.CONFIGURATION_DEFAULTS

@property
def columns_created(self) -> List[str]:
def columns_created(self) -> list[str]:
"""Provides names of columns created by the component.
Returns
Expand All @@ -224,7 +224,7 @@ def columns_created(self) -> List[str]:
return []

@property
def columns_required(self) -> Optional[List[str]]:
def columns_required(self) -> list[str] | None:
"""Provides names of columns required by the component.
Returns
Expand All @@ -244,7 +244,7 @@ def initialization_requirements(
return []

@property
def population_view_query(self) -> Optional[str]:
def population_view_query(self) -> str | None:
"""Provides a query to use when filtering the component's `PopulationView`.
Returns
Expand Down Expand Up @@ -334,14 +334,12 @@ def __init__(self) -> None:
"""
self._repr: str = ""
self._name: str = ""
self._sub_components: List["Component"] = []
self.logger: Optional[Logger] = None
self.get_value_columns: Optional[
Callable[[Union[str, pd.DataFrame]], List[str]]
] = None
self.configuration: Optional[LayeredConfigTree] = None
self._population_view: Optional[PopulationView] = None
self.lookup_tables: Dict[str, LookupTable] = {}
self._sub_components: list["Component"] = []
self.logger: Logger | None = None
self.get_value_columns: Callable[[str | pd.DataFrame], list[str]] | None = None
self.configuration: LayeredConfigTree | None = None
self._population_view: PopulationView | None = None
self.lookup_tables: dict[str, LookupTable] = {}

def setup_component(self, builder: "Builder") -> None:
"""Sets up the component for a Vivarium simulation.
Expand Down Expand Up @@ -501,7 +499,7 @@ def on_simulation_end(self, event: Event) -> None:
# Helper methods #
##################

def get_initialization_parameters(self) -> Dict[str, Any]:
def get_initialization_parameters(self) -> dict[str, Any]:
"""Retrieves the values of all parameters specified in the `__init__` that
have an attribute with the same name.
Expand All @@ -521,7 +519,7 @@ def get_initialization_parameters(self) -> Dict[str, Any]:
if hasattr(self, parameter_name)
}

def get_configuration(self, builder: "Builder") -> Optional[LayeredConfigTree]:
def get_configuration(self, builder: "Builder") -> LayeredConfigTree | None:
"""Retrieves the configuration for this component from the builder.
This method retrieves the configuration for this component from the
Expand Down
4 changes: 2 additions & 2 deletions src/vivarium/examples/boids/forces.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# mypy: ignore-errors
from abc import ABC, abstractmethod
from typing import Any, Dict
from typing import Any

import numpy as np
import pandas as pd
Expand All @@ -14,7 +14,7 @@ class Force(Component, ABC):
# Properties #
##############
@property
def configuration_defaults(self) -> Dict[str, Any]:
def configuration_defaults(self) -> dict[str, Any]:
return {
self.__class__.__name__.lower(): {
"max_force": 0.03,
Expand Down
2 changes: 0 additions & 2 deletions src/vivarium/examples/disease_model/disease.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# mypy: ignore-errors
from __future__ import annotations

import pandas as pd

from vivarium import Component
Expand Down
6 changes: 3 additions & 3 deletions src/vivarium/examples/disease_model/intervention.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# mypy: ignore-errors
from typing import Any, Dict
from typing import Any

import pandas as pd

Expand All @@ -8,7 +8,7 @@


class TreatmentIntervention(Component):
CONFIGURATION_DEFAULTS: Dict[str, Any] = {
CONFIGURATION_DEFAULTS: dict[str, Any] = {
"intervention": {
"effect_size": 0.5,
}
Expand All @@ -19,7 +19,7 @@ class TreatmentIntervention(Component):
##############

@property
def configuration_defaults(self) -> Dict[str, Any]:
def configuration_defaults(self) -> dict[str, Any]:
return {self.intervention: self.CONFIGURATION_DEFAULTS["intervention"]}

#####################
Expand Down
6 changes: 3 additions & 3 deletions src/vivarium/examples/disease_model/mortality.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# mypy: ignore-errors
from typing import Any, Dict, List, Optional
from typing import Any

import numpy as np
import pandas as pd
Expand All @@ -15,7 +15,7 @@ class Mortality(Component):
##############

@property
def configuration_defaults(self) -> Dict[str, Any]:
def configuration_defaults(self) -> dict[str, Any]:
"""A set of default configuration values for this component.
These can be overwritten in the simulation model specification or by
Expand All @@ -28,7 +28,7 @@ def configuration_defaults(self) -> Dict[str, Any]:
}

@property
def columns_required(self) -> Optional[List[str]]:
def columns_required(self) -> list[str] | None:
return ["tracked", "alive"]

#####################
Expand Down
6 changes: 3 additions & 3 deletions src/vivarium/examples/disease_model/observer.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, Optional
from typing import Any

import pandas as pd

Expand All @@ -14,7 +14,7 @@ class DeathsObserver(Observer):
##############

@property
def columns_required(self) -> Optional[list[str]]:
def columns_required(self) -> list[str] | None:
return ["alive"]

#################
Expand All @@ -39,7 +39,7 @@ class YllsObserver(Observer):
##############

@property
def columns_required(self) -> Optional[list[str]]:
def columns_required(self) -> list[str] | None:
return ["age", "alive"]

@property
Expand Down
6 changes: 3 additions & 3 deletions src/vivarium/examples/disease_model/population.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# mypy: ignore-errors
from typing import Any, Dict, List
from typing import Any

import pandas as pd

Expand All @@ -17,7 +17,7 @@ class BasePopulation(Component):
##############

@property
def configuration_defaults(self) -> Dict[str, Any]:
def configuration_defaults(self) -> dict[str, Any]:
"""A set of default configuration values for this component.
These can be overwritten in the simulation model specification or by
Expand All @@ -33,7 +33,7 @@ def configuration_defaults(self) -> Dict[str, Any]:
}

@property
def columns_created(self) -> List[str]:
def columns_created(self) -> list[str]:
return ["age", "sex", "alive", "entrance_time"]

#####################
Expand Down
8 changes: 4 additions & 4 deletions src/vivarium/examples/disease_model/risk.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# mypy: ignore-errors
from __future__ import annotations

from typing import TYPE_CHECKING, Any, Dict, List
from typing import TYPE_CHECKING, Any

import pandas as pd

Expand All @@ -24,11 +24,11 @@ class Risk(Component):
##############

@property
def configuration_defaults(self) -> Dict[str, Any]:
def configuration_defaults(self) -> dict[str, Any]:
return {self.risk: self.CONFIGURATION_DEFAULTS["risk"]}

@property
def columns_created(self) -> List[str]:
def columns_created(self) -> list[str]:
return [self.propensity_column]

@property
Expand Down Expand Up @@ -91,7 +91,7 @@ class RiskEffect(Component):
##############

@property
def configuration_defaults(self) -> Dict[str, Any]:
def configuration_defaults(self) -> dict[str, Any]:
return {self.risk: self.CONFIGURATION_DEFAULTS["risk_effect"]}

#####################
Expand Down
2 changes: 0 additions & 2 deletions src/vivarium/framework/artifact/artifact.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
archive file for convenient access and inspection.
"""
from __future__ import annotations

import re
import warnings
from collections import defaultdict
Expand Down
Loading

0 comments on commit 13c1fbd

Please sign in to comment.