Added more test files from lectures.

This commit is contained in:
cheezedoodle2
2023-04-06 17:03:21 -07:00
parent c610762522
commit 0dd1348601
13 changed files with 311 additions and 7 deletions
+26
View File
@@ -0,0 +1,26 @@
class C:
@classmethod
def class_method(cls):
print("Called class_method with cls:", cls)
def instance_method(self):
print("Called instance_method with self:", self)
@staticmethod
def static_method():
print("Called static_method")
# Accessing class attributes
class_method_obj = C.__dict__["class_method"]
instance_method_obj = C.__dict__["instance_method"]
static_method_obj = C.__dict__["static_method"]
# Calling the methods directly (without transformation)
class_method_obj.__func__(C) # Output: Called class_method with cls: <class '__main__.C'>
instance_method_obj.__func__(1) # Output: Called instance_method with self: <__main__.C object at 0x7f8d7c1e4d90>
static_method_obj.__func__() # Output: Called static_method
# Accessing the methods through class attribute reference (with transformation)
C.class_method() # Output: Called class_method with cls: <class '__main__.C'>
C.instance_method(1) # Raises TypeError: instance_method() missing 1 required positional argument: 'self'
C.static_method() # Output: Called static_method