Commits

Henning Schröder  committed 11005eb

working on supporting *args and **kwargs

  • Participants
  • Parent commits eeea2af

Comments (0)

Files changed (1)

File pycode/stubgen.py

     qDrawWinPanel(QPainter, QRect, QPalette, bool sunken=False, QBrush fill=None)
     qDrawShadeRect(QPainter, int, int, int, int, QPalette, bool sunken=False, int lineWidth=1, int midLineWidth=0, QBrush fill=None)
     qDrawShadeRect(QPainter, QRect, QPalette, bool sunken=False, int lineWidth=1, int midLineWidth=0, QBrush fill=None)
+    func1(*args)
+    func2(**kwargs)
+    func3(*args, **kwargs)
+    func4(x, *args, **kwargs)
+    func5(x, y=123, **kwargs)
     """
     
     example2 = """
                 state = ST_NORMAL
                 pos += 1
             elif state == ST_NORMAL:
-                if char == ",":
+                if char.isdigit():
+                    buf = char
+                    while pos < len(s) and char.isdigit():
+                        pos += 1
+                        char = s[pos]
+                    yield "NUMBER", int(buf)
+                elif char == ",":
                     yield "COMMA", ","
                     pos += 1
                 elif char in ('"', "'"):
                 elif char == "=":
                     pos += 1
                     yield "EQUALS", "="
+                elif char == "*":
+                    pos += 1
+                    yield "STAR", "*"
                 elif char == ".":
                     pos += 1
                     yield "DOT", "."
     def parse_line(self, s):
         next_token = self.tokenize(s).next
         args = []
+        defaults = {}
+        types = {}
         returns = None
         name = None
         token = next_token()
             token = next_token()
             if token[0] == "IDENT": 
                 # c-like declaration of type
+                types[token[1]] = args[-1]
                 args[-1] = token[1]
                 token = next_token()
             if token[0] == "EQUALS":
                 token = next_token()
+                assert token[0] in ("IDENT", "STRING", "NUMBER"), "default value is %s" % repr(token)
+                defaults[args[-1]] = token[1]
                 token = next_token()
 
             if token[0] == "COMMA":
                 token = next_token()
             elif token[0] == "COLON":
                 token = next_token()
+                assert token[0] == "IDENT"
+                types[args[-1]] = token[1]
                 token = next_token()
             else:
                 assert token[0] == "RPAREN", ") expected, %s found" % repr(token)
                     returns = token[1]
             except StopIteration:
                 pass
-        return name, args, returns
+        return name, args, returns, defaults, types