@@ -2890,20 +2890,28 @@ def test_function():
2890
2890
2891
2891
[case testMypycAttrNativeClassDunder]
2892
2892
from mypy_extensions import mypyc_attr
2893
- from typing import Generic, TypeVar
2893
+ from typing import Generic, Optional, TypeVar
2894
2894
2895
2895
_T = TypeVar("_T")
2896
2896
2897
+ get_count = set_count = del_count = 0
2898
+
2897
2899
@mypyc_attr(native_class=False)
2898
2900
class Bar(Generic[_T]):
2899
2901
# Note the lack of __deletable__
2900
2902
def __init__(self) -> None:
2901
2903
self.value: str = 'start'
2902
- def __get__(self, instance: _T, owner: type[_T] | None = None) -> str:
2904
+ def __get__(self, instance: _T, owner: Optional[type[_T]] = None) -> str:
2905
+ global get_count
2906
+ get_count += 1
2903
2907
return self.value
2904
2908
def __set__(self, instance: _T, value: str) -> None:
2909
+ global set_count
2910
+ set_count += 1
2905
2911
self.value = value
2906
2912
def __delete__(self, instance: _T) -> None:
2913
+ global del_count
2914
+ del_count += 1
2907
2915
del self.value
2908
2916
2909
2917
@mypyc_attr(native_class=False)
@@ -2915,11 +2923,15 @@ import native
2915
2923
2916
2924
f = native.Foo()
2917
2925
assert(hasattr(f, 'bar'))
2926
+ assert(native.get_count == 1)
2918
2927
assert(f.bar == 'start')
2928
+ assert(native.get_count == 2)
2919
2929
f.bar = 'test'
2920
2930
assert(f.bar == 'test')
2931
+ assert(native.set_count == 1)
2921
2932
del f.bar
2922
2933
assert(not hasattr(f, 'bar'))
2934
+ assert(native.del_count == 1)
2923
2935
2924
2936
[case testMypycAttrNativeClassMeta]
2925
2937
from mypy_extensions import mypyc_attr
0 commit comments