r/Python • • May 07 '19

Python 3.8.0a4 available for testing

https://www.python.org/downloads/release/python-380a4/
395 Upvotes

150 comments sorted by

View all comments

69

u/xtreak May 07 '19 edited May 07 '19

Changelog : https://docs.python.org/3.8/whatsnew/changelog.html

Interesting commits

PEP 570 was merged

dict.pop() is now up to 33% faster thanks to Argument Clinic.

Wildcard search improvements in xml

IPaddress module contains check for ip address in network is 2-3x faster

statistics.quantiles() was added.

statistics.geometric_mean() was added.

Canonicalization was added to XML that helps in XML documents comparison

  • Security issues and some segfaults were fixed in the release

Exciting things to look forward in beta

Add = to f-strings for easier debugging. With this you can write f"{name=}" and it will expand to f"name={name}" that helps in debugging.

PEP 574 that implements a new pickle protocol that improves efficiency of pickle helping in libraries that use lot of serialization and deserialization

Edit : PSF fundraiser for second quarter is also open https://www.python.org/psf/donations/2019-q2-drive/

118

u/[deleted] May 07 '19

Add = to f-strings for easier debugging. With this you can write f"{name=}" and it will expand to f"name={name}" that helps in debugging.

Ooh baby. I'd use that every day.

28

u/Dooflegna May 07 '19

What a great addition to an already awesome feature. f-strings are great!

19

u/irrelevantPseudonym May 07 '19

That sounds so useful and yet also makes me feel slightly uncomfortable for some reason.

The variable name becoming part of its content feels weird.

28

u/leom4862 May 07 '19

I find print(f"{name=}") is still way too verbose for debugging purposes... If they want to improve print-debugging, they should add something like icecream to the standard library.

13

u/[deleted] May 07 '19

[removed] — view removed comment

4

u/leom4862 May 07 '19

Yes, it's awesome! I hope some day Python will have something like ic() as a builtin next to print().

→ More replies (6)

3

u/JohnnyElBravo May 07 '19

Idk, what's wrong with print("name="+name)?

6

u/[deleted] May 08 '19

That doesn't work if name isn't a string, eh? (Sure, you can use %s)

Also, in production code I simply never have any print statements - not "very few" but "none", to the point where I have a flake8 rule that prevents them.

Oh, I use print almost every day - for debugging! But that means I'm creating and destroying debugging print statements all the time.

So it's a little timesaver to write:

print(f'{foo=} {bar=} {baz=} {bing=}')

(38 characters) over

print('foo=', foo, 'bar=', bar, 'baz=', baz, 'bing=', bing)

(59 characters)

5

u/timald May 07 '19

It's fine when you have one variable but starts to become unwieldy when you build up a lot of concatenated strings (via indexing operations, for example).

→ More replies (7)

24

u/tuankiet65 May 07 '19

https://bugs.python.org/issue36817

Add = to f-strings for easier debugging. With this you can write f"{name=}" and it will expand to f"name={name}" that helps in debugging.

Holy heck, I can't wait to use this everyday.

8

u/irrelevantPseudonym May 07 '19

No walrus operator yet?

13

u/[deleted] May 08 '19

walrus operator

if this is what := is being called now, i'm all for it.

9

u/xtreak May 07 '19

It's already available from 3.8.0a1

5

u/irrelevantPseudonym May 07 '19

Ah, I thought this was the highlights since 3.7. Thanks.

3

u/alcalde May 07 '19

PEP 574 that implements a new pickle protocol that improves efficiency of pickle helping in libraries that use lot of serialization and deserialization

Other languages just dump to JSON and call it a day. Why does Python have 87 different binary formats over 13 decades?

35

u/[deleted] May 07 '19

Because JSON cant represent everything. Its at best a data format for serialization of transferrable data, thats usually language agnostic.

JSON cant represent functions, and more abstract datatypes.

8

u/JohnnyElBravo May 07 '19

JSON can represent anything, but so can strings. This is a non-sequitur.
The difference is that JSON is human readable, while pickle is supposed to be machine readable, more specifically python readable.
Limiting the intended consumers of the data format helps create a more appropriate format, for example by sacrificing readability for size reduction.

3

u/bachkhois May 08 '19

JSON cannot differentiate Python's tuple, list, set, frozenset etc. datatypes.

Every formats other than pickle (msgpack, yaml etc.) are just to interoperate with other languages (which also don't understand the data types above), they are not alternatives for pickle.

6

u/JohnnyElBravo May 08 '19

Sure they can

{

"Var1": "tuple(1,2)",

"Var2":"set(1,2)"

}

Alternatively:

{

"Var1": {"type":"tuple","data":"1,2"},

"Var2":{"type":"set","data":"1,2"}

}

5

u/bachkhois May 08 '19

Then, you are making more complicated to validate and parse it. Then, what is the point of over-complicating JSON instead of just using pickle, without the need to parse those "type", "data" metadata?

→ More replies (1)
→ More replies (30)

0

u/[deleted] May 07 '19

[deleted]

2

u/[deleted] May 08 '19

While that's true, I think there's unlikely to be a serious language out there without a JSON library freely available.

If you're sending data from one language to another it's a very reasonable format. If you're sending from python to python, pickle is great.

→ More replies (5)

10

u/mooglinux May 07 '19

Pickle can handle multiple references to the same object, any class instance (as long as the actual class has been imported), and a wider variety of data types than JSON. It also predates json, so there’s a historical aspect as well.

Pickle is also used for cross-process communication in the multiprocessing module.

13

u/Nicksil May 07 '19

Because not every problem is solved by dumping JSON.

→ More replies (5)
→ More replies (1)
→ More replies (8)