[mypyc] Add generic attribute getters and setters to reduce codesize
Implement a small collection of generic native class attribute getters and setters to avoid generating custom verbose code for most attributes. Attribute types supported are:
- PyObject * (setter: only certain types!)
- Booleans
- Tagged integers
- Floats
It's possible to add support for native classes to the generic setter, but I ultimately chose not to as saving the type struct in the attribute context seems sketchy (sometimes it can't be resolved at compile-time which breaks the struct initialization). I can add support if it's really wanted.
I also fixed a few bugs with the old setter generation logic so the tests I added didn't fail (see https://github.com/python/mypy/commit/42f1d29f3069948baf69d002d1cca2a44605bad7).
I observed a 2.4% reduction in self-compile LOC with this patch.
| Revision | Self-compile LOC |
|---|---|
| PR | 2 111 755 (-2.4%) |
| Master (3d2f43772262060fdb1921933da6dc8c7d8ad8a1) | 2 164 450 |
Resolves mypyc/mypyc#246.