Skip to content

Instantly share code, notes, and snippets.

@mypy-play
mypy-play / main.py
Created March 16, 2025 18:23
Shared via mypy Playground
# remove the typing hints and mypy fails
from typing import Callable, Union
def fun1(x: int) -> Callable[[int], int]:
return lambda y: x + y
x = fun1(1)
reveal_type(x)
@mypy-play
mypy-play / main.py
Created December 21, 2024 00:48
Shared via mypy Playground
from typing import Union, Never
def check(x: int) -> Union[Never, str]:
try:
assert x == 2, "Expected 2"
return "Sat"
except AssertionError as msg:
print(msg)
@stroxler
stroxler / full_vs_args_only.py
Last active February 2, 2025 19:15
Comparing rules for parentheses in arrow callable syntax (PEP 677)
# A quick example to illustrate the two syntaxes
def f(x: str, y: int) -> bool: ...
f: ((str, int) -> bool) # full parentheses syntax
f: (str, int) -> bool # args only parentheses
# Now, some samples from typeshed (I abbreviated a few args lists so that it's easier to find the relevant part)
@stroxler
stroxler / callable-type-vs-union.md
Last active February 2, 2025 19:14
Examples of callable type vs union confusion
  1. We can't naively union a callable type with another type:
union_of_callables: (int) -> str | (bool) -> str  # Syntax error!

# Needs extra parens; Not intuitive or user-friendly.
union_of_callable2: ((int) -> str) | ((bool) -> str)

# Simpler and can be easily split into multiple lines, as Никита mentioned.

Languages, Compilers, Debuggers, and Development Infrastructure Engineering Internships at Apple

Apple's Languages, Compilers, Debuggers and Development Infrastructure teams are now looking for interns for 2022!

We are looking for students who are motivated to get hands on experience working on these exciting technologies. We have interesting problems to solve at every level, from low-level assembly to high-level Swift code. No prior language, compiler or debugger experience is required and candidates without such experience are encouraged to apply. Candidates should be comfortable writing code in C++.

These are paid internships. While most internships last 3 months, starting in May or June, the starting dates and the internship length are flexible. Internships are restricted to students. Students must be enrolled in school in the quarter/semester immediately following the internship. We are looking for candidates of all education levels, from Bachelor’s to Ph.D. Applicants from outside the U.S.A. are w

@stroxler
stroxler / Callable_examples.md
Last active February 2, 2025 19:14
Examples of Callable

Some existing Callable types from github

Using the most restrictive full-stub syntax, here's how we'd express a few Callable types:

# from functools.pyi
f0: Callable[[_T1, _T2], S)
f0: (t1: _T1, t2: _T2, /) -> S

# from shapeflow/api.py
f1: Callable[[Optional[int], np.ndarray], stream_image]