openforcefield / openff-toolkit

The Open Forcefield Toolkit provides implementations of the SMIRNOFF format, parameterization engine, and other tools. Documentation available at http://open-forcefield-toolkit.readthedocs.io
http://openforcefield.org
MIT License
313 stars 92 forks source link

`ParameterAttribute` does not implement `__delete__` #1680

Open mattwthompson opened 1 year ago

mattwthompson commented 1 year ago

Describe the bug

Class attributes are meant to be removed by __delete__, but this doesn't seem to be implemented. ParameterAttribute otherwise follows the descriptor pattern by defining __set__ and __get__.

To Reproduce

In [1]: from openff.toolkit.typing.engines.smirnoff.parameters import BondHandler

In [2]: handler = BondHandler(version=0.4)

In [3]: delattr(handler, "fractional_bondorder_method")
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[3], line 1
----> 1 delattr(handler, "fractional_bondorder_method")

AttributeError: __delete__

In [4]: del handler.fractional_bondorder_method
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[4], line 1
----> 1 del handler.fractional_bondorder_method

AttributeError: __delete__

Output

Additional context

We don't have much of a habit of deleting attributes; if they exist, it's usually for good reason. The existing up-converters are blind to this issue because they muck around with a keyword arguments dictionary before setting anything on an object. But there are cases in which one would want to change a handler in-memory, including deleting attributes.