Skip to content

Instantly share code, notes, and snippets.

View samuelcolvin's full-sized avatar

Samuel Colvin samuelcolvin

View GitHub Profile
@samuelcolvin
samuelcolvin / python-people.md
Last active March 13, 2024 03:13
An incomplete list of people in the Python community to follow on Twitter and Mastodon.

Python People

(Updated 2022-11-16 with suggestions from comments below, Twitter and Mastodon)

An incomplete list of people in the Python community to follow on Twitter and Mastodon.

With the risk that Twitter dies, I'd be sad to lose links to interesting people in the community, hence this list.

I would love you to comment below with links to people I've missed.

@samuelcolvin
samuelcolvin / insert_assert.py
Last active May 10, 2023 17:45
auto-generate assert statements in pytest
"""
License: MIT
Copyright (c) 2022 Samuel Colvin.
See https://twitter.com/adriangb01/status/1573708407479189505
## Usage
Once installed just add
require=(function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.decodeHTML = exports.decodeHTMLStrict = exports.decodeXML = void 0;
var entities_json_1 = __importDefault(require("./maps/entities.json"));
var legacy_json_1 = __importDefault(require("./maps/legacy.json"));
var xml_json_1 = __importDefault(require("./maps/xml.json"));
@samuelcolvin
samuelcolvin / README.md
Last active September 15, 2022 14:42
Check version script used before release.

To use simply run

VERSION_PATH='<your package dir>/version.py' python <(curl -Ls https://gist.githubusercontent.com/samuelcolvin/4e1ad439c5489e8d6478cdee3eb952ef/raw/check_version.py)
import asyncio
import base64
import json
from pathlib import Path
from httpx import AsyncClient
from bs4 import BeautifulSoup
from devtools import debug
START_URL = 'https://github.com/pydantic/pydantic/network/dependents'
<style>
main {
display: flex;
}
pre {
margin: 0;
padding: 0;
}
code, #output {
white-space: pre-wrap;
➤ HYPOTHESIS_MAX_EXAMPLES=1000 pytest tests/test_hypothesis.py::test_recursive_cycles -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):
debug(changes)