Python class members type hinting

PyCharm’s suggest is right. In fact, I think the following code is better:

class DataAnalyzer:
    train_data: pd.DataFrame
    test_data: pd.DataFrame

    def __init__(self, train_data, test_data):
        self.train_data = train_data
        self.test_data = test_data

    def analyze(self):
        pass

Explain:

  • Annotate a member does not make it static.
  • We should not annotate arguments in the __init__ function again.
  • -> None after __init__ can be omitted. For __init__ never return a value.

Leave a Comment

tech