Honestly I was thinking the same thing when I read it! Looks like it's obfuscation work mainly, which I guess is actually a valid, if not bizarre, use case for it. The thread on that issue is pure gold though, reference [5] if you wanna look for yourself!
That guy was upset over a technicality with hilariously linear thinking. He IS technically right that right now, the syntax is supported and I do see his point that you should’n make a warning something that is technically supported. What he failed to realize that the warning has some sort of future (to be made into an error) meaning.
Fun fact, the syntax highlining library, that Discords uses, knows about the optional whitespace issue. What this means is that syntax highlighting properly highlights it. I am not sure if this was intentional or not. I am guessing the latter.
That kind of short circuit evaluation annoys me because it does create these weird ambiguities if you're not reading carefully. However, the third example makes perfect sense because (1) will be interpreted as just 1 and (1,) will be evaluated as a tuple containing a single item which is 1. This also really shows the inspiration of early BASIC's in Python's design.
Short circuit evaluation is when B is not evaluated in A or B if A is True. This is not that, it's just some lenient parsing which happens to allow some unfortunate things.
@@phobos.anomaly '0': start of a number; 'x': mode switch to hex number; '_': continuation of a number, used as visual spacing; 'f': hex character, we've now got 15; 'o': not hex, short circuit here, return to normal mode;
@@phobos.anomaly, this user is complaining about short circuit evaluation, though. Take the first example: `0x_for x in [1, 2, 3]`. There are three parts that python sees here (as you said, leniency): `0x_f`, `or`, and `x in [1, 2, 3]`. Python evaluates `0x_f` to be a non-zero number (i.e. truthy), then it gets to the `or` statement; since it already has a truthy value (0x_f) it short circuits here, never evaluating `x in [1, 2, 3]`.
@@dandyexplorer4252the font they are using has a ligature, which is: when 'x' is in a hexadecimal number, it will be made a little smaller and centred vertically, like '×'. its the same character, the font is just rendering it slightly different. many people (including me) consider this to be a little nicer to read. idk what font it is, but Fira Code does exactly this so it might be that.
@@andrew_ray Evaluating an undefined variable is an error, but not a syntax error. Thus, while I don't know whether Python can be parsed by a linear parser, I don't think the short-circuiting behavior or `and` and `or` has any influence of what parsers can be used, as long as parsing and evaluating are separate steps.
@@zTJq40sl A linear parser would have no way of knowing that it should stop parsing the hex literal after 0x_b. It would have to tokenize that sequence as "0x_ba/nd/ /saw" which would result in a syntax error since "nd" isn't a valid operator.
@Carberra here's one... >>> (False == False) in [False] False >>> False == (False in [False]) False >>> False == False in [False] # what does this print? ???
Not quite, Python 3.10 introduced features with syntax not possible using LL(1). I think the match statement? Something about the use of soft keywords iirc.
@@Carberra Do any of those changes break previously working code (even if it obviously shouldn't code, as is the case with the examples given in this video)?
I don't know what possessed me but here's a funny thing: ``` from warnings import filterwarnings as enemies # We do not overlook enemies enemies('ignore') # Instead, we silence them pledge = bool # Our pledge is resolute pledge(0x_for honor_x0) # The moment of truth: are we people of honor? ```
It's syntax that's correct but considered unwanted. What else are C compiler warnings? They're valid constructs that are probably a bad idea and warrant another look.
@phobos.anomaly ah you are right, I totally missed that. In any case I *strongly hoped* that this thing here is unambiguously classified as a syntax error
@@cn-ml Oh I agree, allowing this syntax is bad for everyone (ok except obfuscated code competitions :P). But disallowing it is backwards incompatible, so I get they want to be careful about it. I hope the warning paves the road for turning it into an error in the future.
SyntaxWarning is a weird concept for a weird situation. It's basically "this syntax is not supposed to be valid, but the interpreter accepts it, and if we make the interpreter raise a SyntaxError like it should, things break"
Hope this helps :) >>> from pathlib import Path >>> words = Path("common-words.txt").read_text().split(" ") >>> len(words) 5000 >>> HEX_LETTERS = set("abcdef") >>> hex_words = [word for word in words if set(word) >> hex_words ['face', 'feed', 'dead', 'deed']
I'll definitely use (1,)in((1,),) in real world instead of while True....
😊
pagan
"=="=="==" is my go-to for True.
Use variables. With single-letter polish prefixes and numeric suffixes. It's better.
while t1 in tt1
Also works with imaginary numbers !
3jor 1 returns (0 + 3i)
A good follow up video would be about what that guy was doing to get upset over them making it a warning
Honestly I was thinking the same thing when I read it! Looks like it's obfuscation work mainly, which I guess is actually a valid, if not bizarre, use case for it.
The thread on that issue is pure gold though, reference [5] if you wanna look for yourself!
That guy was upset over a technicality with hilariously linear thinking. He IS technically right that right now, the syntax is supported and I do see his point that you should’n make a warning something that is technically supported. What he failed to realize that the warning has some sort of future (to be made into an error) meaning.
Fun fact, the syntax highlining library, that Discords uses, knows about the optional whitespace issue. What this means is that syntax highlighting properly highlights it. I am not sure if this was intentional or not. I am guessing the latter.
Reminds me we should read "The zen of Python" few more times 🤗
I did a search through a large dictionary of words. There really isn’t anything common except for “decor” and the Russian name “Fedor”.
1:03 : the third one is just expected behavior? What’s weird about it?
2:48 : ah, ok, yes it is missing the white space, sure
Yea, I thought the 3rd one seemed fine, too.
That kind of short circuit evaluation annoys me because it does create these weird ambiguities if you're not reading carefully. However, the third example makes perfect sense because (1) will be interpreted as just 1 and (1,) will be evaluated as a tuple containing a single item which is 1. This also really shows the inspiration of early BASIC's in Python's design.
Short circuit evaluation is when B is not evaluated in A or B if A is True.
This is not that, it's just some lenient parsing which happens to allow some unfortunate things.
@@phobos.anomaly '0': start of a number; 'x': mode switch to hex number; '_': continuation of a number, used as visual spacing; 'f': hex character, we've now got 15; 'o': not hex, short circuit here, return to normal mode;
@@anon_y_mousse "short circuit evaluation" means a very specific thing in the context of programming languages, and this is not it. Look it up.
@@phobos.anomaly This is one of the contexts in which it is applied.
@@phobos.anomaly, this user is complaining about short circuit evaluation, though. Take the first example: `0x_for x in [1, 2, 3]`. There are three parts that python sees here (as you said, leniency): `0x_f`, `or`, and `x in [1, 2, 3]`. Python evaluates `0x_f` to be a non-zero number (i.e. truthy), then it gets to the `or` statement; since it already has a truthy value (0x_f) it short circuits here, never evaluating `x in [1, 2, 3]`.
Did you write the second example with multiplication symbol instead of 'x'?
nope, he's just FaNcY and uses a font with ligatures that prettyprints, so to say, stuff like "0xdeadbeef"
I like being FaNcY! But yes, it is ligatures.
@@Carberra What do you mean? That you wanted people to think it is 'x' and not *?
@@dandyexplorer4252 no, ligatures. A special font feature
@@dandyexplorer4252the font they are using has a ligature, which is: when 'x' is in a hexadecimal number, it will be made a little smaller and centred vertically, like '×'. its the same character, the font is just rendering it slightly different. many people (including me) consider this to be a little nicer to read. idk what font it is, but Fira Code does exactly this so it might be that.
That thumbnail gave me a headache...
What happens with `0x_band saw`?
It will error unless the variable "saw" is defined as it will check both. If it's defined, it'd be fine though!
@@Carberra That's wild, because that means Python can't be parsed with a linear parser.
@@andrew_ray Evaluating an undefined variable is an error, but not a syntax error. Thus, while I don't know whether Python can be parsed by a linear parser, I don't think the short-circuiting behavior or `and` and `or` has any influence of what parsers can be used, as long as parsing and evaluating are separate steps.
@@zTJq40sl A linear parser would have no way of knowing that it should stop parsing the hex literal after 0x_b. It would have to tokenize that sequence as "0x_ba/nd/ /saw" which would result in a syntax error since "nd" isn't a valid operator.
On my PC, when I run it with Python 3.12.0, it gives 'SyntaxError: invalid hexadecimal literal', no matter if 'saw' is defined or not.
i teach programming languages at university, and i started collecting these a few years ago. i call them coding shenanigans. this is getting added!
Care to share a few of your favourites? I'd be interested to know!
@Carberra here's one...
>>> (False == False) in [False]
False
>>> False == (False in [False])
False
>>> False == False in [False] # what does this print?
???
So these are basically puns in python
So basically python developers are so traumatized by the 2 -> 3 transition that they're afraid to fix obvious parser bugs
Not quite, Python 3.10 introduced features with syntax not possible using LL(1). I think the match statement? Something about the use of soft keywords iirc.
@@Carberra Do any of those changes break previously working code (even if it obviously shouldn't code, as is the case with the examples given in this video)?
python is clearly not following the zen of python at this point
Never did
Sloppy tokenization.
I don't know what possessed me but here's a funny thing:
```
from warnings import filterwarnings as enemies # We do not overlook enemies
enemies('ignore') # Instead, we silence them
pledge = bool # Our pledge is resolute
pledge(0x_for honor_x0) # The moment of truth: are we people of honor?
```
Sorry, but wtf is a syntax *warning* ?? Either it is correct syntax or it is not. What is going on here?
SyntaxWarnings are typically used to warn people of deprecated syntax, and become SyntaxErrors in later versions.
It's syntax that's correct but considered unwanted.
What else are C compiler warnings? They're valid constructs that are probably a bad idea and warrant another look.
@phobos.anomaly ah you are right, I totally missed that. In any case I *strongly hoped* that this thing here is unambiguously classified as a syntax error
@@cn-ml Oh I agree, allowing this syntax is bad for everyone (ok except obfuscated code competitions :P).
But disallowing it is backwards incompatible, so I get they want to be careful about it. I hope the warning paves the road for turning it into an error in the future.
SyntaxWarning is a weird concept for a weird situation. It's basically "this syntax is not supposed to be valid, but the interpreter accepts it, and if we make the interpreter raise a SyntaxError like it should, things break"
Hope this helps :)
>>> from pathlib import Path
>>> words = Path("common-words.txt").read_text().split("
")
>>> len(words)
5000
>>> HEX_LETTERS = set("abcdef")
>>> hex_words = [word for word in words if set(word) >> hex_words
['face', 'feed', 'dead', 'deed']
Looks cool... need to find common-words.txt file somewhere...
@sarimbinwaseem Google for "English words txt"!
Aah, that's cool! Would be interesting to use that to see how many possible words there actually are (including those that end in "or").
The most memorable for me is 0xCAFEBABE which is first four bytes of the Java class file)
Deadbeef c0dedbad