Live data from Hacker News

What new Python features are the most useful for you?

news.ycombinator.com

11–20 of 44 posts

Re: What new Python features are the most useful for you?

#11
Just getting back on the latest open source Python ecosystem after a long stint of mostly writing Python in a corporate mono-repo context with bespoke tooling.

So far I like:

  - black autoformats my code swiftly
  - ruff is fast and replaces multiple python linters
  - pip-tools lets me manage multiple dependency specifications (local, prod, test) more sanely than manually syncing `pip freeze` with multiple requirements files. 
  - f-strings are nice improvement over .format calls, % string interpolation, string.Templates, etc.
  - I appreciate pattern matching and case classes in Scala. I expect to like them  using dataclasses and pattern matching Python

Re: What new Python features are the most useful for you?

#12
post #7

In the 15 years I have been developing in python (and C++ at the same time, daily), I can't remember a single bug I ever had on account of an incorrect type. 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.

what do you attribute to never finding a bug due to incorrect type? and what is good python vs bad python?

Re: What new Python features are the most useful for you?

#14
I use Type hints and using mypy strictly.

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.

Re: What new Python features are the most useful for you?

#16

- Pydantic: basically it might as well be part of the standard library for me - I'm excited by polars as a potential pandas replacement - Speaking of pandas i really like pandera and how it integrates with both pandas and pydantic

Why use Pydantic instead of dataclasses?

Re: What new Python features are the most useful for you?

#17
post #6

The `click` library would be a nice replacement to `argparse`

"Click" and "DocOpt" are the 'argparse' replacements. They're the most semantic and intuitive way of developing command-line apps.

I've found Typer [1] pretty intuitive to integrate with existing code, it uses type hints to generate the CLI arguments.

[1] https://typer.tiangolo.com/

Re: What new Python features are the most useful for you?

#18
post #6

The `click` library would be a nice replacement to `argparse`

"Click" and "DocOpt" are the 'argparse' replacements. They're the most semantic and intuitive way of developing command-line apps.

I find `typer` way more ergonomic than either argparse or click (which it uses under the hood).

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.

Re: What new Python features are the most useful for you?

#19
post #2

- einops (probably by far the most useful Python dsl for me as of late, esp. if you deal a lot with tensors) - 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…

Maybe not practical for your workflow, but making interactive plots in Pluto.jl is so much nicer than hacking around in matplotlib

If it was easier to use virtual environments with PyCall I think I’d abandon matplotlib entirely.

Re: What new Python features are the most useful for you?

#20
post #16

- Pydantic: basically it might as well be part of the standard library for me - I'm excited by polars as a potential pandas replacement - Speaking of pandas i really like pandera and how it integrates with both pandas and pydantic

Why use Pydantic instead of dataclasses?

Pydantic can do validation. There’s also the related Typer, which builds command line interfaces from the type annotations on your entry point
Post reply on HN