File tree Expand file tree Collapse file tree 2 files changed +13
-19
lines changed Expand file tree Collapse file tree 2 files changed +13
-19
lines changed Original file line number Diff line number Diff line change 27
27
import keyword
28
28
import pydoc
29
29
import re
30
- import sys
31
30
import types
32
- from itertools import dropwhile
33
31
34
32
from pygments .token import Token
35
33
@@ -115,36 +113,31 @@ def __repr__(self):
115
113
116
114
def parsekeywordpairs (signature ):
117
115
tokens = PythonLexer ().get_tokens (signature )
116
+ preamble = True
118
117
stack = []
119
118
substack = []
120
119
parendepth = 0
121
- begin = False
122
120
for token , value in tokens :
123
- if not begin :
124
- if token is Token .Punctuation and value == u'(' :
125
- begin = True
121
+ if preamble :
122
+ if token is Token .Punctuation and value == u"(" :
123
+ preamble = False
126
124
continue
127
125
128
126
if token is Token .Punctuation :
129
- if value == u'(' :
127
+ if value in [ u'(' , u'{' , u'[' ] :
130
128
parendepth += 1
131
- elif value == u')' :
129
+ elif value in [ u')' , u'}' , u']' ] :
132
130
parendepth -= 1
133
131
elif value == ':' and parendepth == - 1 :
134
132
# End of signature reached
135
133
break
134
+ if ((value == ',' and parendepth == 0 ) or
135
+ (value == ')' and parendepth == - 1 )):
136
+ stack .append (substack )
137
+ substack = []
138
+ continue
136
139
137
- if parendepth > 0 :
138
- substack .append (value )
139
- continue
140
-
141
- if (token is Token .Punctuation and
142
- (value == ',' or (value == ')' and parendepth == - 1 ))):
143
- stack .append (substack [:])
144
- del substack [:]
145
- continue
146
-
147
- if value and value .strip ():
140
+ if value and (parendepth > 0 or value .strip ()):
148
141
substack .append (value )
149
142
150
143
d = {}
Original file line number Diff line number Diff line change @@ -31,6 +31,7 @@ def spam():
31
31
self .assertFalse (inspection .is_callable (None ))
32
32
33
33
def test_parsekeywordpairs (self ):
34
+ # See issue #109
34
35
def fails (spam = ['-a' , '-b' ]):
35
36
pass
36
37
You can’t perform that action at this time.
0 commit comments