result = all (1, 2, 3) # TypeError: all() takes exactly one argument (3 given)
result = all [1, 2, 3] # TypeError: 'builtin_function_or_method' object is not subscriptable
result = all {1, 2, 3} # SyntaxError: invalid syntax
Have you considered not changing the syntax at all but just having the interpreter recognize code like any(key in m for m in self.maps) and handle it differently if any turns out to be the built-in function?
Isn’t that only possible with the JIT compiler? It might be, but it feels like it would be even more work. And it’s not sure if it would even leave experimental phase before 3.13 reaches end of life.
No, it’d be possible without the JIT. In fact, that kind of special case would be unnecessary with the JIT, since the JIT accomplishes much the same thing, but in a more general way.
OK, if someone can implement that, I’m all aboard. Otherwise we need new syntax.
About that @pf_moore, I know you said you didn’t intend to get into further debate on this proposal, but does this look better to you? I’m just asking for your opinion.
If you’ve been using Python for years, you might have noticed that different syntax/functions yield different performance results in different Python versions.
Remember, Python isn’t primarily about speed; it’s about ease of use. Nonetheless, it’s fast enough for 99% of real-world use cases.
Whatever micro-optimizations you see merged in CPython, they may need to be reverted in the next version. I wouldn’t bother merging them at all.
You’re not just searching for the built-in all or any. Your search also includes user-defined all or any functions (or methods).
Furthermore, these numbers don’t matter much if these built-in functions aren’t being used in tight loops. They won’t significantly impact the performance of the application. That’s why they’re called micro-optimizations; their effects are negligible.
Rest assured, if performance is critical, users will resort to C extensions or even assembler.
It’s not simple to filter them out. And that actually strengthens my argument as it decreases the percentage.
I haven’t figured out how to call C code from a python repository downloaded straight from GitHub, so I currently need to optimise my Python code as well as I can.