Skip to content

Instantly share code, notes, and snippets.

@mypy-play
mypy-play / main.py
Created October 31, 2026 23:42
Shared via mypy Playground
age: int = 25
nom: str = "Mehdi"
moyenne: float = 15.5
age = "vingt-cinq"
nom = 42
moyenne = "excellent"
@mypy-play
mypy-play / main.py
Created October 31, 2026 20:25
Shared via mypy Playground
def func_with_kw_only(x: int, *, y: int = 0):
return x + y
def func_with_pos_only(x: int, y: int, /):
return x + y
func_with_kw_only(1) # OK
func_with_kw_only(1, y=2) # OK
func_with_kw_only(1, 2) # error: Too many positional arguments for "func_with_kw_only" [call-arg]
@mypy-play
mypy-play / main.py
Created October 31, 2026 19:32
Shared via mypy Playground
from collections.abc import Callable
class Animal: ...
class Dog(Animal):
def bark(self) -> None: print("woof")
class Cat(Animal): ...
class Handler[T]:
def __init__(self, cb: Callable[[T], None]) -> None:
self.cb = cb
@mypy-play
mypy-play / main.py
Created October 31, 2026 18:00
Shared via mypy Playground
def foo(a_type: type) -> None:
reveal_type(a_type) # N: Revealed type is "builtins.type"
class Sub(a_type): pass
@mypy-play
mypy-play / main.py
Created October 31, 2026 17:58
Shared via mypy Playground
class Person():
def __init__(self, name: str, age: int, characteristics: type):
self.name = name
self.age = age
self.characteristics = characteristics
def foo(person: Person) -> None:
reveal_type(person.characteristics) # N: Revealed type is "builtins.type"
class Sub(person.characteristics): pass
@mypy-play
mypy-play / main.py
Created October 31, 2026 17:57
Shared via mypy Playground
class Person():
def __init__(self, name: str, age: int, characteristics: type):
self.name = name
self.age = age
self.characteristics = characteristics
def foo(person: Person) -> None:
reveal_type(person.characteristics) # N: Revealed type is "builtins.type"
class Sub(person.characteristics): pass
@mypy-play
mypy-play / main.py
Created October 31, 2026 17:55
Shared via mypy Playground
from typing import Any
class Person():
def __init__(self, name: str, age: int, characteristics: type):
self.name = name
self.age = age
self.characteristics = characteristics
def foo(person: Person) -> None:
reveal_type(person.characteristics) # N: Revealed type is "builtins.type"
@mypy-play
mypy-play / main.py
Created October 31, 2026 15:15
Shared via mypy Playground
mypy somme.py
@mypy-play
mypy-play / main.py
Created October 30, 2026 07:11
Shared via mypy Playground
from typing import Iterator
def fib(n: int) -> Iterator[int]:
a, b = 0, 1
while a < n:
yield a
a, b = b, a + b
@mypy-play
mypy-play / main.py
Created October 29, 2026 22:35
Shared via mypy Playground
from typing import overload, Optional
class A:
pass
class B:
pass
class C:
pass