Menu

#1384 Bogus "Assignment to reserved built-in symbol" warnings

closed-works-for-me
nobody
None
5
2011-09-14
2011-09-10
No

In PyDev 2.2.1.20110818, code like

class bla(object):
def open(self):
pass

results in a Bogus "Assignment to reserved built-in symbol: open" warnings from the PyDev code analysis. I believe this is bogus, since the build-in open function isn't actually being touched at all.

Discussion

  • Fabio Zadrozny

    Fabio Zadrozny - 2011-09-14
    • status: open --> closed-works-for-me
     
  • Fabio Zadrozny

    Fabio Zadrozny - 2011-09-14

    Actually, you're redefining the 'open' builtin method, so, it's not bogus. You can either Ctrl+1 in that line and choose to ignore that warning or you can disable that analysis at the preferences > PyDev > Editor > Code Analysis > Others > Redefinition of builtin symbols.

     
  • Nikolaus Rath

    Nikolaus Rath - 2011-11-21

    I think redefining symbols in class scope is a very different thing than redefining them in module- or function scope. There is very little chance of accidentally calling the overwritten method, since the only way to do so is if the function is called in the class body (see attached example).

    On the other hand, I consider the check for redefined buildins at module and function scope very useful, so I'd rather not disable it.

    I think the practice of using built-in names for class methods and attributes is also very common (and e.g. not reported by pylint), so in my opinion it would be great if this check could be modified to exclude class scope redefinitions.

     
  • Nikolaus Rath

    Nikolaus Rath - 2011-11-21

    Hmm. Can't seem to find a way to attach a file, so here it is with probably broken indentation (all 3 open calls have different indent):

    $ python test.py
    open redefined!

    $ cat test.py
    class scary(object):
    def open(self, *a):
    print "open redefined!"
    def test():
    open('/dev/null', 'rb')
    open('/dev/null', 'rb')
    open('/dev/null', 'rb')

     
  • Sorin Sbarnea (old)

    I think that nikratio is right, this warning is bogus, using def open(...) inside a class should be something that does not trigger any warning.

     
  • Nikolaus Rath

    Nikolaus Rath - 2011-12-05

    fabioz, any comment? Would you consider reopening this?

     
  • Nikolaus Rath

    Nikolaus Rath - 2012-01-12

    Hm. Maybe Fabio isn't getting notifications for closed issues. I've resubmitted this as issue 577329.