|
109 | 109 | import math |
110 | 110 | import time |
111 | 111 | import os |
| 112 | +import inspect |
112 | 113 |
|
113 | 114 | from os.path import isfile, split, join |
114 | 115 | from copy import deepcopy |
@@ -3889,31 +3890,35 @@ def read_docstrings(lang): |
3889 | 3890 |
|
3890 | 3891 |
|
3891 | 3892 | def getmethparlist(ob): |
3892 | | - "Get strings describing the arguments for the given object" |
3893 | | - argText1 = argText2 = "" |
| 3893 | + """Get strings describing the arguments for the given object |
| 3894 | +
|
| 3895 | + Returns a pair of strings representing function parameter lists |
| 3896 | + including parenthesis. The first string is suitable for use in |
| 3897 | + function definition and the second is suitable for use in function |
| 3898 | + call. The "self" parameter is not included. |
| 3899 | + """ |
| 3900 | + defText = callText = "" |
3894 | 3901 | # bit of a hack for methods - turn it into a function |
3895 | 3902 | # but we drop the "self" param. |
3896 | 3903 | # Try and build one for Python defined functions |
3897 | | - argOffset = 1 |
3898 | | - counter = ob.__code__.co_argcount |
3899 | | - items2 = list(ob.__code__.co_varnames[argOffset:counter]) |
3900 | | - realArgs = ob.__code__.co_varnames[argOffset:counter] |
| 3904 | + args, varargs, varkw = inspect.getargs(ob.__code__) |
| 3905 | + items2 = args[1:] |
| 3906 | + realArgs = args[1:] |
3901 | 3907 | defaults = ob.__defaults__ or [] |
3902 | | - defaults = list(map(lambda name: "=%s" % repr(name), defaults)) |
| 3908 | + defaults = ["=%r" % (value,) for value in defaults] |
3903 | 3909 | defaults = [""] * (len(realArgs)-len(defaults)) + defaults |
3904 | | - items1 = list(map(lambda arg, dflt: arg+dflt, realArgs, defaults)) |
3905 | | - if ob.__code__.co_flags & 0x4: |
3906 | | - items1.append("*"+ob.__code__.co_varnames[counter]) |
3907 | | - items2.append("*"+ob.__code__.co_varnames[counter]) |
3908 | | - counter += 1 |
3909 | | - if ob.__code__.co_flags & 0x8: |
3910 | | - items1.append("**"+ob.__code__.co_varnames[counter]) |
3911 | | - items2.append("**"+ob.__code__.co_varnames[counter]) |
3912 | | - argText1 = ", ".join(items1) |
3913 | | - argText1 = "(%s)" % argText1 |
3914 | | - argText2 = ", ".join(items2) |
3915 | | - argText2 = "(%s)" % argText2 |
3916 | | - return argText1, argText2 |
| 3910 | + items1 = [arg + dflt for arg, dflt in zip(realArgs, defaults)] |
| 3911 | + if varargs is not None: |
| 3912 | + items1.append("*" + varargs) |
| 3913 | + items2.append("*" + varargs) |
| 3914 | + if varkw is not None: |
| 3915 | + items1.append("**" + varkw) |
| 3916 | + items2.append("**" + varkw) |
| 3917 | + defText = ", ".join(items1) |
| 3918 | + defText = "(%s)" % defText |
| 3919 | + callText = ", ".join(items2) |
| 3920 | + callText = "(%s)" % callText |
| 3921 | + return defText, callText |
3917 | 3922 |
|
3918 | 3923 | def _turtle_docrevise(docstr): |
3919 | 3924 | """To reduce docstrings from RawTurtle class for functions |
|
0 commit comments