diff --git a/news/remove-setscattering.rst b/news/remove-setscattering.rst new file mode 100644 index 0000000..f470fcd --- /dev/null +++ b/news/remove-setscattering.rst @@ -0,0 +1,4 @@ +**Removed:** + +* Remove the deprecated ``setScatteringFactorTableByType`` method from + ``ScatteringFactorTableOwner``, ``PDFCalculator``, and ``DebyePDFCalculator``. diff --git a/src/extensions/wrap_PDFCalculators.cpp b/src/extensions/wrap_PDFCalculators.cpp index a71b5ef..0190859 100644 --- a/src/extensions/wrap_PDFCalculators.cpp +++ b/src/extensions/wrap_PDFCalculators.cpp @@ -175,19 +175,9 @@ Use PeakWidthModel.getRegisteredTypes() for a set of registered names.\n\ const char* doc_ScatteringFactorTableOwner_scatteringfactortable = "\ ScatteringFactorTable object used for a lookup of scattering factors.\n\ -This can be also set with the setScatteringFactorTableByType method.\n\ -"; - -const char* doc_ScatteringFactorTableOwner_setScatteringFactorTableByType = "\ -Set internal ScatteringFactorTable according to specified string type.\n\ -\n\ -tp -- string identifier of a registered ScatteringFactorTable type.\n\ - Use ScatteringFactorTable.getRegisteredTypes for the allowed values.\n\ -\n\ -Deprecated: This method is deprecated and will be removed in the 2.0.0 release.\n\ -Use direct assignment to the `scatteringfactortable` property instead, for example:\n\ - obj.scatteringfactortable = SFTNeutron()\n\ -No return value.\n\ +This attribute can be assigned either a ScatteringFactorTable-derived object\n\ +or a string name of a registered ScatteringFactorTable class.\n\ +Use ScatteringFactorTable.getRegisteredTypes() for a set of registered names.\n\ "; const char* doc_ScatteringFactorTableOwner_getRadiationType = "\ @@ -318,25 +308,6 @@ ScatteringFactorTablePtr getscatteringfactortable(T& obj) DECLARE_BYTYPE_SETTER_WRAPPER(setScatteringFactorTable, setscatteringfactortable) -template -void setscatteringfactortablebytype(T& obj, const std::string& tp) -{ - try - { - nb::object warnings = nb::module_::import_("warnings"); - nb::object builtins = nb::module_::import_("builtins"); - nb::object DeprecationWarning = builtins.attr("DeprecationWarning"); - warnings.attr("warn")( - std::string("setScatteringFactorTableByType is deprecated; " - "assign the 'scatteringfactortable' property directly, for example:\n" - "obj.scatteringfactortable = SFTNeutron()"), - DeprecationWarning, - 2); - } - catch (...) { /* don't let warnings break the binding */ } - obj.setScatteringFactorTableByType(tp); -} - template std::string getradiationtype(T& obj) { @@ -383,10 +354,6 @@ C& wrap_PDFCommon(C& cls) getscatteringfactortable, setscatteringfactortable, doc_ScatteringFactorTableOwner_scatteringfactortable) - .def("setScatteringFactorTableByType", - setscatteringfactortablebytype, - nb::arg("tp"), - doc_ScatteringFactorTableOwner_setScatteringFactorTableByType) .def("getRadiationType", getradiationtype, doc_ScatteringFactorTableOwner_getRadiationType) diff --git a/src/extensions/wrap_ScatteringFactorTable.cpp b/src/extensions/wrap_ScatteringFactorTable.cpp index 696a2b4..91e99d1 100644 --- a/src/extensions/wrap_ScatteringFactorTable.cpp +++ b/src/extensions/wrap_ScatteringFactorTable.cpp @@ -152,19 +152,9 @@ Base class for classes that own ScatteringFactorTable instance.\n\ const char* doc_ScatteringFactorTableOwner_scatteringfactortable = "\ ScatteringFactorTable object used for a lookup of scattering factors.\n\ -This can be also set with the setScatteringFactorTableByType method.\n\ -"; - -const char* doc_ScatteringFactorTableOwner_setScatteringFactorTableByType = "\ -Set internal ScatteringFactorTable according to specified string type.\n\ -\n\ -tp -- string identifier of a registered ScatteringFactorTable type.\n\ - Use ScatteringFactorTable.getRegisteredTypes for the allowed values.\n\ -\n\ -Deprecated: This method is deprecated and will be removed in the 2.0.0 release.\n\ -Use direct assignment to the `scatteringfactortable` property instead, for example:\n\ - obj.scatteringfactortable = SFTNeutron()\n\ -No return value.\n\ +This attribute can be assigned either a ScatteringFactorTable-derived object\n\ +or a string name of a registered ScatteringFactorTable class.\n\ +Use ScatteringFactorTable.getRegisteredTypes() for a set of registered names.\n\ "; const char* doc_ScatteringFactorTableOwner_getRadiationType = "\ @@ -454,27 +444,6 @@ void wrap_ScatteringFactorTable(nb::module_& m) getsftable, setsftable, doc_ScatteringFactorTableOwner_scatteringfactortable) - // deprecated: prefer assigning the `scatteringfactortable` property - .def("setScatteringFactorTableByType", - +[](SFTOwner& obj, const std::string& tp) - { - try - { - nb::object warnings = nb::module_::import_("warnings"); - nb::object builtins = nb::module_::import_("builtins"); - nb::object DeprecationWarning = builtins.attr("DeprecationWarning"); - warnings.attr("warn")( - std::string("setScatteringFactorTableByType is deprecated; " - "assign the 'scatteringfactortable' property directly, for example:\n" - "obj.scatteringfactortable = SFTNeutron()"), - DeprecationWarning, - 2); - } - catch (...) { /* don't let warnings break the binding */ } - obj.setScatteringFactorTableByType(tp); - }, - nb::arg("tp"), - doc_ScatteringFactorTableOwner_setScatteringFactorTableByType) .def("getRadiationType", [](const SFTOwner &obj) { diff --git a/tests/test_debyepdfcalculator.py b/tests/test_debyepdfcalculator.py index 140cab5..1de5481 100644 --- a/tests/test_debyepdfcalculator.py +++ b/tests/test_debyepdfcalculator.py @@ -4,7 +4,6 @@ import pickle import unittest -import warnings import numpy from testutils import _maxNormDiff, loadDiffPyStructure, pickle_with_attr @@ -142,28 +141,8 @@ def test_partial_pdfs(self): def test_pickling(self): """Check pickling and unpickling of PDFCalculator.""" - # New syntax: assign an SFT instance to the property (should not warn) dpdfc = self.dpdfc - with warnings.catch_warnings(record=True) as w: - warnings.simplefilter("always") - dpdfc.scatteringfactortable = SFTNeutron() - self.assertFalse( - any(isinstance(x.message, DeprecationWarning) for x in w) - ) - - dpdfc.scatteringfactortable.setCustomAs("Na", "Na", 7) - spkl = pickle.dumps(dpdfc) - dpdfc1_new = pickle.loads(spkl) - self.assertEqual( - dpdfc.scatteringfactortable.type(), - dpdfc1_new.scatteringfactortable.type(), - ) - self.assertEqual(7.0, dpdfc1_new.scatteringfactortable.lookup("Na")) - - # Old syntax: call the deprecated method (should warn) - dpdfc = self.dpdfc - with self.assertWarns(DeprecationWarning): - dpdfc.setScatteringFactorTableByType("N") + dpdfc.scatteringfactortable = SFTNeutron() dpdfc.scatteringfactortable.setCustomAs("Na", "Na", 7) dpdfc.addEnvelope("sphericalshape") dpdfc.debyeprecision = 0.001