Skip to content

Commit

Permalink
Add a code comment discouraging __len__
Browse files Browse the repository at this point in the history
Add a code comment to the pybind11 wrapper explaining why defining
`__len__` is unwise.
  • Loading branch information
r-owen committed Apr 24, 2017
1 parent 13fa11a commit a900c6e
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions python/lsst/daf/base/propertyContainer/propertyList.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ void declareAccessors(C& cls, std::string const& name) {
cls.def(getName.c_str(), (T (PropertyList::*)(std::string const&, T const&) const) & PropertyList::get<T>,
"name"_a, "defaultValue"_a);

// Warning: __len__ is ambiguous so do not attempt to define it. It could return
// the number of unique names or the number of entries (e.g. as returned by toList,
// a pure Python method). C++ begin and end iterate over unique names, but users often
// view PropertyList as a representation of a FITS header. When in doubt, refuse to guess.

const std::string getArrayName = "getArray" + name;
cls.def(getArrayName.c_str(),
(std::vector<T> (PropertyList::*)(std::string const&) const) & PropertyList::getArray<T>,
Expand Down

0 comments on commit a900c6e

Please sign in to comment.