google / google/flax

`__getattr__` and pytype checking

Open
#2,416 17 comments 0 reactions 1 assignee Claimed by @cgarciae View on GitHub
Dominant language
Jupyter Notebook
Stars
7.3k
Forks
833
Avg merge
5h 11m
Merged PRs (30d)
5

Description

Currently `nn.Module` implement `__getattr__`. This disable any type checking when making a typo in attribute:

```python
my_module = MyModule()

my_module.non_existing_attribute # << pytype do not detect this
```

It would be nice to wrap `__getattr__` in a `if not typing.TYPE_CHECKING:` so that pytype actually check the attribute types.

Note that `class Module` would have to be updated so that the `Module` fields are defined (note doing this today would also allow type checking on `module.scope`,...):

```python
class Module:
scope: Optional[Scope]
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.