flandre/test/testpy.py
2025-04-25 22:19:38 +08:00

115 lines
2.1 KiB
Python

import dataclasses
import hashlib
import inspect
import sys
import time
from enum import Enum
from pathlib import Path, PosixPath
@dataclasses.dataclass
class ASD:
aaa: int = 1
bbb: int = 1
ccc: int = 1
@property
def b(self):
return self.aaa
class EE(Enum):
asd = ASD
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
def f1(self, arg):
print('f1', arg)
def f2(self, arg):
print('f2', arg)
class E1:
a = 1
if __name__ == '__main__':
# print(sys.argv)
# print(dir(ASD()))
# print(ASD.__dict__)
# print(inspect.getmembers(ASD))
# print(inspect.getmembers(ASD))
# for f in dataclasses.fields(ASD):
# print(f.name, f.type)
# 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)
# dc = DC()
# dc.f1(11,cond=False)
# dc.f2(22)
a = E1()
b = E1()
a.a = 1413
print(b.a)
print()