HACKER Q&A
📣 behnamoh

What should be added to the syntax of Python and why?


I recently came across the pipe library [0] which allows function chaining in a much more straightforward way:

    sum(fib() | where(lambda x: x % 2 == 0) | take_while(lambda x: x < 4000000))
I know in Lisp languages you can extend the syntax easily, but I was wondering if there are any needs for that in Python.

[0] https://pypi.org/project/pipe/


  👤 thek3nger Accepted Answer ✓
None propagation. It such a pain to constantly check for None when accessing very deep nested structures (as I had to do often with JSON data).

There is a PEP for this[1] but it is currently deferred.

[1]: https://peps.python.org/pep-0505/


👤 pid-1
I don't know the name of this idiom, but the following is valid Python:

import pandas as pd

my_df = (

    pd.Dataframe()

    .join(<...>)

    .query(<...>)

    .sort_values(<...>)
)

I also use plotly like so:

my_plot = (

    px.line(<...>)

    .update_xaxes(<...>)

    .update_layout(<...)
)

Not exactly function chaining, but I guess it has a similar effect.

I'm happy with Python's syntax nowadays and much prefer seeing improvements on library / environment related things.


👤 VoodooJuJu
Curly braces, to make whitespace insignificant. I don't like significant whitespace.

👤 backslash_16
I would love separate variable initialization vs assignment. I know that ship has sailed.

It's interesting, I never cared about that until I did "Crafting Interpreters" and realized how separating those two actions helps clarify scopes.

Being realistic I know it's too large of a breaking change and will never land in the language but I can dream right?


👤 eternityforest
Ditch the general purpose variable annotations thing and make strong typing types first class

👤 mdwalters
Multi-line lambda. It would be more easier to use than cramming a piece of code into a single line.

👤 pm2222
I want braces.