Email [Python-projects] Problems with new-style class inheritance and base class methods and attributes.

from
subject
[Python-projects] Problems with new-style class inheritance and base class methods and attributes.
date
2005/04/21 21:36
Bonjour a tous!

Pylint 0.6.4 complains with an access to undefined member when a class 
derived from the built-in file class accesses file members.  Pychecker, 
on the other hand accepts the code with no error or warnings.

The following code works just fine but generates several Pylint errors 
(see the report after the code):

# F i l e         -- Testing inheritance from file --
# ^^^^^^^
#
class File(file):
     """ Testing new-style class inheritance from file"""

     #
     def __init__(self, name, mode="r", buffering=-1, verbose=False):
         """Constructor"""

         self.was_modified = False
         self.verbose = verbose
         super(File, self).__init__(name, mode, buffering)
         if self.verbose:
             print "File %s is opened.  The mode is: %s" % (self.name, 
self.mode)

     #
     def write(self, a_string):
         """ Write a string to the file."""

         super(File, self).write(a_string)
         self.was_modified = True

     #
     def writelines(self, sequence):
         """ Write a sequence of strings to the file. """

         super(File, self).writelines(sequence)
         self.was_modified = True

     #
     def close(self) :
         """Close the file."""

         if self.verbose:
             print "Closing file %s" % self.name

         super(File, self).close()
         self.was_modified = False


# --- Running PyLint check              ---
# Pylint control file: c:\dev\python\pylintrc.txt
# C:\dev\python\test_pylint\test_file.py:15: [E0201, File.__init__] 
Access to undefined member 'mode'
# C:\dev\python\test_pylint\test_file.py:15: [E0201, File.__init__] 
Access to undefined member 'name'
# C:\dev\python\test_pylint\test_file.py:36: [E0201, File.close] Access 
to undefined member 'name'


-- 
Pierre Rouleau

_______________________________________________
Python-Projects mailing list
Python-Projects@lists.logilab.org
http://lists.logilab.org/mailman/listinfo/python-projects