Improve Error Message: Consider extending AttributeError on Flax Modules
- Dominant language
- Jupyter Notebook
- Stars
- 7.3k
- Forks
- 833
- Avg merge
- 5h 11m
- Merged PRs (30d)
- 5
Description
@untom was surprised about the error from this example:
```python
from flax import linen as nn
from jax import random
class MyClass(nn.Module):
def setup(self):
self.myvar = 42
def __call__(self, x):
return x * self.myvar
model = MyClass()
params = model.init(random.PRNGKey(0), 0)
print(model.myvar)
```
`AttributeError: "MyClass" object has no attribute "myvar"`.
While we are planning to write a "Module Lifecycle" Doc (#1576), I think it could still be useful to improve this error message. It seems like a case that users familiar to Pytorch will hit often, so we could consider extending `AttributeError` on `Module` with a custom error message that provides a brief explanation and points to the Module Lifecycle Doc.
Contributor guide
Assessment
This issue has not been assessed yet.