81 else: # this is the first time we're posting this menu
82 await self.ctx.interaction.response.send_message(embed=embed, view=self, ephemeral=self.whisper)
83
84 async def on_timeout(self): 85 self.stopped = True
86 self.refresh_button_state()
87 await self.refresh_response_message()
When a method has the same name as an attribute (defined in the ancestor class or the same class), the attribute takes precedence and hides the method. Python will throw an error when the method is called.
class Example:
def __init__(self, pie="Apple"):
self.pie = pie
def pie(self):
...
Here, if the class is instantiated with a value for pie
, the method pie
would be hidden.
So, a function call like this: Example("apple").pie()
will raise a run time error — TypeError: 'str' object is not callable
.
It is recommended to have different names for attributes and methods.
class Example:
def __init__(self, pie="Apple"):
self.pie = pie
def make_pie(self): # No longer shadowed by self.pie
...