Skip to content

Commit

Permalink
Warn about deprecated connections that are not removed.
Browse files Browse the repository at this point in the history
  • Loading branch information
TallJimbo committed Jul 5, 2023
1 parent dd1a135 commit 9c7b402
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
7 changes: 7 additions & 0 deletions python/lsst/pipe/base/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import dataclasses
import itertools
import string
import warnings
from collections import UserDict
from collections.abc import Collection, Generator, Iterable, Mapping, Sequence, Set
from dataclasses import dataclass
Expand Down Expand Up @@ -361,6 +362,12 @@ def __call__(cls, *, config: PipelineTaskConfig | None = None) -> PipelineTaskCo
instance._allConnections.clear()
instance._allConnections.update(updated_all_connections)

for obj in instance._allConnections.values():
if obj.deprecated is not None:
warnings.warn(
obj.deprecated, FutureWarning, stacklevel=find_outside_stacklevel("lsst.pipe.base")
)

# Freeze the connection instance dimensions now. This at odds with the
# type annotation, which says [mutable] `set`, just like the connection
# type attributes (e.g. `inputs`, `outputs`, etc.), though MyPy can't
Expand Down
16 changes: 15 additions & 1 deletion tests/test_connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"""

import unittest
import warnings

import lsst.pipe.base as pipeBase
import lsst.utils.tests
Expand Down Expand Up @@ -194,13 +195,26 @@ class TestConnections(pipeBase.PipelineTaskConnections, dimensions=self.test_dim
deprecated="Deprecated in v50000, will be removed after v50001.",
)

def __init__(self, config):
if config.drop_input1:
del self.input1

class TestConfig(pipeBase.PipelineTaskConfig, pipelineConnections=TestConnections):
pass
drop_input1 = Field("Remove the 'input1' connection if True", dtype=bool, default=False)

config = TestConfig()
with self.assertWarns(FutureWarning):
config.connections.input1 = "some_other_dataset_type"

with self.assertWarns(FutureWarning):
TestConnections(config=config)

config.drop_input1 = True

with warnings.catch_warnings():
warnings.simplefilter("error", FutureWarning)
TestConnections(config=config)


class MyMemoryTestCase(lsst.utils.tests.MemoryTestCase):
pass
Expand Down

0 comments on commit 9c7b402

Please sign in to comment.