What new Python features are the most useful for you?
In recent years Python ecosystem evolved significantly. From using requirements.txt to dependency management tools like Poetry, from simple typing to Protocols [1] and Variadic Generics [2]. We've got walrus operator, match case statement, and finally even faster Python. More and more low-level libraries are being written in Rust [3].
What new features, tools, libraries (already implemented or being worked on) are the most useful for your work with Python? What are you the most excited about?
[1] https://peps.python.org/pep-0544/ [2] https://peps.python.org/pep-0646/ [3] https://github.com/pydantic/pydantic-core
43 comments
[ 6.1 ms ] story [ 84.8 ms ] thread- numpy __array__ interface standardization (easy compatibility across a lot of numerical libraries, e.g. torch, awkward-array, zarr, jax.numpy, dask, xarray)
- the various jit compilers (e.g. numba, jax.jit, torch.compile)
- hw-accelerated functional programming style (e.g. functorch.vmap)
- pybind11 for easy af bindings to c++
- named dimensions for tensors
- pandas-compatible ecosystem (eg seaborn)
- pytrees
- pyenv
- mamba
What I really need, though, is a realtime successor to matplotlib with a much simpler interface/dsl. Haven't looked into plotly much but probably will try it soonish
If it was easier to use virtual environments with PyCall I think I’d abandon matplotlib entirely.
plot.ly now has an API:
https://jugad2.blogspot.com/2013/07/plotly-now-has-api.html
[1] https://typer.tiangolo.com/
If you're developing something more complex, you might find the feature set too small, but you can get surprisingly far with what's there.
The benefits from its type safety and lack of boilerplate alone are enough to keep me using it in favour of anything else.
> Typer uses Click internally. That's the only dependency.
Pretty clever way to walk on giants shoulders!
I do like the := to save a few lines here and there.
3.10 does seem to run faster but maybe that is my imagination.
I wish more people would focus on writing good python.
If the function/method expects an int, string or complex type and I accidentally call it with the wrong type, resulting in an error, such as "can't add 1 to a string", or "can't access access that method because a string was passed".
>and what is good python vs bad python?
This is kinda of subjective but, for a start, don't just start at the type and do stuff until the bottom like a shell script. This is by far how I see most python scripts. All the other normal things. Don't repeat yourself (in moderation, a few times is OK). Keep it simple.
Us older people tend to keep the whole workflow as simple as possible. That is why I love python. There is very little overhead to just using it.
If you tend to make this mistake a lot it might make sense to add some tooling. I don't need it. If I wanted strict typing I would probably just use C++.
For example, if you're redefining bug as "bug that made it past testing" that's one thing.
But I don't buy anyone writing Python daily for 15 years hasn't seen the term "TypeError" which is what your previous two comments were implying.
Testing. Over that long time I have used many test frameworks. My normal workflow is to try and exercise all the code I write as I go.
On the other hand I am 100% pedantic about using 'schema' (https://pypi.org/project/schema/) to validate all the types, structure and domains when I read json.
But I made way more type errors when programming in C/++.
Why do you prefer schema to (fast)jsonschema?
There are many of these things. Maybe some are better but I like this one.
it is not necessarily about type mismatch bugs per se, but more like without type information in the code I will misunderstand what kind of structure is passed in to a function, how to decompose it, what members the data has, what functions does it have, how do you spell them correctly, what elements to expect in dictionaries and what kinds of values do they have, and how can I make massive changes to code without knowing all those answers and expect it all to still work.
type annotations are solving a lot of those issues for me nicely, and the number of things that it doesn't solve well is decreasing with each version and the new features they are adding
So far I like:
Huge fan of dataclasses as well.
Most of the python I write is functions / functional + data classes with type hinted everything and it seems to work nicely and make writing tests for functions very easy.
Using black, isort, mypy, pylint, pytest, makes every project simpler.
For example, clang and gcc can still compile C89 programs.
That in itself is a great feature.
Hope they will add support for Unicode sets `\p{}`, subexpression calls, (*SKIP)(*F), etc. For now, the third-party `regex` module is handy for such features.
If I ever could wrap my brain around asyncio, it would be an appreciated third.
I never used the walrus operator, IIRC, and I find type hints not so useful. Somewhere in the future I will try to use them in APIs, they may have their benefit there.
Edit: I forgot enums. Not so new, but a must.