Missing cls in class method

Class methods should take cls as the first argument.

The @classmethod decorator converts the method to a class method.

When the class method is called, Python will implicitly pass in the class as the first argument, just like how an instance method receives the instance (self, by convention).

While it is true that the first argument could be called anything, Python should be written to be read, and Python developers expect the first argument of class methods to be named cls.

If our GitHub code review bot spots this issue in your pull request it gives this advice:

code-review-doctorbotsuggested changes just now
class FooBarClass:
    def from_dict(self):
Suggested changes
    def from_dict(self):
    def from_dict(cls):
Commit suggestion

Class methods should take cls as the first argument.

Read more
Update models.py
We're your Python code review copilot. Get code improvements right in your pull request with our GitHub code review bot.

Configuring this check

Code Review Doctor will run this check by default. No configuration is needed but the check can be turned on/off using check code class-method-missing-cls in your pyproject.toml file.

Read more about configuring Code Review Doctor.