Is there __setattr__
support?
There is a parallel thread proposing to add that:
As mentioned there one downside of setting __class__
is that it slows down all attribute access and reading attributes from a module is very common (np.sin(...)
etc).
In ordinary Python code modules are namespaces and their interface is only expected to provide attributes. The __getattr__
proposal (PEP 562) has a clear motivation around accessing deprecated attributes. PEP 562 also added __dir__
which is for listing attributes. The __setattr__
proposal in the other thread is motivated by wanting to disallow (or warn about) setting attributes in cases where it could be a likely user error to do so. I don’t see why any special support should be added to encourage defining modules that have unusual features besides attribute access: most other operations should generally be expected to give TypeError
.