0

I have the following at the top of my file/module which says how various types are defined (sort of like a declaration in a C file):

Env = dict  # The Interpreter environment is a map of {key: value}

And then below in the actual meat of the code I redefine Env like so:

class Env(dict):
    "An environment dict, containing the parent Env (or None) where created."
    def __init__(self, parent=None):
        self.parent = parent
    # etc.

Pylint gives me the following warning:

function-redefined: class already defined line 16

I understand why it is giving this, but it is intentional in the above case. What would be the suggested way to deal with this? Doing something like the following seems to be the most expedient way (but then I find my files are just littered with all these comments every other line if I apply this "let's-dismiss-this-one-here" philosophy), but what would someone suggest in this particular case?

class Env(dict): # pylint: disable=function-redefinition

Additionally, what is the name for doing the # pylint: thing called? (Comment/Annotation/Pragma/?)


Additionally, here is a useful thread about type redefinitions in mypy: https://github.com/python/mypy/issues/1191.

David542
  • 104,438
  • 178
  • 489
  • 842
  • 1
    Does this answer your question? [How do I disable a Pylint warning?](https://stackoverflow.com/questions/4341746/how-do-i-disable-a-pylint-warning) – mkrieger1 Apr 02 '21 at 20:30
  • 1
    So what is the problem now? – mkrieger1 Apr 02 '21 at 20:32
  • @mkrieger1 I'm wondering for someone who uses linting, do they just litter their code with every time they want to silence a one-off warning with the comments? Or, from someone with experience using `pylint` what might be a good way to address this in a more holistic approach...let's see what some python developers have to say. – David542 Apr 02 '21 at 20:33
  • The answers I've linked list numerous other options. I'm sure you haven't evaluated them all within 2 minutes. – mkrieger1 Apr 02 '21 at 20:34
  • @mkrieger1 which one addresses function-redefinition? That's the question I'm asking. – David542 Apr 02 '21 at 20:35
  • @mkrieger1 but yes, thank you for the link. I'm reading those now, actually... (Seems to answer the more 'general' question, but not the specific case) – David542 Apr 02 '21 at 20:35
  • 2
    Why do you use `Env = dict` in the first place if you redefine it later? If you don't do that the whole problem goes away. – mkrieger1 Apr 02 '21 at 20:37

0 Answers0