S
S
sazhyk2018-05-18 10:57:01
Python
sazhyk, 2018-05-18 10:57:01

Why is PyCharm giving such a warning?

There is such an example

Example
class Person:

    def __init__(self):
        pass

    def foo(self, name=None):

        def __init__(self):
            self.name = name

        result = []
        result = result.append(name)
        return result

PyCharm prompts
Screen
5afe8688d87e4276350148.png

Is this a bug in the code? Where am I making this mistake? What needs to be done to fix it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gornostaev, 2018-05-18
@sazhyk

The translation of the warning is "hides the name 'self' from the outer scope". What it means is that the selfnested function __init__argument overrides the selfenclosing method argument foo. If inside this __init__you need to refer to the outer selfone, you can't do that. If you don't need it, then don't worry. And if necessary, the selfnested function must be renamed to something.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question