LSSTApplications  18.0.0+68,19.0.0+5,19.0.0+56,19.0.0+65,19.0.0+9,19.0.0-1-g20d9b18+24,19.0.0-1-g49a97f9+3,19.0.0-1-g5549ca4+4,19.0.0-1-g8c57eb9+24,19.0.0-1-g9a028c0+1,19.0.0-1-ga72da6b+3,19.0.0-1-gb77924a+1,19.0.0-1-gbfe0924+52,19.0.0-1-gd0f30f5+1,19.0.0-1-ge272bc4+24,19.0.0-1-gefe1d0d+38,19.0.0-11-g57ef05f+3,19.0.0-11-g90346d2c+1,19.0.0-13-g8db0348+6,19.0.0-14-g706b86db4+2,19.0.0-15-g9352a82,19.0.0-16-g224c443+1,19.0.0-16-gdc8ce7c+3,19.0.0-2-g0d9f9cd+61,19.0.0-2-g260436e+42,19.0.0-2-g361aba8+1,19.0.0-2-g9675b69+3,19.0.0-2-gde8e5e3+3,19.0.0-2-gff6972b+8,19.0.0-3-ga642a0f,19.0.0-4-g33ce3a3+1,19.0.0-4-gac56cce+3,19.0.0-4-gb4013cc+1,19.0.0-4-gdb4f201+1,19.0.0-41-g13db8fbc+3,19.0.0-43-gbcf6a3c+2,19.0.0-6-gdd6eb13,19.0.0-7-g686a884+4,w.2020.15
LSSTDataManagementBasePackage
deprecated.py
Go to the documentation of this file.
1 # This file is part of ip_diffim.
2 #
3 # Developed for the LSST Data Management System.
4 # This product includes software developed by the LSST Project
5 # (http://www.lsst.org).
6 # See the COPYRIGHT file at the top-level directory of this distribution
7 # for details of code ownership.
8 #
9 # This program is free software: you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation, either version 3 of the License, or
12 # (at your option) any later version.
13 #
14 # This program is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
18 #
19 # You should have received a copy of the GNU General Public License
20 # along with this program. If not, see <http://www.gnu.org/licenses/>.
21 __all__ = ["deprecate_policy"]
22 
23 import warnings
24 import functools
25 from lsst.pex.policy import Policy
26 
27 
28 def deprecate_policy(func, policy_args=None):
29  """Issue a deprecation warning if one of the supplied arguments
30  is a Policy, and convert that to a PropertySet.
31 
32  Parameters
33  ----------
34  policy_args : `~collections.abc.Sequence`, optional
35  Known positions of likely `~lsst.pex.Policy` arguments for the wrapped
36  function. Can be out of range since some pybind11 constructors take
37  different numbers of arguments. If `None` all arguments will be
38  checked.
39  """
40 
41  @functools.wraps(func)
42  def internal(*args, **kwargs):
43  newargs = list(args)
44 
45  if policy_args is None:
46  # Check all arguments
47  args_to_check = range(len(args))
48  else:
49  max_i = len(newargs) - 1
50  args_to_check = [p for p in policy_args if p <= max_i]
51 
52  for i in args_to_check:
53  a = newargs[i]
54  if isinstance(a, Policy):
55  warnings.warn(f"pexPolicy in argument {i} is deprecated. Replace with PropertySet"
56  " (Policy support will be removed in v19)",
57  FutureWarning, stacklevel=2)
58  a = a.asPropertySet()
59  newargs[i] = a
60  return func(*newargs, **kwargs)
61 
62  return internal
def deprecate_policy(func, policy_args=None)
Definition: deprecated.py:28
daf::base::PropertyList * list
Definition: fits.cc:903