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 c972026 commit 74ccb42
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
8 changes: 8 additions & 0 deletions python/lsst/pipe/base/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,14 @@
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
from types import MappingProxyType, SimpleNamespace
from typing import TYPE_CHECKING, Any

from lsst.utils.introspection import find_outside_stacklevel
from lsst.daf.butler import DataCoordinate, DatasetRef, DatasetType, NamedKeyDict, NamedKeyMapping, Quantum
from lsst.utils.introspection import find_outside_stacklevel

Expand Down Expand Up @@ -361,6 +363,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
17 changes: 16 additions & 1 deletion tests/test_connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
"""

import unittest
import warnings

from lsst.pex.config import Field
import lsst.pipe.base as pipeBase
import lsst.utils.tests
import pytest
Expand Down Expand Up @@ -194,13 +196,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 74ccb42

Please sign in to comment.