Here is my test suite.
# PATH: mod.pyi
def get_foo() -> Foo: ...
class Foo: ...
Here is my test suite.
# PATH: mod.pyi
def get_foo() -> Foo: ...
class Foo: ...
>>> class Foo: | |
... def __call__(self): | |
... return 42 | |
... | |
>>> class Bar: | |
... __call__ = Foo() | |
... | |
>>> class Baz: | |
... __call__ = Bar() | |
... |
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=}") |
"""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" |
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: ... |
import ast | |
import sys | |
import keyword | |
import seaborn | |
from pathlib import Path | |
from collections import Counter | |
from dataclasses import dataclass | |
LENGTHS_COUNT = Counter[int]() |