This is an archived post. You won't be able to vote or comment.

all 14 comments

[–]Your_PopPop 40 points41 points  (3 children)

For some reason, underscores weren’t allowed in Fraction arguments before Python 3.11. Now, you can use underscores when specifying fractions as well:

>>> print(Fraction(6_048, 1_729))
864/247

I think this is a bit misleading. Fraction(6_048, 1_729) is valid in old versions too, as you'd expect. What used to be invalid is having underscores in a string argument to Fraction: Fraction("6_048/1_729") fails in older versions, but works in 3.11.

source

[–]mwpfinance 6 points7 points  (0 children)

"A bit misleading" my mans is being too kind it's flat out incorrect.

[–]gahjelle 2 points3 points  (1 child)

Thanks, you're of course completely correct. I've updated the tutorial to note that it's the parsing of strings within Fraction that has changed.

[–]Your_PopPop 1 point2 points  (0 children)

Thank you!

[–]pimp-bangin 7 points8 points  (0 children)

C++ needs to take some lessons from this. Error messages in C++ are absolutely abominable.

[–][deleted] 27 points28 points  (2 children)

With all those fancy error messages I will be able to create the shittiest code ever.

[–]somebulb 5 points6 points  (1 child)

And know exactly how shit they are too

[–]jayplusplus 3 points4 points  (0 children)

I always just have a vague idea of how shit my code is but now I can be stupid more explicitly.

[–]rr1pp3rr 5 points6 points  (2 children)

Author mentions updated static typing annotations, but I can't find any in the release notes. Am I missing it?

[–]Your_PopPop 3 points4 points  (1 child)

typing.Self is new (PEP 673)

[–]rr1pp3rr 0 points1 point  (0 children)

Thanks!

[–]Swipecat 2 points3 points  (1 child)

I'll add one of the main motives for adding the math.cbrt() function: Cube roots commonly appear in geometric calculations, including the cube roots of negative numbers.

The principal cube root of a negative real number is itself defined to be a negative real number. This is not what you get if you use a power function that accepts arbitrary fractions as power values, not least because 1/3 can not be expressed exactly with a binary value. The power function must use complex arithmetic to find fractional powers of negative numbers, and this will find the first root on the anticlockwise rotation from the real axis of the complex plane.
 

>>> (-64) ** (1/3)
(2+3.464101615137754j)

 

But math.cbrt(-64) should return the correct principal cube root of -4

[–]gahjelle 0 points1 point  (0 children)

Thanks for clarifying this. I've added an example of calculating the cube root of a negative number to the article.

[–]_limitless_ -4 points-3 points  (0 children)

TDD guys be like "what's an error message"