from blib2to3.pgen2 import driver, token
from blib2to3.pgen2.parse import ParseError
-__version__ = "18.3a2"
+__version__ = "18.3a3"
DEFAULT_LINE_LENGTH = 88
# types
syms = pygram.python_symbols
token.AMPER,
token.PERCENT,
token.CIRCUMFLEX,
+ token.TILDE,
token.LEFTSHIFT,
token.RIGHTSHIFT,
token.DOUBLESTAR,
):
return False
- if closing.type == token.RSQB or closing.type == token.RBRACE:
+ if closing.type == token.RBRACE:
self.leaves.pop()
return True
+ if closing.type == token.RSQB:
+ comma = self.leaves[-1]
+ if comma.parent and comma.parent.type == syms.listmaker:
+ self.leaves.pop()
+ return True
+
# For parens let's check if it's safe to remove the comma. If the
# trailing one is the only one, we might mistakenly change a tuple
# into a different type by removing the comma.
if prevp.type == token.EQUAL:
if prevp.parent and prevp.parent.type in {
- syms.typedargslist,
- syms.varargslist,
- syms.parameters,
syms.arglist,
syms.argument,
+ syms.parameters,
+ syms.typedargslist,
+ syms.varargslist,
}:
return NO
elif prevp.type == token.DOUBLESTAR:
if prevp.parent and prevp.parent.type in {
- syms.typedargslist,
- syms.varargslist,
- syms.parameters,
syms.arglist,
+ syms.argument,
syms.dictsetmaker,
+ syms.parameters,
+ syms.typedargslist,
+ syms.varargslist,
}:
return NO
if prevp.parent and prevp.parent.type in {syms.subscript, syms.sliceop}:
return NO
- elif prevp.parent and prevp.parent.type in {syms.factor, syms.star_expr}:
+ elif (
+ prevp.parent
+ and prevp.parent.type in {syms.factor, syms.star_expr}
+ and prevp.type in MATH_OPERATORS
+ ):
return NO
elif prev.type in OPENING_BRACKETS: