Today at work I completely had my mind blown by something that turned out to be completely normal behavior from the lexical analysis of the python interpreter and would like to share, and hear if this is really common knowledge.
I was reviewing code for one of my colleagues and came across something to the effect of:
if self. some_member: do_something()
When I noticed the space after the self. I thought he had made a typo, and could not have tested his code, since I would expect it to fail. He maintained however that the code was tested and working, so I had to think again.
After looking into it - mainly throught the python documentation for lexical analysis - I had to admit that his code, however unpleasing, worked like a charm.
I find the fact that the dot is treated the same as the parenthesis quite surprising, and a line like the above looks positively wrong. What’s even more surprising is the fact that no inspection was triggered in PyCharm which also seemed to find the code completely by the book.
I’m thinking this might be done for simplicity in the lexical analyser, and that there might be no inspection for the given case because people never write like this.
Please share any input to the how and why of it along with any similar surprises you might have had