r/coding • u/RubiksCodeNMZ • May 11 '20
Python 3.9 - The Shape of Things to Come
https://rubikscode.net/2020/05/11/python-3-9-the-shape-of-things-to-come/6
u/burnblue May 11 '20 edited May 11 '20
blog_dict_merged = {**blog_dict1, **blog_dict2}
The ** operator unpacks elements from the dictionary. It is there since Python 3.5+. As you can see this is not intuitive and it takes a while to get used to it. In Python 3.9 you can use union operator | for merging two dictionaries, like this:
blog_dict_merged = blog_dict1 | blog_dict2
Clean, cool and intuitive.
Maybe I spend too much time in javascript. But to me the first one looks like "take stuff from dict1 and stuff from dict2 to make dict3" which is intuitive. The second one looks like "dict1 or dict2". Even if I don't see the pipe as an OR, it looks like one dict doing something to the other or feeding into the other as opposed to making a brand new 3rd dict... I can easily get used to this syntax but my point is while it may be clean there's nothing more "intuitive" about it. You have to learn it ie be told what it does.
4
u/freopen May 11 '20
Well, sets have this operation since forever, I think it's pretty intuitive to have the same operation for dicts.
1
u/burnblue May 11 '20
But while training in Python there's never been something always saying "keep set theory in mind". I mean that yes this is what it means for sets, but the pipe means something else in dozens of other contexts. If you're told "it's a union, like sets" you'll go "ah, ok, sure". But I don't expect someone to come along and take one look and decide that must be what it does in Python.
2
u/rocketpower4 May 11 '20
Yeah, not intuitive at all. I guess what they're arguing is that it is like a set of all items in dict1 OR dict2 but to me that only makes sense with types or immutable data structures.
5
4
u/Keevanar May 11 '20
So python will have now support for types? Does this mean it will potentially run faster?
6
u/metriczulu May 11 '20
Python has type support already, it's just pretty useless rn. It doesn't make it faster. Maybe one day.
0
May 11 '20
[deleted]
2
u/AReluctantRedditor May 11 '20
Let me know if you do this, I’d be interested in following the project.
1
u/metriczulu May 12 '20
I'm interested, what exactly is your plan? A completely new Python interpreter, a system for transpiling strongly typed Python to Cython, a brand new Python-esque language with an enforced type system?
0
2
u/yaxriifgyn May 11 '20
There are several good things I want to try out.
Here are the changes I made to test my local (i.e. just for me, not for all users) install. I updated "C:\WINDOWS\py.ini" to:
[defaults]
python=3.8
python3=3.8This allows both py [script] and py -3 [script] to use the latest python 3.8. When I want to test, I have to request it with py -3.9 [script].
Or, when I want my user to use 3.9 when I use py -3 [script] and 3.8 when I use py [script], I can change "C:\Users%USERNAME%\AppData\Local\py.ini" to:
[defaults]
python3=3.9
python=3.9HTH
8
u/wsppan May 11 '20
Topological Ordering looks very promising and useful.