diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/basics/class_use_other.py | 12 | ||||
-rw-r--r-- | tests/basics/self_type_check.py | 31 |
2 files changed, 43 insertions, 0 deletions
diff --git a/tests/basics/class_use_other.py b/tests/basics/class_use_other.py new file mode 100644 index 0000000000..c6aa94ad25 --- /dev/null +++ b/tests/basics/class_use_other.py @@ -0,0 +1,12 @@ +# check that we can use an instance of B in a method of A + +class A: + def store(a, b): + a.value = b + +class B: + pass + +b = B() +A.store(b, 1) +print(b.value) diff --git a/tests/basics/self_type_check.py b/tests/basics/self_type_check.py new file mode 100644 index 0000000000..947e362cdb --- /dev/null +++ b/tests/basics/self_type_check.py @@ -0,0 +1,31 @@ +# make sure type of first arg (self) to a builtin method is checked + +list.append + +try: + list.append() +except TypeError as e: + print("TypeError") + +try: + list.append(1) +except TypeError as e: + print("TypeError") + +try: + list.append(1, 2) +except TypeError as e: + print("TypeError") + +l = [] +list.append(l, 2) +print(l) + +try: + getattr(list, "append")(1, 2) +except TypeError as e: + print("TypeError") + +l = [] +getattr(list, "append")(l, 2) +print(l) |