Skip to content

Commit ff5438c

Browse files
committed
chore: deprecate setScatteringFactorTableByType by emitting deprecation warning
1 parent cd4e94e commit ff5438c

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

src/extensions/wrap_ScatteringFactorTable.cpp

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,11 @@ const char* doc_ScatteringFactorTableOwner_setScatteringFactorTableByType = "\
158158
Set internal ScatteringFactorTable according to specified string type.\n\
159159
\n\
160160
tp -- string identifier of a registered ScatteringFactorTable type.\n\
161-
Use ScatteringFactorTable.getRegisteredTypes for the allowed values.\n\
161+
Use ScatteringFactorTable.getRegisteredTypes for the allowed values.\n\
162162
\n\
163+
Deprecated: This method is deprecated and will be removed in a future release.\n\
164+
Use direct assignment to the `scatteringfactortable` property instead, for example:\n\
165+
obj.scatteringfactortable = SFTNeutron()\n\
163166
No return value.\n\
164167
";
165168

@@ -399,10 +402,27 @@ void wrap_ScatteringFactorTable()
399402
getsftable,
400403
setsftable<ScatteringFactorTableOwner,ScatteringFactorTable>,
401404
doc_ScatteringFactorTableOwner_scatteringfactortable)
405+
// deprecated: prefer assigning the `scatteringfactortable` property
402406
.def("setScatteringFactorTableByType",
403-
&SFTOwner::setScatteringFactorTableByType,
404-
bp::arg("tp"),
405-
doc_ScatteringFactorTableOwner_setScatteringFactorTableByType)
407+
+[](SFTOwner& obj, const std::string& tp)
408+
{
409+
namespace bp = boost::python;
410+
try
411+
{
412+
bp::object warnings = bp::import("warnings");
413+
bp::object builtins = bp::import("builtins");
414+
bp::object DeprecationWarning = builtins.attr("DeprecationWarning");
415+
warnings.attr("warn")(
416+
std::string("setScatteringFactorTableByType is deprecated; "
417+
"assign the 'scatteringfactortable' property directly (for example, use SFTNeutron()/SFTXray())."),
418+
DeprecationWarning,
419+
2);
420+
}
421+
catch (...) { /* don't let warnings break the binding */ }
422+
obj.setScatteringFactorTableByType(tp);
423+
},
424+
bp::arg("tp"),
425+
doc_ScatteringFactorTableOwner_setScatteringFactorTableByType)
406426
.def("getRadiationType",
407427
&SFTOwner::getRadiationType,
408428
return_value_policy<copy_const_reference>(),

tests/test_debyepdfcalculator.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,8 @@ def test_partial_pdfs(self):
142142
def test_pickling(self):
143143
"""Check pickling and unpickling of PDFCalculator."""
144144
dpdfc = self.dpdfc
145-
dpdfc.setScatteringFactorTableByType("N")
145+
with self.assertWarns(DeprecationWarning):
146+
dpdfc.setScatteringFactorTableByType("N")
146147
dpdfc.scatteringfactortable.setCustomAs("Na", "Na", 7)
147148
dpdfc.addEnvelope("sphericalshape")
148149
dpdfc.debyeprecision = 0.001

0 commit comments

Comments
 (0)