Skip to content
Advertisement

“parameter ‘self’ unfilled” when using decorators, even after instantiating object

I’m using a decorator with parameters to do something with an instance attribute (self.x in this example, if track_bool is true). However when running I get the “parameter ‘self’ unfilled” error when calling b.do(). From what I understand this error is supposed to appear when calling an instance method before instantiating an object, so I don’t understand why it appears in this case when I’ve used b=B(). Is this something to do with the fact I’m using decorators ? Help please !

Edit: The code does run, but I would like to understand the error so that it doesn’t risk breaking anything when running with the rest of my code.

JavaScript

Here is the image of the error: PyCharm IDE message

Advertisement

Answer

Ok, this is PyCharm being a tiny bit too eager. You should submit a bug report for this because your code is actually working just fine and you don’t want to have to go round suppressing all calls to decorated methods.

Here is a work-around. You can change the decorator to not have an explicit self parameter:

JavaScript

Note how you can still get hold of self because it is guaranteed to be the first element of args.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement