2025-04-12 00:03:28 +08:00
|
|
|
import dataclasses
|
2025-04-13 01:01:13 +08:00
|
|
|
import hashlib
|
2025-04-12 00:03:28 +08:00
|
|
|
import inspect
|
2025-04-12 15:39:56 +08:00
|
|
|
import sys
|
2025-04-25 22:19:38 +08:00
|
|
|
import time
|
2025-04-12 01:29:38 +08:00
|
|
|
from enum import Enum
|
2025-04-12 15:39:56 +08:00
|
|
|
from pathlib import Path, PosixPath
|
2025-04-12 00:03:28 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
@dataclasses.dataclass
|
|
|
|
|
class ASD:
|
|
|
|
|
aaa: int = 1
|
|
|
|
|
bbb: int = 1
|
|
|
|
|
ccc: int = 1
|
|
|
|
|
|
2025-04-12 00:34:24 +08:00
|
|
|
@property
|
2025-04-12 00:03:28 +08:00
|
|
|
def b(self):
|
|
|
|
|
return self.aaa
|
|
|
|
|
|
2025-04-13 22:58:17 +08:00
|
|
|
|
2025-04-12 01:29:38 +08:00
|
|
|
class EE(Enum):
|
|
|
|
|
asd = ASD
|
2025-04-13 22:58:17 +08:00
|
|
|
x = 1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def skip1(f):
|
|
|
|
|
def wrapper(self, *args, **kwargs):
|
|
|
|
|
if 'cond' not in kwargs:
|
|
|
|
|
return f(self, *args, **kwargs)
|
|
|
|
|
if kwargs['cond']:
|
|
|
|
|
del kwargs['cond']
|
|
|
|
|
return f(self, *args, **kwargs)
|
|
|
|
|
else:
|
|
|
|
|
return self
|
|
|
|
|
|
|
|
|
|
return wrapper
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def skip(original_class):
|
|
|
|
|
def f2(self, x):
|
|
|
|
|
print(x)
|
|
|
|
|
|
|
|
|
|
for name, f in inspect.getmembers(original_class, inspect.isfunction):
|
|
|
|
|
print(name, f)
|
|
|
|
|
setattr(original_class, name, skip1(f))
|
|
|
|
|
return original_class
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Decorator(object):
|
|
|
|
|
def __init__(self, arg):
|
|
|
|
|
self.arg = arg
|
|
|
|
|
|
|
|
|
|
def __call__(self, cls):
|
|
|
|
|
pass
|
|
|
|
|
# def wrappedClass(*args):
|
|
|
|
|
# return cls(*args)
|
|
|
|
|
#
|
|
|
|
|
# return type("TestClass", (cls,), dict(newMethod=self.newMethod, classattr=self.arg))
|
|
|
|
|
|
|
|
|
|
def newMethod(self, value):
|
|
|
|
|
return value * 2
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@skip
|
|
|
|
|
class DC:
|
|
|
|
|
def __init__(self):
|
|
|
|
|
pass
|
2025-04-25 22:19:38 +08:00
|
|
|
|
2025-04-13 22:58:17 +08:00
|
|
|
def f1(self, arg):
|
|
|
|
|
print('f1', arg)
|
|
|
|
|
|
|
|
|
|
def f2(self, arg):
|
|
|
|
|
print('f2', arg)
|
|
|
|
|
|
2025-04-12 00:03:28 +08:00
|
|
|
|
2025-04-25 22:19:38 +08:00
|
|
|
class E1:
|
|
|
|
|
a = 1
|
|
|
|
|
|
|
|
|
|
|
2025-04-12 00:03:28 +08:00
|
|
|
if __name__ == '__main__':
|
2025-04-13 22:58:17 +08:00
|
|
|
# print(sys.argv)
|
2025-04-12 00:03:28 +08:00
|
|
|
# print(dir(ASD()))
|
|
|
|
|
# print(ASD.__dict__)
|
|
|
|
|
# print(inspect.getmembers(ASD))
|
|
|
|
|
# print(inspect.getmembers(ASD))
|
2025-04-12 01:29:38 +08:00
|
|
|
# for f in dataclasses.fields(ASD):
|
|
|
|
|
# print(f.name, f.type)
|
2025-04-13 01:01:13 +08:00
|
|
|
# p = Path('asd')
|
|
|
|
|
# pt = type(p)
|
|
|
|
|
# print(pt)
|
|
|
|
|
# print(pt.__name__)
|
|
|
|
|
# print(type(type(p)))
|
|
|
|
|
# match pt:
|
|
|
|
|
# case _x if isinstance(_x, PosixPath):
|
|
|
|
|
# print(-2)
|
|
|
|
|
# case type(__name__='PosixPath'):
|
|
|
|
|
# print(-1)
|
|
|
|
|
# case type():
|
|
|
|
|
# print(0)
|
|
|
|
|
# case Path():
|
|
|
|
|
# print(1)
|
|
|
|
|
# case PosixPath():
|
|
|
|
|
# print(3)
|
|
|
|
|
# case _:
|
|
|
|
|
# print(2)
|
2025-04-25 22:19:38 +08:00
|
|
|
# dc = DC()
|
|
|
|
|
# dc.f1(11,cond=False)
|
|
|
|
|
# dc.f2(22)
|
|
|
|
|
|
|
|
|
|
a = E1()
|
|
|
|
|
b = E1()
|
|
|
|
|
a.a = 1413
|
|
|
|
|
print(b.a)
|
|
|
|
|
print()
|