How could I disable a python in-built function?
For example, I note that it is possible to reassign or overwrite len() (like len = None), but it is not possible to reassign list.__len__() , which raises:
TypeError: can't set attributes of built-in/extension type 'list'
However, even if reassignment were possible it seems easy to override. In this example, del len or from builtins import len would restore the original functionality of len().
The reason I ask is that on Codewars sometimes people want to set a coding challenge for a user to complete while forbidding the use of certain in-built functions. A trivial example could be determining the length of a list without using the length function.
On reflection, thanks to the comments I have already received and this related question, I now realize that a full-proof solution is very hard, but I'd still be interested in a pragmatic solution that could be useful in this context.
Thank you
__len__and an object's attribute named__len__are two completely different things.__len__is an attribute of thelisttype, while your example assigns a new variable to the global namespace. The right namespace would belist.__len__ = None, but you can't easily do that with types implemented in C.__len__you would have to do so for every object