Suggestion/question for IntelliJ name shadowing?

Answered

class oops:
    shared_list = []

    def __init__(self, name):
        self.name = name
        self.shared_list = []

    def add_to_shared_list(self, item):
        self.shared_list.append(item)

    def show_shared_list(self):
        print(f"{self.name}: shared_list = {self.shared_list}")


So I'm not getting any notification that shared_list is being shadowed and was wondering if it might be a good idea to have it there? Or is it technically not being shadowed so it's not necessary? :o

0
2 comments

Hi S Jake D, this looks like a valid syntax with a class variable and instance variable. Please check out this thread with similar question: https://stackoverflow.com/a/12409963/23603774

0

Hey Mikhail,

Yup I understand that it's valid syntax, but my example is shadowing another variable name outside of its scope, so I was just suggesting that it might be a good idea for intellij to warn a user if they did such a thing.

0

Please sign in to leave a comment.