You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I couldn't get python (neither 2.7, nor 3.5 or 3.7) to raise a Method could be a function error on your example (or reasonable variations, like actually calling Rectangle.area). If this is obsolete, please update the page to describe the behaviour of current python versions. Otherwise, update the example to reproduce the error.
Also, you refer to self and cls as keywords. At least in Python 3 they aren't. There is just a (pretty strong) convention to call the first parameter of an instance method self and the first parameter of a class method cls.
The text was updated successfully, but these errors were encountered:
This section and the section following it ("Method has no argument") present several examples as anti-patterns that are really just logical errors. The user will find out pretty quickly that not including self as an argument means that you can't reference self. We should nuke those examples.
The actual anti-pattern here is creating methods that should be functions, like so:
classFoo:
defbar(self, a, b): # should be a functionreturna+b
defbar(a, b):
returna+bclassFoo:
...
If it doesn't need the instance (or class in the case of @classmethod), it shouldn't be a method.
We should also note that the use of @staticmethod is discouraged. Guido has even pointed out that @staticmethod was a mistake.
I couldn't get python (neither 2.7, nor 3.5 or 3.7) to raise a
Method could be a function
error on your example (or reasonable variations, like actually calling Rectangle.area). If this is obsolete, please update the page to describe the behaviour of current python versions. Otherwise, update the example to reproduce the error.Also, you refer to
self
andcls
as keywords. At least in Python 3 they aren't. There is just a (pretty strong) convention to call the first parameter of an instance methodself
and the first parameter of a class methodcls
.The text was updated successfully, but these errors were encountered: