This repository has been archived by the owner on Jan 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathcommunism.py
52 lines (40 loc) · 1.49 KB
/
communism.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import random
from warnings import warn
from typing import Iterable, Union
def _election(__PIGS__):
"""
this method will perform an election after each revolution.
*note:*
as this is a communist module, the election is protected
and only __PIGS__ have access to it.
"""
party = random.choices(__PIGS__, k=min(10, len(__PIGS__)))
leader = random.choice(party)
party.remove(leader)
print(
"Glorious election has been held with huge amount of participation (99.3%).",
"\nSecretary General of the Party:",
leader,
"\nPeople's representatives:",
party,
)
def revolution(to_convert: Union[dict, Iterable]):
import inspect, builtins
__PythonIntrinsicGlobalStructures__ = dir(builtins)
def convert(c):
from types import MethodType
# We must protect the builtin elite to not be affected by the revolution
if inspect.isclass(c) and c.__name__ not in __PythonIntrinsicGlobalStructures__:
try:
c.__eq__ = MethodType(lambda s, _: True, c)
c.__hash__ = MethodType(lambda s: hash(1), c)
except:
warn(f"Failed to convert {c} to communism.")
to_convert = to_convert.values() if isinstance(to_convert, dict) else to_convert
for m in to_convert:
if inspect.ismodule(m):
for c in vars(m).values():
convert(c)
else:
convert(m)
_election(__PythonIntrinsicGlobalStructures__)