diff --git a/python/lsst/pipe/base/config.py b/python/lsst/pipe/base/config.py index 21afc3ba5..6e16a17cf 100644 --- a/python/lsst/pipe/base/config.py +++ b/python/lsst/pipe/base/config.py @@ -146,7 +146,10 @@ def __new__( docString = "Template parameter used to format corresponding field template parameter" for templateName, default in connectionsClass.defaultTemplates.items(): configConnectionsNamespace[templateName] = TemplateField( - dtype=str, doc=docString, default=default + dtype=str, + doc=docString, + default=default, + deprecated=connectionsClass.deprecatedTemplates.get(templateName), ) # add a reference to the connection class used to create this sub # config diff --git a/python/lsst/pipe/base/connections.py b/python/lsst/pipe/base/connections.py index 54286b9f8..9f442975c 100644 --- a/python/lsst/pipe/base/connections.py +++ b/python/lsst/pipe/base/connections.py @@ -224,14 +224,20 @@ def __new__(cls, name, bases, dct, **kwargs): # look up any template from base classes and merge them all # together mergeDict = {} + mergeDeprecationsDict = {} for base in bases[::-1]: if hasattr(base, "defaultTemplates"): mergeDict.update(base.defaultTemplates) + if hasattr(base, "deprecatedTemplates"): + mergeDeprecationsDict.update(base.deprecatedTemplates) if "defaultTemplates" in kwargs: mergeDict.update(kwargs["defaultTemplates"]) - + if "deprecatedTemplates" in kwargs: + mergeDeprecationsDict.update(kwargs["deprecatedTemplates"]) if len(mergeDict) > 0: kwargs["defaultTemplates"] = mergeDict + if len(mergeDeprecationsDict) > 0: + kwargs["deprecatedTemplates"] = mergeDeprecationsDict # Verify that if templated strings were used, defaults were # supplied as an argument in the declaration of the connection @@ -258,6 +264,7 @@ def __new__(cls, name, bases, dct, **kwargs): f" (conflicts are {nameTemplateIntersection})." ) dct["defaultTemplates"] = kwargs.get("defaultTemplates", {}) + dct["deprecatedTemplates"] = kwargs.get("deprecatedTemplates", {}) # Convert all the connection containers into frozensets so they cannot # be modified at the class scope diff --git a/tests/test_connections.py b/tests/test_connections.py index 8317332e3..7d088c926 100644 --- a/tests/test_connections.py +++ b/tests/test_connections.py @@ -187,10 +187,15 @@ class TestConnectionsWithBrokenDimensionsIter(pipeBase.PipelineTask, dimensions= def test_deprecation(self) -> None: """Test support for deprecating connections.""" - class TestConnections(pipeBase.PipelineTaskConnections, dimensions=self.test_dims): + class TestConnections( + pipeBase.PipelineTaskConnections, + dimensions=self.test_dims, + defaultTemplates={"t1": "dataset_type_1"}, + deprecatedTemplates={"t1": "Deprecated in v600, will be removed after v601."}, + ): input1 = pipeBase.connectionTypes.Input( doc="Docs for input1", - name="input1_dataset_type", + name="input1_{t1}", storageClass="StructuredDataDict", deprecated="Deprecated in v50000, will be removed after v50001.", ) @@ -204,7 +209,9 @@ class TestConfig(pipeBase.PipelineTaskConfig, pipelineConnections=TestConnection config = TestConfig() with self.assertWarns(FutureWarning): - config.connections.input1 = "some_other_dataset_type" + config.connections.input1 = "dataset_type_2" + with self.assertWarns(FutureWarning): + config.connections.t1 = "dataset_type_3" with self.assertWarns(FutureWarning): TestConnections(config=config)