Things I dislike
- Missing
- Multiline lambdas
- Mutable variable references across scope (or: mutating rather than new binding in loops etc.), e.g.
par_map((lambda: f(x)) for x in xs)
- Typing is terrible
- Also, state of tools: e.g. typing
async with asynccontextmanagers() as ...
- 4 spaces!
- GIL
- Perf
- Async (generically)
Typing woes
- mostly just makes me miss typescript
- no mapped types
- no utility types
- TypedDict very limited, e.g. can only say “expect a dict with exactly these key” rather than “a superset of these keys”
- no way to get the arguments of a function as a type, e.g. to type a dict of kwargs
- py3.12 will have Unpack but that’s not really the right direction
- unclear what is type level vs value level, where the limits are of analysis
- typevartuples won’t
- dataclass_transformer is a special case for things like dataclasses, pydantic, FieldClass: https://typing.readthedocs.io/en/latest/spec/dataclasses.html#dataclass-transform
Exceptions
- Python 3 no longer supports
raise type, instance, traceback . Instead, do raise error.with_traceback(sys.exc_info()[2]).
- Python 3 supports chaining:
raise RuntimeError('specific message') from error.
- Re-raising/chaining exceptions:
raise re-raises exactly what was raised before, with the original traceback.
raise error combines their stacks.
raise Exception() from error shows both errors and The above exception was the direct cause of the following exception.