1

Is there a way to implement a proxy object with mypyc?

For example, consider the following code which works fine with Python but not mypyc:

import typing


class Thing:
    def __getattr__(self, name: str) -> typing.Any:
        return 5

t = Thing()
print(t.lol)

Python output:

5

mypyc compiled output:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "blah.py", line 9, in <module>
    print(t.lol)
AttributeError: 'Thing' object has no attribute 'lol'
Sohail
  • 3,020
  • 1
  • 25
  • 23
  • 1
    `mypyc` supports a subset of Python. This is not in the subset, I guess. – Tim Roberts Mar 13 '21 at 05:40
  • Seems that way. Would be nice if there was some way to figure this out though... I need a proxy :-( – Sohail Mar 13 '21 at 06:03
  • 2
    These are limits of mypyc native class: https://mypyc.readthedocs.io/en/latest/native_classes.html#native-classes – hussic Mar 13 '21 at 11:39
  • I just went ahead and added support in a fork of mypy. Hopefully they will pick it up: https://github.com/python/mypy/pull/10211 – Sohail Mar 13 '21 at 23:40

0 Answers0