This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import evdev | |
from evdev import InputDevice, categorize, ecodes | |
devices = [evdev.InputDevice(path) for path in evdev.list_devices()] | |
for device in devices: | |
print(device.path, device.name, device.phys) | |
device = devices[int(input(">> "))] | |
for event in dev.read_loop(): | |
if event.type == ecodes.EV_KEY: | |
print(categorize(event)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
__import__("sys").settrace(lambda frame, event, arg: (setattr(frame, "f_lineno", (getattr(frame, "f_lineno") + tuple(__import__("dis").Bytecode(frame.f_code))[(frame.f_lasti // 2) + 1].argval)) if event == "line" and tuple(__import__("dis").Bytecode(frame.f_code))[(frame.f_lasti // 2)].argval == "goto" else None) or (lambda frame, event, arg: (setattr(frame, "f_lineno", (getattr(frame, "f_lineno") + tuple(__import__("dis").Bytecode(frame.f_code))[(frame.f_lasti // 2) + 1].argval)) if event == "line" and tuple(__import__("dis").Bytecode(frame.f_code))[(frame.f_lasti // 2)].argval == "goto" else None))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ast | |
import inspect | |
from astpretty import pprint | |
def simple_name_equal(elt, target): | |
if not (isinstance(elt, ast.Name) and isinstance(target, ast.Name)): | |
return False | |
return elt.id == target.id | |
class Optimizer(ast.NodeTransformer): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import valf | |
class Grammar(valf.Grammar): | |
class Terminals: | |
AUTO_HANDLE = ("int",) | |
END_OF_STMT = valf.Const(";") | |
class Compiler(valf.Visitor): | |
def __init__(self, *args, **kwargs): | |
super().__init__(*args, **kwargs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import collections.abc | |
from itertools import chain | |
MUTABLE_TYPES = tuple( | |
filter( | |
lambda item: isinstance(item, type) and item.__name__.startswith("Mutable"), | |
collections.abc.__dict__.values(), | |
) | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import collections.abc | |
MUTABLE_TYPES = tuple( | |
filter( | |
lambda item: isinstance(item, type) and item.__name__.startswith("Mutable"), | |
collections.abc.__dict__.values(), | |
) | |
) | |
class Parent: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mutable_attrs = filter( | |
lambda attr: not attr[0].startswith("__") and isinstance(attr[1], MUTABLE_TYPES), | |
vars(Parent).items() | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import collections.abc | |
MUTABLE_TYPES = tuple( | |
filter( | |
lambda item: isinstance(item, type) and item.__name__.startswith("Mutable"), | |
collections.abc.__dict__.values(), | |
) | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Parent: | |
items = [] | |
def __init_subclass__(cls): | |
cls.items = Parent.items.copy() | |
class Child(Parent): | |
pass | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ParentMeta(type): | |
def __new__(cls, name, bases, cls_dict): | |
cls = super().__new__(cls, name, bases, cls_dict) | |
cls.items = cls.items.copy() | |
return cls | |
class Parent(metaclass=ParentMeta): | |
items = [] | |
class Child(Parent): |