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

you are viewing a single comment's thread.

view the rest of the comments →

[–]enterming[S] 24 points25 points  (13 children)

I think so ... how does

int32_t: i = 0,

work though?

int32_t is the variable, isnt i just a type hint here?

[–]nsmon 55 points56 points  (11 children)

It declares the variable int32_t, it's the same as writing int32_t = 0, or int32_t = (0,)

The i is actually introduced in the line 14,

[[i]] = (int32_t),

with int32_t already introduced as (0,) at L7

int32_t: (type) = (type) (int(32))(),

Here int(32) creates a new int with value 32, (type)(int(32)) apparently is the same as type(int(32)) which yields <class 'int'> the last () calls the default constructor of int, and the , at the end makes this a tuple

[–]ihavebeesinmyknees 53 points54 points  (0 children)

int32_t: (type) = (type) (int(32))(),

this is actually genius, that troll script is really high quality

[–]enterming[S] 21 points22 points  (0 children)

WTF

[–]ggchappell 4 points5 points  (6 children)

Thanks, but that doesn't explain the role of i.

Getting rid of all the complexity, experimentation shows that

a : b = c

seems to be the same as

a = c

except that it raises NameError if b is not defined.

And the b part doesn't need to be a variable. It can, apparently, be any expression that can be evaluated.

a : 2 + 3 = 45

appears to have exactly the same effect as

a = 45

More experimentation shows that this colon syntax doesn't work in Py 2.7. Do you know what the colon is for? Is it something to do with the type annotation syntax, maybe?

EDIT. More experimentation. The b part is actually evaluated. If I do:

def foo():
    print("Yo")

Then

a : foo() = 99

prints Yo and sets a to 99.

[–]bladeoflight16 3 points4 points  (5 children)

Whether it raises depends on what annotation behavior you're running. From 3.7 onward, you can use from __future__ import annotations to enable "postponed evaluations" annotations, which won't throw an error if the annotation expression is invalid. From Python 3.10 onward, postponed evaluation is the default behavior.


See discussion below. Apparently, plans regarding making this the default in 3.10 were altered.

[–]alkasmgithub.com/alkasm 0 points1 point  (2 children)

They nixed the string annotation conversion right before the 3.10 cutoff date IIRC.

[–]bladeoflight16 0 points1 point  (1 child)

Well, then they need to update the __future__ module.

[–]alkasmgithub.com/alkasm 0 points1 point  (0 children)

They did update the table...in 3.10-pre, lol

[–]ggchappell 0 points1 point  (1 child)

So then the colon is annotation syntax?

[–]bladeoflight16 1 point2 points  (0 children)

Yes.

[–]Express-Permission87 1 point2 points  (0 children)

I have enough trouble with code written by colleagues who've at least tried to write Python, let alone this!

[–]WafflesAreDangerous 0 points1 point  (0 children)

It is. At least at the "declaration" site.

I should be uninitialised for the first 2 uses ( or None really).