Can I use a builtin name as a method name of a Python class?
<p>I have a class that performs some simple data manipulation, I need three methods: set, add, sub:</p>

<pre><code>class Entry():  # over-simplified but should be enough for the question
    def __init__(self, value):
        self.set(value)
    def set(self, value):
        self.value=value
    def add(self, value):
        self.value += value
    def sub(self, value):
        self.value -= value
</code></pre>

<p>The problem is with the "set" method but defining it as a class method should not clash with the "set()" builtin function.</p>

<p>The <a href="https://www.python.org/dev/peps/pep-0008/#function-and-method-arguments" rel="nofollow" title="Python Style Guide">Python Style Guide</a> states that argument names of functions and methods should not shadow built-in functions, but it's this the case for method names?</p>

<p>Obviously I could choose another method name, but the question is more generic and valid for other possible method names (i.e. filter, sum, input).</p>

<p>The whole thing about not shadowing builtin names is that you don't want to stop your self from being able to use them, so when your code does this:</p>

<pre><code>x.set(a) #set the value to a
b = set((1,2,3)) #create a set
</code></pre>

<p>you can still access the builtin <code>set</code> so there is no conflict, the only problem is if you wanted to use <code>set</code> <strong>inside the class definition</strong></p>

<pre><code>class Entry():
    def __init__(self, value):
        self.set(value)
    def set(self, value):
        self.value=value
    possible_values = set((1,2,3,4,5)) #TypeError: set() missing 1 required positional argument: 'value'
</code></pre>

<p>Inside the class definition - and there only - is the built in name shadowed, so you have to consider which you would rather settle for: the unlikely scenario where you try to use <code>set</code> inside the class definition and get an error or using a non-intuitive name for your method.</p>

<p>Also note that if you like using method names that make sense to you and also want to use <code>set</code> in your class definition you can still access it with <code>builtins.set</code> for python 3 or <code>__builtin__.set</code> for python 2.</p>

python pep8