Back to blog

Aug 15, 2022

Common Python Mistakes #1: Mixing Up Instance and Class Members

Don't mix up Python class variables and instance variables. Here is a common Python mistake we see in PRs for robusta.dev on GitHub.

Common Python Mistakes #1: Mixing Up Instance and Class Members

Don't mix up Python class variables and instance variables

Here is a common Python mistake we see in PRs for robusta.dev on GitHub:

class Person:
  name: str

  def __init__(self, name):
    self.name = name

Don't do this!

There are two variables defined in the above code.

First, there is a class variable name: str on line 2.

Second, there is an instance (member) variable self.name on line 5.

Those two variables have nothing to do with one another.

They happen to share the same name, but that's all. The instance variable on line 5 overrides the class variable on line 2.

See it running in your environment.

We'll help you get Robusta installed on your cluster and walk through a live incident.

Prefer to tell us about your setup first?