python-minifier 2.11.2__py2-none-any.whl → 3.0.0__py2-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. python_minifier/__init__.py +14 -9
  2. python_minifier/__init__.pyi +8 -3
  3. python_minifier/__main__.py +77 -15
  4. python_minifier/ast_annotation/__init__.py +82 -0
  5. python_minifier/ast_compare.py +12 -14
  6. python_minifier/ast_compat.py +38 -0
  7. python_minifier/ast_printer.py +8 -5
  8. python_minifier/expression_printer.py +14 -13
  9. python_minifier/f_string.py +44 -45
  10. python_minifier/ministring.py +3 -3
  11. python_minifier/module_printer.py +19 -16
  12. python_minifier/rename/__init__.py +1 -1
  13. python_minifier/rename/bind_names.py +2 -1
  14. python_minifier/rename/binding.py +39 -40
  15. python_minifier/rename/mapper.py +66 -50
  16. python_minifier/rename/rename_literals.py +17 -15
  17. python_minifier/rename/renamer.py +26 -28
  18. python_minifier/rename/resolve_names.py +8 -7
  19. python_minifier/rename/util.py +7 -5
  20. python_minifier/token_printer.py +12 -1
  21. python_minifier/transforms/combine_imports.py +0 -1
  22. python_minifier/transforms/constant_folding.py +16 -10
  23. python_minifier/transforms/remove_annotations.py +18 -16
  24. python_minifier/transforms/remove_annotations_options.py +3 -1
  25. python_minifier/transforms/remove_annotations_options.pyi +8 -7
  26. python_minifier/transforms/remove_asserts.py +1 -2
  27. python_minifier/transforms/remove_debug.py +4 -3
  28. python_minifier/transforms/remove_exception_brackets.py +12 -7
  29. python_minifier/transforms/remove_explicit_return_none.py +5 -4
  30. python_minifier/transforms/remove_literal_statements.py +5 -6
  31. python_minifier/transforms/remove_object_base.py +2 -1
  32. python_minifier/transforms/remove_pass.py +1 -2
  33. python_minifier/transforms/remove_posargs.py +3 -4
  34. python_minifier/transforms/suite_transformer.py +6 -5
  35. python_minifier/util.py +12 -18
  36. {python_minifier-2.11.2.dist-info → python_minifier-3.0.0.dist-info}/METADATA +2 -2
  37. python_minifier-3.0.0.dist-info/RECORD +45 -0
  38. python_minifier-2.11.2.dist-info/RECORD +0 -44
  39. {python_minifier-2.11.2.dist-info → python_minifier-3.0.0.dist-info}/LICENSE +0 -0
  40. {python_minifier-2.11.2.dist-info → python_minifier-3.0.0.dist-info}/WHEEL +0 -0
  41. {python_minifier-2.11.2.dist-info → python_minifier-3.0.0.dist-info}/entry_points.txt +0 -0
  42. {python_minifier-2.11.2.dist-info → python_minifier-3.0.0.dist-info}/top_level.txt +0 -0
  43. {python_minifier-2.11.2.dist-info → python_minifier-3.0.0.dist-info}/zip-safe +0 -0
@@ -6,17 +6,17 @@ Mostly because FStrings feel like a hack.
6
6
 
7
7
  """
8
8
 
9
- import python_minifier.ast_compat as ast
10
9
  import copy
11
10
  import re
12
11
 
12
+ import python_minifier.ast_compat as ast
13
+
13
14
  from python_minifier import UnstableMinification
14
- from python_minifier.ast_compare import CompareError
15
- from python_minifier.ast_compare import compare_ast
15
+ from python_minifier.ast_compare import CompareError, compare_ast
16
16
  from python_minifier.expression_printer import ExpressionPrinter
17
17
  from python_minifier.ministring import MiniString
18
18
  from python_minifier.token_printer import TokenTypes
19
- from python_minifier.util import is_ast_node
19
+ from python_minifier.util import is_constant_node
20
20
 
21
21
 
22
22
  class FString(object):
@@ -36,7 +36,7 @@ class FString(object):
36
36
  c = ast.parse(code, 'FString candidate', mode='eval')
37
37
  compare_ast(self.node, c.body)
38
38
  return True
39
- except Exception as e:
39
+ except Exception:
40
40
  return False
41
41
 
42
42
  def complete_debug_specifier(self, partial_specifier_candidates, value_node):
@@ -70,7 +70,7 @@ class FString(object):
70
70
  nested_allowed.remove(quote)
71
71
 
72
72
  for v in self.node.values:
73
- if is_ast_node(v, ast.Str):
73
+ if is_constant_node(v, ast.Str):
74
74
 
75
75
  # Could this be used as a debug specifier?
76
76
  if len(candidates) < 10:
@@ -79,12 +79,12 @@ class FString(object):
79
79
  # Maybe!
80
80
  try:
81
81
  debug_specifier_candidates = [x + '{' + v.s for x in candidates]
82
- except Exception as e:
82
+ except Exception:
83
83
  continue
84
84
 
85
85
  try:
86
86
  candidates = [x + self.str_for(v.s, quote) for x in candidates]
87
- except Exception as e:
87
+ except Exception:
88
88
  continue
89
89
  elif isinstance(v, ast.FormattedValue):
90
90
  try:
@@ -93,15 +93,14 @@ class FString(object):
93
93
  x + y for x in candidates for y in FormattedValue(v, nested_allowed, self.pep701).get_candidates()
94
94
  ] + completed
95
95
  debug_specifier_candidates = []
96
- except Exception as e:
96
+ except Exception:
97
97
  continue
98
98
  else:
99
99
  raise RuntimeError('Unexpected JoinedStr value')
100
100
 
101
101
  actual_candidates += ['f' + quote + x + quote for x in candidates]
102
102
 
103
- actual_candidates = filter(self.is_correct_ast, actual_candidates)
104
- return actual_candidates
103
+ return filter(self.is_correct_ast, actual_candidates)
105
104
 
106
105
  def str_for(self, s, quote):
107
106
  return s.replace('{', '{{').replace('}', '}}')
@@ -270,34 +269,34 @@ class Str(object):
270
269
  elif c != quote:
271
270
  return quote
272
271
 
273
- raise ValueError('Couldn\'t find a quote')
272
+ raise ValueError("Couldn't find a quote")
274
273
 
275
274
  def _literals(self):
276
- l = ''
275
+ literal = ''
277
276
  for c in self._s:
278
277
  if not self._can_quote(c):
279
- if l:
280
- l += self.current_quote
281
- yield l
282
- l = ''
278
+ if literal:
279
+ literal += self.current_quote
280
+ yield literal
281
+ literal = ''
283
282
 
284
283
  self.current_quote = self._get_quote(c)
285
284
 
286
- if l == '':
287
- l += self.current_quote
285
+ if literal == '':
286
+ literal += self.current_quote
288
287
 
289
288
  if c == '\n':
290
- l += '\\n'
289
+ literal += '\\n'
291
290
  elif c == '\r':
292
- l += '\\r'
291
+ literal += '\\r'
293
292
  elif c == '\\':
294
- l += '\\\\'
293
+ literal += '\\\\'
295
294
  else:
296
- l += c
295
+ literal += c
297
296
 
298
- if l:
299
- l += self.current_quote
300
- yield l
297
+ if literal:
298
+ literal += self.current_quote
299
+ yield literal
301
300
 
302
301
  def __str__(self):
303
302
  if self._s == '':
@@ -316,10 +315,10 @@ class Str(object):
316
315
  for start_quote in self.allowed_quotes:
317
316
  self.current_quote = start_quote
318
317
  s = ''
319
- for l in self._literals():
320
- if s and s[-1] == l[0]:
318
+ for literal in self._literals():
319
+ if s and s[-1] == literal[0]:
321
320
  s += ' '
322
- s += l
321
+ s += literal
323
322
 
324
323
  if eval(s) == self._s:
325
324
  candidates.append(s)
@@ -349,7 +348,7 @@ class FormatSpec(object):
349
348
 
350
349
  candidates = ['']
351
350
  for v in self.node.values:
352
- if is_ast_node(v, ast.Str):
351
+ if is_constant_node(v, ast.Str):
353
352
  candidates = [x + self.str_for(v.s) for x in candidates]
354
353
  elif isinstance(v, ast.FormattedValue):
355
354
  candidates = [
@@ -397,26 +396,26 @@ class Bytes(object):
397
396
  elif chr(c) != quote:
398
397
  return quote
399
398
 
400
- raise ValueError('Couldn\'t find a quote')
399
+ raise ValueError("Couldn't find a quote")
401
400
 
402
401
  def _literals(self):
403
- l = ''
402
+ literal = ''
404
403
  for b in self._b:
405
404
  if not self._can_quote(b):
406
- if l:
407
- l += self.current_quote
408
- yield l
409
- l = ''
405
+ if literal:
406
+ literal += self.current_quote
407
+ yield literal
408
+ literal = ''
410
409
 
411
410
  self.current_quote = self._get_quote(b)
412
411
 
413
- if l == '':
414
- l = 'b' + self.current_quote
415
- l += chr(b)
412
+ if literal == '':
413
+ literal = 'b' + self.current_quote
414
+ literal += chr(b)
416
415
 
417
- if l:
418
- l += self.current_quote
419
- yield l
416
+ if literal:
417
+ literal += self.current_quote
418
+ yield literal
420
419
 
421
420
  def __str__(self):
422
421
  if self._b == b'':
@@ -435,10 +434,10 @@ class Bytes(object):
435
434
  for start_quote in self.allowed_quotes:
436
435
  self.current_quote = start_quote
437
436
  s = ''
438
- for l in self._literals():
439
- if s and s[-1] == l[0]:
437
+ for literal in self._literals():
438
+ if s and s[-1] == literal[0]:
440
439
  s += ' '
441
- s += l
440
+ s += literal
442
441
 
443
442
  assert eval(s) == self._b
444
443
  candidates.append(s)
@@ -32,7 +32,7 @@ class MiniString(object):
32
32
 
33
33
  try:
34
34
  eval(self.quote + s + self.quote)
35
- except (UnicodeDecodeError, UnicodeEncodeError) as e:
35
+ except (UnicodeDecodeError, UnicodeEncodeError):
36
36
  if self.safe_mode:
37
37
  raise
38
38
 
@@ -63,7 +63,7 @@ class MiniString(object):
63
63
  }
64
64
 
65
65
  for c in self._s:
66
- if c in escaped.keys():
66
+ if c in escaped:
67
67
  s += escaped[c]
68
68
  else:
69
69
  if self.safe_mode:
@@ -95,7 +95,7 @@ class MiniString(object):
95
95
  }
96
96
 
97
97
  for c in self._s:
98
- if c in escaped.keys():
98
+ if c in escaped:
99
99
  s += escaped[c]
100
100
  else:
101
101
  if self.safe_mode:
@@ -1,9 +1,9 @@
1
- import python_minifier.ast_compat as ast
2
1
  import sys
3
2
 
3
+ import python_minifier.ast_compat as ast
4
+
4
5
  from .expression_printer import ExpressionPrinter
5
6
  from .token_printer import Delimiter
6
- from .util import is_ast_node
7
7
 
8
8
 
9
9
  class ModulePrinter(ExpressionPrinter):
@@ -28,11 +28,15 @@ class ModulePrinter(ExpressionPrinter):
28
28
  assert isinstance(module, ast.Module)
29
29
 
30
30
  self.visit_Module(module)
31
- return str(self.printer).rstrip('\n' + self.indent_char + ';')
31
+ # On Python 2.7, preserve unicode strings to avoid encoding issues
32
+ code = unicode(self.printer) if sys.version_info[0] < 3 else str(self.printer)
33
+ return code.rstrip('\n' + self.indent_char + ';')
32
34
 
33
35
  @property
34
36
  def code(self):
35
- return str(self.printer).rstrip('\n' + self.indent_char + ';')
37
+ # On Python 2.7, preserve unicode strings to avoid encoding issues
38
+ code = unicode(self.printer) if sys.version_info[0] < 3 else str(self.printer)
39
+ return code.rstrip('\n' + self.indent_char + ';')
36
40
 
37
41
  # region Simple Statements
38
42
 
@@ -55,7 +59,7 @@ class ModulePrinter(ExpressionPrinter):
55
59
  def visit_Expr(self, node):
56
60
  assert isinstance(node, ast.Expr)
57
61
 
58
- if is_ast_node(node.value, (ast.Yield, 'YieldFrom')):
62
+ if isinstance(node.value, (ast.Yield, ast.YieldFrom)):
59
63
  self._yield_expr(node.value)
60
64
  else:
61
65
  self._testlist(node.value)
@@ -82,7 +86,7 @@ class ModulePrinter(ExpressionPrinter):
82
86
  self.printer.delimiter('=')
83
87
 
84
88
  # Yield nodes that are the sole node on the right hand side of an assignment do not need parens
85
- if is_ast_node(node.value, (ast.Yield, 'YieldFrom')):
89
+ if isinstance(node.value, (ast.Yield, ast.YieldFrom)):
86
90
  self._yield_expr(node.value)
87
91
  else:
88
92
  self._testlist(node.value)
@@ -97,7 +101,7 @@ class ModulePrinter(ExpressionPrinter):
97
101
  self.printer.delimiter('=')
98
102
 
99
103
  # Yield nodes that are the sole node on the right hand side of an assignment do not need parens
100
- if is_ast_node(node.value, (ast.Yield, 'YieldFrom')):
104
+ if isinstance(node.value, (ast.Yield, ast.YieldFrom)):
101
105
  self._yield_expr(node.value)
102
106
  else:
103
107
  self._testlist(node.value)
@@ -143,7 +147,7 @@ class ModulePrinter(ExpressionPrinter):
143
147
 
144
148
  self.printer.keyword('return')
145
149
  if isinstance(node.value, ast.Tuple):
146
- if sys.version_info < (3, 8) and [n for n in node.value.elts if is_ast_node(n, 'Starred')]:
150
+ if sys.version_info < (3, 8) and [n for n in node.value.elts if isinstance(n, ast.Starred)]:
147
151
  self.printer.delimiter('(')
148
152
  self._testlist(node.value)
149
153
  self.printer.delimiter(')')
@@ -243,7 +247,7 @@ class ModulePrinter(ExpressionPrinter):
243
247
  assert isinstance(node, ast.ImportFrom)
244
248
 
245
249
  self.printer.keyword('from')
246
- for i in range(node.level):
250
+ for _i in range(node.level):
247
251
  self.printer.delimiter('.')
248
252
  if node.module is not None:
249
253
  self.printer.identifier(node.module)
@@ -326,7 +330,7 @@ class ModulePrinter(ExpressionPrinter):
326
330
  self._suite(node.orelse)
327
331
 
328
332
  def visit_For(self, node, is_async=False):
329
- assert isinstance(node, ast.For) or (hasattr(ast, 'AsyncFor') and isinstance(node, ast.AsyncFor))
333
+ assert isinstance(node, (ast.For, ast.AsyncFor))
330
334
 
331
335
  self.printer.newline()
332
336
 
@@ -362,7 +366,7 @@ class ModulePrinter(ExpressionPrinter):
362
366
  self._suite(node.orelse)
363
367
 
364
368
  def visit_Try(self, node, star=False):
365
- assert is_ast_node(node, (ast.Try, 'TryStar'))
369
+ assert isinstance(node, (ast.Try, ast.TryStar))
366
370
 
367
371
  self.printer.newline()
368
372
  self.printer.keyword('try')
@@ -440,7 +444,7 @@ class ModulePrinter(ExpressionPrinter):
440
444
  self._suite(node.body)
441
445
 
442
446
  def visit_With(self, node, is_async=False):
443
- assert is_ast_node(node, (ast.With, 'AsyncWith'))
447
+ assert isinstance(node, (ast.With, ast.AsyncWith))
444
448
 
445
449
  self.printer.newline()
446
450
 
@@ -469,7 +473,7 @@ class ModulePrinter(ExpressionPrinter):
469
473
  self._suite(node.body)
470
474
 
471
475
  def visit_withitem(self, node):
472
- assert is_ast_node(node, ('withitem', ast.With))
476
+ assert isinstance(node, (ast.withitem, ast.With))
473
477
 
474
478
  self._expression(node.context_expr)
475
479
 
@@ -478,7 +482,7 @@ class ModulePrinter(ExpressionPrinter):
478
482
  self._expression(node.optional_vars)
479
483
 
480
484
  def visit_FunctionDef(self, node, is_async=False):
481
- assert is_ast_node(node, (ast.FunctionDef, 'AsyncFunctionDef'))
485
+ assert isinstance(node, (ast.FunctionDef, ast.AsyncFunctionDef))
482
486
 
483
487
  self.printer.newline()
484
488
 
@@ -670,7 +674,7 @@ class ModulePrinter(ExpressionPrinter):
670
674
  for kwd, pattern in zip(node.kwd_attrs, node.kwd_patterns):
671
675
  delimiter.new_item()
672
676
 
673
- self.printer.identifier(kwd)
677
+ self.printer.identifier(kwd)
674
678
  self.printer.delimiter('=')
675
679
 
676
680
  self.pattern(pattern)
@@ -859,4 +863,3 @@ class ModulePrinter(ExpressionPrinter):
859
863
 
860
864
  for node in node_list:
861
865
  statements[node.__class__.__name__](node)
862
-
@@ -3,4 +3,4 @@ from python_minifier.rename.mapper import add_namespace
3
3
  from python_minifier.rename.rename_literals import rename_literals
4
4
  from python_minifier.rename.renamer import rename
5
5
  from python_minifier.rename.resolve_names import resolve_names
6
- from python_minifier.rename.util import allow_rename_locals, allow_rename_globals
6
+ from python_minifier.rename.util import allow_rename_globals, allow_rename_locals
@@ -1,7 +1,7 @@
1
1
  import python_minifier.ast_compat as ast
2
2
 
3
3
  from python_minifier.rename.binding import NameBinding
4
- from python_minifier.rename.util import arg_rename_in_place, get_global_namespace, get_nonlocal_namespace, builtins
4
+ from python_minifier.rename.util import arg_rename_in_place, builtins, get_global_namespace
5
5
  from python_minifier.transforms.suite_transformer import NodeVisitor
6
6
 
7
7
 
@@ -180,6 +180,7 @@ class NameBinder(NodeVisitor):
180
180
 
181
181
  get_global_namespace(node.namespace).preserved.add(node.name)
182
182
 
183
+
183
184
  def bind_names(module):
184
185
  """
185
186
  Bind names to their local namespace
@@ -1,7 +1,6 @@
1
1
  import python_minifier.ast_compat as ast
2
2
 
3
3
  from python_minifier.rename.util import arg_rename_in_place, insert
4
- from python_minifier.util import is_ast_node
5
4
 
6
5
 
7
6
  class Binding(object):
@@ -105,11 +104,11 @@ class Binding(object):
105
104
  # Python 2 Param context
106
105
  if not arg_rename_in_place(node):
107
106
  arg_rename = True
108
- elif is_ast_node(node, (ast.ClassDef, ast.FunctionDef, 'AsyncFunctionDef')):
107
+ elif isinstance(node, (ast.ClassDef, ast.FunctionDef, ast.AsyncFunctionDef)):
109
108
  pass
110
109
  elif isinstance(node, ast.ExceptHandler):
111
110
  pass
112
- elif is_ast_node(node, (ast.Global, 'Nonlocal')):
111
+ elif isinstance(node, (ast.Global, ast.Nonlocal)):
113
112
  pass
114
113
  elif isinstance(node, ast.alias):
115
114
  if node.asname is None:
@@ -119,22 +118,22 @@ class Binding(object):
119
118
  pass
120
119
  if node.kwarg == self._name:
121
120
  pass
122
- elif is_ast_node(node, 'arg'):
121
+ elif isinstance(node, ast.arg):
123
122
  if not arg_rename_in_place(node):
124
123
  arg_rename = True
125
124
 
126
- elif is_ast_node(node, 'MatchAs'):
125
+ elif isinstance(node, ast.MatchAs):
127
126
  if node.name is None:
128
127
  additional_bytes += 4 # ' as '
129
- elif is_ast_node(node, 'MatchStar'):
128
+ elif isinstance(node, ast.MatchStar):
130
129
  pass
131
- elif is_ast_node(node, 'MatchMapping'):
130
+ elif isinstance(node, ast.MatchMapping):
132
131
  pass
133
- elif is_ast_node(node, 'TypeVar'):
132
+ elif isinstance(node, ast.TypeVar):
134
133
  pass
135
- elif is_ast_node(node, 'TypeVarTuple'):
134
+ elif isinstance(node, ast.TypeVarTuple):
136
135
  pass
137
- elif is_ast_node(node, 'ParamSpec'):
136
+ elif isinstance(node, ast.ParamSpec):
138
137
  pass
139
138
 
140
139
  else:
@@ -160,11 +159,11 @@ class Binding(object):
160
159
  mentions += 1
161
160
  arg_rename = True
162
161
 
163
- elif is_ast_node(node, (ast.ClassDef, ast.FunctionDef, 'AsyncFunctionDef')):
162
+ elif isinstance(node, (ast.ClassDef, ast.FunctionDef, ast.AsyncFunctionDef)):
164
163
  pass
165
164
  elif isinstance(node, ast.ExceptHandler):
166
165
  pass
167
- elif is_ast_node(node, (ast.Global, 'Nonlocal')):
166
+ elif isinstance(node, (ast.Global, ast.Nonlocal)):
168
167
  pass
169
168
  elif isinstance(node, ast.alias):
170
169
  if node.asname is None:
@@ -172,22 +171,22 @@ class Binding(object):
172
171
  mentions += 1
173
172
  elif isinstance(node, ast.arguments):
174
173
  pass
175
- elif is_ast_node(node, 'arg'):
174
+ elif isinstance(node, ast.arg):
176
175
  if not arg_rename_in_place(node):
177
176
  mentions += 1
178
177
  arg_rename = True
179
178
 
180
- elif is_ast_node(node, 'MatchAs'):
179
+ elif isinstance(node, ast.MatchAs):
181
180
  pass
182
- elif is_ast_node(node, 'MatchStar'):
181
+ elif isinstance(node, ast.MatchStar):
183
182
  pass
184
- elif is_ast_node(node, 'MatchMapping'):
183
+ elif isinstance(node, ast.MatchMapping):
185
184
  pass
186
- elif is_ast_node(node, 'TypeVar'):
185
+ elif isinstance(node, ast.TypeVar):
187
186
  pass
188
- elif is_ast_node(node, 'TypeVarTuple'):
187
+ elif isinstance(node, ast.TypeVarTuple):
189
188
  pass
190
- elif is_ast_node(node, 'ParamSpec'):
189
+ elif isinstance(node, ast.ParamSpec):
191
190
  pass
192
191
 
193
192
  else:
@@ -210,11 +209,11 @@ class Binding(object):
210
209
  else:
211
210
  # Python 2 Param context
212
211
  arg_rename = True
213
- elif is_ast_node(node, (ast.ClassDef, ast.FunctionDef, 'AsyncFunctionDef')):
212
+ elif isinstance(node, (ast.ClassDef, ast.FunctionDef, ast.AsyncFunctionDef)):
214
213
  mentions += 1
215
214
  elif isinstance(node, ast.ExceptHandler):
216
215
  mentions += 1
217
- elif is_ast_node(node, (ast.Global, 'Nonlocal')):
216
+ elif isinstance(node, (ast.Global, ast.Nonlocal)):
218
217
  mentions += len([n for n in node.names if n == self._name])
219
218
  elif isinstance(node, ast.alias):
220
219
  mentions += 1
@@ -223,20 +222,20 @@ class Binding(object):
223
222
  mentions += 1
224
223
  if node.kwarg == self._name:
225
224
  mentions += 1
226
- elif is_ast_node(node, 'arg'):
225
+ elif isinstance(node, ast.arg):
227
226
  arg_rename = True
228
227
 
229
- elif is_ast_node(node, 'MatchAs'):
228
+ elif isinstance(node, ast.MatchAs):
230
229
  mentions += 1
231
- elif is_ast_node(node, 'MatchStar'):
230
+ elif isinstance(node, ast.MatchStar):
232
231
  mentions += 1
233
- elif is_ast_node(node, 'MatchMapping'):
232
+ elif isinstance(node, ast.MatchMapping):
234
233
  mentions += 1
235
- elif is_ast_node(node, 'TypeVar'):
234
+ elif isinstance(node, ast.TypeVar):
236
235
  mentions += 1
237
- elif is_ast_node(node, 'TypeVarTuple'):
236
+ elif isinstance(node, ast.TypeVarTuple):
238
237
  mentions += 1
239
- elif is_ast_node(node, 'ParamSpec'):
238
+ elif isinstance(node, ast.ParamSpec):
240
239
  mentions += 1
241
240
 
242
241
  else:
@@ -273,7 +272,7 @@ class Binding(object):
273
272
 
274
273
  """
275
274
 
276
- raise NotImplementedError()
275
+ raise NotImplementedError
277
276
 
278
277
  def rename(self, new_name):
279
278
  """
@@ -283,7 +282,7 @@ class Binding(object):
283
282
 
284
283
  """
285
284
 
286
- raise NotImplementedError()
285
+ raise NotImplementedError
287
286
 
288
287
 
289
288
  class NameBinding(Binding):
@@ -362,7 +361,7 @@ class NameBinding(Binding):
362
361
  else:
363
362
  assert func_namespace_binding is node.namespace
364
363
 
365
- elif is_ast_node(node, (ast.FunctionDef, 'AsyncFunctionDef')):
364
+ elif isinstance(node, (ast.FunctionDef, ast.AsyncFunctionDef)):
366
365
  node.name = new_name
367
366
  elif isinstance(node, ast.ClassDef):
368
367
  node.name = new_name
@@ -371,7 +370,7 @@ class NameBinding(Binding):
371
370
  node.asname = None
372
371
  else:
373
372
  node.asname = new_name
374
- elif is_ast_node(node, 'arg'):
373
+ elif isinstance(node, ast.arg):
375
374
 
376
375
  if arg_rename_in_place(node):
377
376
  node.arg = new_name
@@ -384,7 +383,7 @@ class NameBinding(Binding):
384
383
 
385
384
  elif isinstance(node, ast.ExceptHandler):
386
385
  node.name = new_name
387
- elif is_ast_node(node, (ast.Global, 'Nonlocal')):
386
+ elif isinstance(node, (ast.Global, ast.Nonlocal)):
388
387
  node.names = [new_name if n == self._name else n for n in node.names]
389
388
  elif isinstance(node, ast.arguments):
390
389
 
@@ -398,17 +397,17 @@ class NameBinding(Binding):
398
397
  node.kwarg = new_name
399
398
  node.kwarg_renamed = True
400
399
 
401
- elif is_ast_node(node, 'MatchAs'):
400
+ elif isinstance(node, ast.MatchAs):
402
401
  node.name = new_name
403
- elif is_ast_node(node, 'MatchStar'):
402
+ elif isinstance(node, ast.MatchStar):
404
403
  node.name = new_name
405
- elif is_ast_node(node, 'MatchMapping'):
404
+ elif isinstance(node, ast.MatchMapping):
406
405
  node.rest = new_name
407
- elif is_ast_node(node, 'TypeVar'):
406
+ elif isinstance(node, ast.TypeVar):
408
407
  node.name = new_name
409
- elif is_ast_node(node, 'TypeVarTuple'):
408
+ elif isinstance(node, ast.TypeVarTuple):
410
409
  node.name = new_name
411
- elif is_ast_node(node, 'ParamSpec'):
410
+ elif isinstance(node, ast.ParamSpec):
412
411
  node.name = new_name
413
412
 
414
413
  if func_namespace_binding is not None:
@@ -492,4 +491,4 @@ class BuiltinBinding(NameBinding):
492
491
  if not isinstance(node.ctx, ast.Load):
493
492
  return True
494
493
 
495
- return False
494
+ return False