Skip to content

Commit 9de126b

Browse files
committed
slots是个不错的玩意儿
1 parent 45999bc commit 9de126b

7 files changed

+35
-1
lines changed

bili_sched.py

+5
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@
1010

1111

1212
class BiliSched:
13+
__slots__ = (
14+
'_loop', '_sched_running', '_force_sleeping', '_sched_daily_jobs',
15+
'_sched_shedule', '_monitors', '_switch_lock',
16+
)
17+
1318
def __init__(self, loop: Optional[asyncio.AbstractEventLoop] = None):
1419
if loop is None:
1520
self._loop = asyncio.get_event_loop()

bili_statistics.py

+6
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,12 @@ def result(self):
7171

7272

7373
class BiliStatistics:
74+
__slots__ = (
75+
'area_num', 'area_duplicated', 'pushed_raffles',
76+
'joined_raffles', 'raffle_results',
77+
'danmu_raffleid_checker', 'cover_checker0', 'cover_checker1', 'tasks_records',
78+
)
79+
7480
def __init__(self, area_num=0):
7581
self.area_num = area_num
7682
self.area_duplicated = False

json_rsp_ctrl.py

+2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ class JsonRspType(enum.IntEnum):
1313

1414

1515
class In:
16+
__slots__ = ('_value',)
17+
1618
def __init__(self, value):
1719
self._value = value
1820

notifier.py

+4
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212

1313
class Users:
14+
__slots__ = ('_users', )
15+
1416
def __init__(self, users: List[User]):
1517
self._users = users
1618

@@ -56,6 +58,8 @@ def gets(self, index: int):
5658

5759

5860
class Notifier:
61+
__slots__ = ('_loop', '_users', '_scheduler',)
62+
5963
def __init__(self, loop=None):
6064
if loop is None:
6165
self._loop = asyncio.get_event_loop()

printer.py

+5
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88

99
class BiliLogger:
10+
__slots__ = ()
1011
# 格式化数据
1112
@staticmethod
1213
def format(
@@ -64,6 +65,8 @@ def error(
6465

6566

6667
class PythonistaPrinter(BiliLogger):
68+
__slots__ = ('dic_color', 'danmu_control',)
69+
6770
def __init__(self):
6871
self.dic_color = {
6972
'user-level': defaultdict(list),
@@ -139,6 +142,8 @@ def print_danmu(self, danmu_msg: dict):
139142

140143

141144
class NormalPrinter(BiliLogger):
145+
__slots__ = ('danmu_control',)
146+
142147
def __init__(self):
143148
self.danmu_control = False
144149

user.py

+11-1
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,18 @@
1313

1414
class User:
1515
_ids = count(0)
16+
__slots__ = (
17+
'id', 'force_sleep', 'name', 'password', 'alias', 'task_ctrl',
18+
'task_arrangement', 'is_log_in', 'is_in_jail',
1619

17-
def __init__(self, dict_user: dict, task_ctrl: dict, task_arrangement: dict, dict_bili: dict, force_sleep: callable):
20+
'bililive_session', 'login_session', 'other_session',
21+
22+
'dict_bili', 'app_params', 'list_delay', 'repost_del_lock',
23+
'dyn_lottery_friends', 'storm_lock', 'recording_tasks',
24+
)
25+
26+
def __init__(
27+
self, dict_user: dict, task_ctrl: dict, task_arrangement: dict, dict_bili: dict, force_sleep: callable):
1828
self.id = next(self._ids)
1929
self.force_sleep = force_sleep
2030
self.name = dict_user['username']

web_session.py

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212

1313

1414
class WebSession:
15+
__slots__ = ('var_session',)
16+
1517
def __init__(self):
1618
self.var_session = aiohttp.ClientSession(timeout=aiohttp.ClientTimeout(total=4))
1719

0 commit comments

Comments
 (0)