Python allows programmers to pass additional arguments to functions via comments.
Now armed with this knowledge head out and spread it to all code bases.
Feel free to use the code I wrote in your projects.
from lib import add
# Go ahead and change the comments.
# See how python uses them as arguments.
result = add() # 1 2
print(result)
result = add() # 3 4
print(result)
result = add() # 3 4 5 20
print(result)
I assume the people freaking out about how dumb python is didn't bother to read the code and have never coded in python in their life, because the behavior here is totally reasonable. Python doesn't parse comments normally, which is what you'd expect, but if you tell it to read the raw source code and then parse the raw source code for the comments specifically, of course it does.
The add function in the example above probably traverses the call stack to see what line of the script is currently being executed by the interpreter, then reads in that line in the original script, parses the comment, and subs in the values in the function call.
This functionality exists so when you get a traceback you can see what line of code triggered it in the error message
One case where I find it useful, tho it operates in a more limited way, is code in block blocks within code comments in Rust, which are also printed out in the generated documentation. They essentially get ran as part of your unit tests. This is great for making sure that, eg, your examples left in code comments actually work, especially if they’re written in a way that functions like a unit test.
The add() function (that is available in the source code) basically uses some built in debugging tools to find out where in the code the function is called, and then parses the comment from the file and uses it for adding stuff.
I’ve never tried (becuse why would you…) but something similar can probably be built in any interpreted language
One of Python’s design philosophies is—or at least was—“we are all consenting adults here.” If you really want to turn Python into Brainfuck, the interpreter isn’t going to stop you.
Makes sence if u think about it. We use comments as docstrings that the interpreter has an understanding of. Python lets u fuck with its internals (at least in an immutable manner) so why not fuck with comments.