should these be fixed for python 2.4?

Alexander Schmolck a.schmolck at gmx.net
Fri Oct 1 16:33:39 EDT 2004


"Martin v. Löwis" <martin at v.loewis.de> writes:

> Alexander Schmolck wrote:
>> 1. ``os.system`` (and co): Shouldn't ``os.system``'s signature really be
>>    ``os.system(cmd, arg1, arg2,...)`` rather than ``os.system(some_string)``?
>
> No. This is a direct exposition of the system(3) function of the C
> library, and has precisely the same interface like this function.
> Use os.spawnv for what you want.

OK, but let me say that this is *not* obvious -- it is difficult to find in
the docs (I don't really want to spawn anything and it's burried amongst a
zillion cryptically named similar functions with a complex interface) and
difficult to use.

So I think many (most?) people will use os.system instead and in a way that is
broken. If changing system is a bad idea, how about introducing a convenience
function or adding a note to the os.system docs?


>> 2. pydoc's handling of overriden methods without docstrings: I really think it
>>    should show the documentation of the method in the baseclass; the current
>>    behavior really sucks when working with things like backends.
>
> Feel free to contribute a patch.

I would if I hadn't trouble with sf.net. I'll try again over the weekend but
if someone else would like to submit it, it's appended below.

>
>> I currently use this to run e.g. latex, but it doesn't seem to work absolutely
>> reliably and is unix only. I'm pretty sure there must be a better way.
>
> I don't think there is.
>
> Regards,
> Martin

*** pydoc.py.old	Fri Oct  1 19:14:54 2004
--- pydoc.py	Fri Oct  1 21:29:42 2004
***************
*** 72,78 ****
      return dirs
  
  def getdoc(object):
      """Get the doc string or comments for an object."""
!     result = inspect.getdoc(object) or inspect.getcomments(object)
      return result and re.sub('^ *\n', '', rstrip(result)) or ''
  
--- 72,103 ----
      return dirs
  
+ _method_types = (staticmethod, classmethod, types.MethodType,
+                 types.BuiltinMethodType, types.FunctionType)
+ def _getdoc_helper(thing):
+     """Like `inspect.getdoc` but for methods with no documentation it
+        retrieves the documentation from a baseclasses corresponding method, if
+        possible."""
+     if inspect.getdoc(thing):
+          return inspect.getdoc(thing)
+     else:
+         def find_method_doc(c, name):
+             v = c.__dict__.get(name)
+             return isinstance(v, _method_types) and inspect.getdoc(v)
+         if isinstance(thing, _method_types):
+             try:
+                 the_class = thing.im_class
+                 func_name = thing.im_func.func_name
+                 for c in inspect.getmro(the_class)[1:]:
+                     if find_method_doc(c, func_name):
+                         return find_method_doc(c, func_name)
+                 return None
+             except AttributeError, msg:
+                 print >> sys.stderr,\
+                       "Couldn't get doc from baseclass for %s: %s" % (thing, msg)
+         return None
+     
  def getdoc(object):
      """Get the doc string or comments for an object."""
!     result = _getdoc_helper(object) or inspect.getcomments(object)
      return result and re.sub('^ *\n', '', rstrip(result)) or ''
  



More information about the Python-list mailing list