From 71785c2d77b2ab44c6b45fcc6ba8954edc2a43a4 Mon Sep 17 00:00:00 2001 From: "Kevin R. Thornton" Date: Thu, 9 Nov 2023 10:09:52 -0800 Subject: [PATCH] Deprecate use of None for a demographic model. --- doc/misc/deprecated.md | 6 ++++++ fwdpy11/_evolvets.py | 5 +++-- fwdpy11/_types/model_params.py | 8 +++++--- tests/test_add_mutation.py | 3 +++ 4 files changed, 17 insertions(+), 5 deletions(-) diff --git a/doc/misc/deprecated.md b/doc/misc/deprecated.md index c241425a5e..271da14006 100644 --- a/doc/misc/deprecated.md +++ b/doc/misc/deprecated.md @@ -10,4 +10,10 @@ python -Wd ``` +To treat all warning as errors: +```{code-block} bash + +python -We + +``` diff --git a/fwdpy11/_evolvets.py b/fwdpy11/_evolvets.py index 9830d35d50..9ce3b32553 100644 --- a/fwdpy11/_evolvets.py +++ b/fwdpy11/_evolvets.py @@ -129,8 +129,9 @@ def evolvets( sizes = pop.deme_sizes()[1].tolist() msg = "Applying a default demographic model " msg += f"where deme sizes are {sizes} " - msg += f"and the burn-in length is 10*{sum(sizes)}" - warnings.warn(msg, stacklevel=2) + msg += f"and the burn-in length is 10*{sum(sizes)}. " + msg += "This will raise an error in future releases." + warnings.warn(msg, DeprecationWarning, stacklevel=2) demographic_model = ForwardDemesGraph.tubes(sizes, 10) for r in params.sregions: diff --git a/fwdpy11/_types/model_params.py b/fwdpy11/_types/model_params.py index f15178719e..36a65076c3 100644 --- a/fwdpy11/_types/model_params.py +++ b/fwdpy11/_types/model_params.py @@ -186,9 +186,8 @@ class ModelParams(object): recregions = attr.ib(factory=list) rates: MutationAndRecombinationRates = attr.ib(converter=_convert_rates) gvalue = attr.ib(default=None) - demography: typing.Optional[typing.Union[ForwardDemesGraph, - DemographicModelDetails]] = attr.ib( - default=None) + demography: typing.Union[ForwardDemesGraph, + DemographicModelDetails] = attr.ib(default=None) simlen: int = attr.ib(converter=int, default=0) prune_selected: bool = attr.ib(default=True) allow_residual_selfing: bool = attr.ib(default=True) @@ -290,6 +289,9 @@ def validate_gvalue(self, attribute, value): @demography.validator def validate_demography(self, attribute, value): if value is None: + warnings.warn("No demographic model specified." + " This will be a hard error in a future release.", + DeprecationWarning) return if isinstance(value, fwdpy11.ForwardDemesGraph): diff --git a/tests/test_add_mutation.py b/tests/test_add_mutation.py index 2879dc8354..80367eb84c 100644 --- a/tests/test_add_mutation.py +++ b/tests/test_add_mutation.py @@ -48,6 +48,9 @@ def generate_msprime_ancestry( "recregions": [fwdpy11.PoissonInterval(0, 1, 5e-2)], "gvalue": fwdpy11.Multiplicative(2.0), "rates": (0, 0, None), + "demography": fwdpy11.ForwardDemesGraph.tubes([pop.N], + burnin=10*pop.N, + burnin_is_exact=True), "prune_selected": False, "simlen": 10 * pop.N, }