View baal.py
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 math | |
import statistics | |
import ast | |
class NotSafe(Exception): | |
pass | |
class DangerLister(ast.NodeVisitor): |
View context-manager.py
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 ContextManager: | |
def __init__(self, func): | |
self.func = func | |
def __call__(self, *args, **kwargs): | |
self.gen = self.func(*args, **kwargs) | |
return self | |
def __enter__(self): | |
return next(self.gen) |
View some.c
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
PyObject * | |
hookify_PyFunction_FastCallKeywords(PyObject *func, PyObject *const *stack, | |
Py_ssize_t nargs, PyObject *kwnames) | |
{ | |
__asm__("NOP"); | |
PyCodeObject *co = (PyCodeObject *)PyFunction_GET_CODE(func); | |
PyObject *globals = PyFunction_GET_GLOBALS(func); | |
PyObject *argdefs = PyFunction_GET_DEFAULTS(func); | |
PyObject *kwdefs, *closure, *name, *qualname; | |
PyObject **d; |
View custom.c
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
PyObject * | |
custom_PyFunction_FastCallKeywords(PyObject *func, PyObject *const *stack, | |
Py_ssize_t nargs, PyObject *kwnames) | |
{ | |
__asm__("NOP"); | |
PyCodeObject *co = (PyCodeObject *)PyFunction_GET_CODE(func); | |
PyObject *globals = PyFunction_GET_GLOBALS(func); | |
PyObject *argdefs = PyFunction_GET_DEFAULTS(func); | |
PyObject *kwdefs, *closure, *name, *qualname; | |
PyObject **d; |
View fx.py
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 parser | |
import math | |
class Function: | |
def __init__(self, expr): | |
self.code = parser.expr(expr).compile() | |
def __call__(self, **kwargs): | |
return eval(self.code, {'pi': math.pi, 'e': math.e, 'cos': math.cos}, kwargs) | |
f = Function('2*x') |
View kheb.py
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
from itertools import repeat | |
from functools import partial | |
from copy import deepcopy | |
PREVIEW_SPACING = 15 | |
PREVIEW_ENDING = 2 | |
preview_print = partial(print, end="\n" * PREVIEW_ENDING) | |
def preview(area): |
View osmoz.py
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
def exc(self, result): | |
for callback in self.hook_spec[result.condition][1]: | |
try: callback(result) | |
except CallbackStop: break | |
def meth_wrapper(function, catlizor): | |
def wrapper(*args, **kwargs): | |
if HookConditions.PRE in catlizor.tracked(function.__name__): catlizor.exc(Result(function, args, kwargs, HookConditions.PRE)) | |
res = function(*args, **kwargs) | |
if HookConditions.ON_CALL in catlizor.tracked(function.__name__): catlizor.exc(Result(function, args, kwargs, HookConditions.ON_CALL, res)) | |
if HookConditions.POST in catlizor.tracked(function.__name__): catlizor.exc(Result(function, args, kwargs, HookConditions.POST, kwargs)) |
View different_approach.py
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 operator | |
from collections import UserString | |
from enum import Enum, auto, unique | |
from functools import partial | |
from pprint import pprint | |
from queue import SimpleQueue | |
from typing import Callable, Dict, List | |
@unique |
View metaclass_example.py
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): |
View initsubclass_example.py
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 | |
OlderNewer