Skip to content

Instantly share code, notes, and snippets.


Samuel Colvin samuelcolvin

View GitHub Profile
View hypothesis_traceback.txt
➤ HYPOTHESIS_MAX_EXAMPLES=1000 pytest tests/ -s
Test session starts (platform: darwin, Python 3.10.5, pytest 7.1.2, pytest-sugar 0.9.4)
benchmark: 3.4.1 (defaults: timer=time.perf_counter disable_gc=False min_rounds=5 min_time=0.000005 max_time=1.0 calibration_precision=10 warmup=True warmup_iterations=100000)
rootdir: /Users/samuel/code/pydantic-core, configfile: pyproject.toml
plugins: benchmark-3.4.1, sugar-0.9.4, hypothesis-6.48.1, timeout-2.1.0, mock-3.8.1
timeout: 30.0s
timeout method: signal
timeout func_only: False
collecting ...
import os
from typing import TypeVar, Generic
import psutil
import pytest
from pydantic.generics import GenericModel
process = psutil.Process(os.getpid())

Differentiating between "fields" and library methods/attributes

(Samuel Colvin)

See this discussion.

from pathlib import Path
from watchfiles import watch
from devtools import debug
THIS_DIR = Path(__file__).parent
for changes in watch(THIS_DIR, debug=True):
#!/usr/bin/env python3
import time
clocks = ['🕛', '🕐', '🕑', '🕒', '🕓', '🕔', '🕕', '🕖', '🕗', '🕘', '🕙', '🕚']
# moves the cursor to the beginning of the line
# (3 columns back in this case is always enough)
reset_cursor = '\033[3D'
i = 0
while True:
View codecov_colors_bookmarklet.js
const set_color = (cls, col) => document.querySelectorAll(cls).forEach(el => { = col});
set_color('.bg-ds-coverage-partial', '#ffa');
set_color('.bg-ds-coverage-uncovered', '#fdd');

Usage is simply

VERSION_PATH=<package name> python <(curl -Ls

This will set the __version__ variable in `

samuelcolvin /
Created Dec 18, 2021
List of Characters which are (amazingly) valid as the first character of identifiers.
This file has been truncated, but you can view the full file.
Take the "Derived Property: ID_Start" section from
and save to "DerivedCoreProperties.txt"
from pathlib import Path
def get_value(s: str) -> int:
samuelcolvin / webauthn_client.js
Created Nov 17, 2021
demo of webauthn using FastAPI
View webauthn_client.js
const log_el = document.getElementById('log')
function log(...messages) {
log_el.innerText += '\n' + => JSON.stringify(m, null, 2)).join(' ')
function error(message) {
log_el.innerText += '\n' + message
from pathlib import Path
from httpx import AsyncClient
from import SesConfig, SesClient, SesRecipient, SesAttachment
async def ses_demo(client: AsyncClient):
ses_client = SesClient(client, SesConfig('<access key>', '<secret key>', '<region>'))
message_id = await ses_client.send_email(
SesRecipient('', 'Sender', 'Name'),
'This is the subject',