Skip to content

Instantly share code, notes, and snippets.

View AlexWaygood's full-sized avatar
🚀
brb, building a type checker

Alex Waygood AlexWaygood

🚀
brb, building a type checker
View GitHub Profile
@AlexWaygood
AlexWaygood / primer.diff
Created May 6, 2025 10:28
primer report
This file has been truncated, but you can view the full file.
com2ann (https://github.com/ilevkivskyi/com2ann)
+ error[lint:invalid-argument-type] src/com2ann.py:667:23: Argument to this function is incorrect: Expected `str`, found `str | None`
+ error[lint:invalid-argument-type] src/test_cli.py:51:59: Argument to this function is incorrect: Expected `Sequence[str] | None`, found `tuple[Unknown, ...]`
- Found 9 diagnostics
+ Found 11 diagnostics
mypy_primer (https://github.com/hauntsaninja/mypy_primer)
+ error[lint:no-matching-overload] mypy_primer/globals.py:224:24: No overload of bound method `parse_args` matches arguments
- error[lint:unsupported-operator] mypy_primer/main.py:168:23: Operator `*` is unsupported between objects of type `list` and `int | None`
+ error[lint:unsupported-operator] mypy_primer/main.py:168:23: Operator `*` is unsupported between objects of type `list[Unknown]` and `int | None`
@AlexWaygood
AlexWaygood / panic_repro.py
Created April 30, 2025 11:40
Repro of new red-knot panic
f'None{name_5!s}' if (name_5 if name_2 else name_2)({*()}, (name_4 := name_0)) else name_4 % name_5 if f'' else name_4 & name_5
{{*()}: {name_4.name_1 for name_1 in name_2 if name_0 if name_2 if name_3 if name_0 for name_0 in name_4 if name_4 if name_3 for name_0 in name_1 if name_5 for name_4 in name_5 if name_1 if name_4 if name_4 if name_2 if name_1 for name_0 in name_2 if name_4 if name_5 if name_2 if name_2} for name_1, in (lambda: name_5) if {name_0: name_1 for name_0 in name_2 for name_4 in name_1 for name_0 in name_3} for name_0[name_2] in name_0 and name_3 and name_4 and name_5 if name_3(name_4, name_4, name_0=name_3) for [name_2, name_0] in (name_4 async for name_4 in name_5 async for name_0 in name_1 async for name_1 in name_3 async for name_5 in name_2) if {name_3 for name_5 in name_4 for name_2 in name_4 for name_4 in name_3 for name_4 in name_0} if {*()} if {name_2 for name_5 in name_1 for name_0 in name_3 for name_1 in name_2 for name_1 in name_3 for name_5 in name_4 for name_4 in name_2} if na
@AlexWaygood
AlexWaygood / path-in-comment.md
Last active January 24, 2025 19:42 — forked from dcreager/path-in-comment.md
mdtest file path bikeshedding

Here is my test suite.

# PATH: mod.pyi

def get_foo() -> Foo: ...
class Foo: ...
@AlexWaygood
AlexWaygood / call_chain.txt
Last active December 30, 2024 12:36
`__call__` chaining
>>> class Foo:
... def __call__(self):
... return 42
...
>>> class Bar:
... __call__ = Foo()
...
>>> class Baz:
... __call__ = Bar()
...
@AlexWaygood
AlexWaygood / c3.py
Last active October 11, 2024 09:57
C3 linearization
type BasesList = list[type]
type Mro = list[type]
def merge(seqs: list[BasesList]) -> Mro:
print(f"Merging {seqs}")
mro: Mro = []
i = 1
while True:
print(f"{mro=}")
@AlexWaygood
AlexWaygood / annotations-demo.py
Last active June 19, 2024 19:40
Demo for an `__annotations__` solution
"""Proof of concept for how `__annotations__` issues with metaclasses could be solved under PEP 649.
See https://discuss.python.org/t/pep-749-implementing-pep-649/54974/28 for more context.
To experiment with this proof of concept:
1. Clone CPython
2. Create a fresh build of the main branch according to the instructions in the devguide.
3. Save this file to the repository root.
4. Run `./python.exe annotations-demo.py --test` to run tests,
or `PYTHON_BASIC_REPL=1 ./python.exe -i annotations-demo.py` to play with it in the REPL.
from types import SimpleNamespace
AnsiColors = SimpleNamespace(
BOLD_GREEN="\x1b[1;32m",
BOLD_MAGENTA="\x1b[1;35m",
BOLD_RED="\x1b[1;31m",
GREEN="\x1b[32m",
GREY = "\x1b[90m"
MAGENTA = "\x1b[35m"
RED = "\x1b[31m"
@AlexWaygood
AlexWaygood / last_n_lines.py
Last active March 10, 2024 16:30
Script to find the last `n` lines of a file
import os
from collections import deque
from collections.abc import Iterator, Sequence
from typing import Final, Protocol
class SeekableBytesFile(Protocol):
def seek(self, position: int, whence: int = ..., /) -> int: ...
def read(self, amount: int, /) -> bytes: ...
@AlexWaygood
AlexWaygood / find_identifier_lengths.py
Last active February 3, 2024 17:19
Script to find the distribution of lengths of Python identifiers in a given directory
import ast
import sys
import keyword
import seaborn
from pathlib import Path
from collections import Counter
from dataclasses import dataclass
LENGTHS_COUNT = Counter[int]()