Requires the dont
library
This file contains hidden or 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 inspect | |
import ast | |
import hashlib | |
import sys | |
import textwrap | |
from contextlib import contextmanager | |
def indent(line): | |
return len(line) - len(line.lstrip(" ")) |
This file contains hidden or 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 typing | |
import fishhook | |
class IntersectionMeta(type): | |
def __instancecheck__(self, other): | |
return all(isinstance(other, t) for t in self.types) | |
def __repr__(self): | |
if hasattr(self, "types"): | |
return " & ".join(t.__name__ for t in self.types) |
This file contains hidden or 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 | |
from time import sleep | |
from contextlib import contextmanager | |
@contextmanager | |
def dots(): | |
def _dots(): | |
while True: | |
for i, char in enumerate("⠁⠃⠇⡇⣇⣧⣷⣿"): | |
if i: |
This file contains hidden or 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 importlib.util import spec_from_loader, module_from_spec | |
from importlib.machinery import SourceFileLoader | |
import pytest | |
class ModuleWithoutExtension(pytest.Module): | |
def _importtestmodule(self): | |
print(self.path, type(self.path)) | |
spec = spec_from_loader(self.path.name, SourceFileLoader(self.path.name, str(self.path))) |
This file contains hidden or 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 | |
import threading | |
from time import sleep | |
from typing import Annotated, get_origin, get_args | |
from collections import namedtuple | |
timeout = namedtuple("timeout", "s") | |
This file contains hidden or 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 SubscriptableSneaky: | |
def __init__(self, ns, name): | |
self.ns = ns | |
self.args = [] | |
self.name = name | |
def __getitem__(self, items): | |
if not isinstance(items, tuple): | |
items = items, | |
self.args = [item.name for item in items] |
This file contains hidden or 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 MatchMeta(type): | |
def __instancecheck__(cls, inst): | |
return cls.isinstance(inst) | |
def matching(fn): | |
class cls(metaclass=MatchMeta): | |
isinstance = fn | |
return cls | |
This file contains hidden or 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
#!/bin/bash | |
if (( $# > 6 )); then | |
layout=tiled | |
else | |
layout=even-vertical | |
fi | |
hosts=( "$@" ) | |
tmux new-window | |
tmux send-keys "ssh ${hosts[0]}" | |
for i in $(seq 1 $((${#hosts[@]} - 1))) |
As of 3.11, code objects have a new co_positions()
method that yields tuples of the form (lineno_start, lineno_end, char_start, char_end)
for each bytecode instruction.
Combined with setting f_trace_opcodes
to True
on a frame, trace functions can theoretically track coverage on a character level.
There are a bunch of issues though, shown in part in the code:
- Some instructions correctly cover a wide range of code:
JUMP_*
instructions from branching code basically seems to span the entire length of the jump, i.e. from theif
to the end of the indented block.MAKE_FUNCTION
covers the entire function definition. These issues seem to be easy to resolve on first glance, because you can just ignore the corresponding opcodes.
NewerOlder