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 2727import keyword
2828import pydoc
2929import re
30- import sys
3130import types
32- from itertools import dropwhile
3331
3432from pygments .token import Token
3533
@@ -115,36 +113,31 @@ def __repr__(self):
115113
116114def parsekeywordpairs (signature ):
117115 tokens = PythonLexer ().get_tokens (signature )
116+ preamble = True
118117 stack = []
119118 substack = []
120119 parendepth = 0
121- begin = False
122120 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
126124 continue
127125
128126 if token is Token .Punctuation :
129- if value == u'(' :
127+ if value in [ u'(' , u'{' , u'[' ] :
130128 parendepth += 1
131- elif value == u')' :
129+ elif value in [ u')' , u'}' , u']' ] :
132130 parendepth -= 1
133131 elif value == ':' and parendepth == - 1 :
134132 # End of signature reached
135133 break
134+ if ((value == ',' and parendepth == 0 ) or
135+ (value == ')' and parendepth == - 1 )):
136+ stack .append (substack )
137+ substack = []
138+ continue
136139
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 ()):
148141 substack .append (value )
149142
150143 d = {}
Original file line number Diff line number Diff line change @@ -31,6 +31,7 @@ def spam():
3131 self .assertFalse (inspection .is_callable (None ))
3232
3333 def test_parsekeywordpairs (self ):
34+ # See issue #109
3435 def fails (spam = ['-a' , '-b' ]):
3536 pass
3637
You can’t perform that action at this time.
0 commit comments