8000 Use 3.9 syntax + count dunder calls · python/mypy@7059bbe · GitHub
[go: up one dir, main page]

Skip to content
8000

Commit 7059bbe

Browse files
committed
Use 3.9 syntax + count dunder calls
1 parent 7df6ab1 commit 7059bbe

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

mypyc/test-data/irbuild-classes.test

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1381,4 +1381,3 @@ class M(type): # E: Inheriting from most builtin types is unimplemented
13811381
@mypyc_attr(native_class=True)
13821382
class A(metaclass=M): # E: Class is marked as native_class=True but it can't be a native class
13831383
pass
1384-

mypyc/test-data/run-classes.test

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2890,20 +2890,28 @@ def test_function():
28902890

28912891
[case testMypycAttrNativeClassDunder]
28922892
from mypy_extensions import mypyc_attr
2893-
from typing import Generic, TypeVar
2893+
from typing import Generic, Optional, TypeVar
28942894

28952895
_T = TypeVar("_T")
28962896

2897+
get_count = set_count = del_count = 0
2898+
28972899
@mypyc_attr(native_class=False)
28982900
class Bar(Generic[_T]):
28992901
# Note the lack of __deletable__
29002902
def __init__(self) -> None:
29012903
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
29032907
return self.value
29042908
def __set__(self, instance: _T, value: str) -> None:
2909+
global set_count
2910+
set_count += 1
29052911
self.value = value
29062912
def __delete__(self, instance: _T) -> None:
2913+
global del_count
2914+
del_count += 1
29072915
del self.value
29082916

29092917
@mypyc_attr(native_class=False)
@@ -2915,11 +2923,15 @@ import native
29152923

29162924
f = native.Foo()
29172925
assert(hasattr(f, 'bar'))
2926+
assert(native.get_count == 1)
29182927
assert(f.bar == 'start')
2928+
assert(native.get_count == 2)
29192929
f.bar = 'test'
29202930
assert(f.bar == 'test')
2931+
assert(native.set_count == 1)
29212932
del f.bar
29222933
assert(not hasattr(f, 'bar'))
2934+
assert(native.del_count == 1)
29232935

29242936
[case testMypycAttrNativeClassMeta]
29252937
from mypy_extensions import mypyc_attr

0 commit comments

Comments
 (0)
0