libv8 6.3.292.48.1 → 6.7.288.46.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (195) hide show
  1. checksums.yaml +5 -5
  2. data/.travis.yml +10 -34
  3. data/CHANGELOG.md +16 -0
  4. data/README.md +9 -63
  5. data/Rakefile +2 -2
  6. data/ext/libv8/builder.rb +22 -87
  7. data/ext/libv8/extconf.rb +1 -1
  8. data/ext/libv8/paths.rb +5 -18
  9. data/lib/libv8/version.rb +1 -1
  10. data/spec/location_spec.rb +1 -2
  11. data/spec/spec_helper.rb +0 -1
  12. data/vendor/depot_tools/.gitattributes +1 -2
  13. data/vendor/depot_tools/OWNERS +0 -1
  14. data/vendor/depot_tools/PRESUBMIT.py +11 -6
  15. data/vendor/depot_tools/README.md +0 -1
  16. data/vendor/depot_tools/WATCHLISTS +0 -6
  17. data/vendor/depot_tools/auth.py +129 -87
  18. data/vendor/depot_tools/autoninja +11 -1
  19. data/vendor/depot_tools/autoninja.bat +7 -1
  20. data/vendor/depot_tools/autoninja.py +14 -6
  21. data/vendor/depot_tools/bootstrap/win/manifest.txt +1 -1
  22. data/vendor/depot_tools/bootstrap/win/manifest_bleeding_edge.txt +1 -1
  23. data/vendor/depot_tools/cipd +23 -2
  24. data/vendor/depot_tools/cipd.bat +2 -2
  25. data/vendor/depot_tools/cipd_client_version +1 -1
  26. data/vendor/depot_tools/cipd_manifest.txt +17 -7
  27. data/vendor/depot_tools/cit.py +7 -6
  28. data/vendor/depot_tools/cpplint.py +195 -35
  29. data/vendor/depot_tools/detect_host_arch.py +51 -0
  30. data/vendor/depot_tools/download_from_google_storage.py +85 -26
  31. data/vendor/depot_tools/fetch.py +11 -6
  32. data/vendor/depot_tools/fetch_configs/chromium.py +0 -1
  33. data/vendor/depot_tools/fetch_configs/goma_client.py +41 -0
  34. data/vendor/depot_tools/fetch_configs/infra.py +0 -1
  35. data/vendor/depot_tools/fetch_configs/infra_internal.py +0 -1
  36. data/vendor/depot_tools/gclient-new-workdir.py +4 -0
  37. data/vendor/depot_tools/gclient.py +732 -476
  38. data/vendor/depot_tools/gclient_eval.py +569 -58
  39. data/vendor/depot_tools/gclient_scm.py +258 -46
  40. data/vendor/depot_tools/gclient_utils.py +17 -1
  41. data/vendor/depot_tools/gerrit_util.py +46 -13
  42. data/vendor/depot_tools/git_cache.py +0 -2
  43. data/vendor/depot_tools/git_cl.py +176 -335
  44. data/vendor/depot_tools/git_common.py +19 -16
  45. data/vendor/depot_tools/git_footers.py +19 -5
  46. data/vendor/depot_tools/git_hyper_blame.py +9 -3
  47. data/vendor/depot_tools/git_new_branch.py +15 -3
  48. data/vendor/depot_tools/git_upstream_diff.py +7 -2
  49. data/vendor/depot_tools/gsutil.py +1 -1
  50. data/vendor/depot_tools/infra/config/cq.cfg +1 -2
  51. data/vendor/depot_tools/infra/config/recipes.cfg +1 -1
  52. data/vendor/depot_tools/luci-auth +13 -0
  53. data/vendor/depot_tools/luci-auth.bat +8 -0
  54. data/vendor/depot_tools/man/html/depot_tools.html +0 -8
  55. data/vendor/depot_tools/man/html/git-upstream-diff.html +20 -3
  56. data/vendor/depot_tools/man/man1/git-upstream-diff.1 +27 -6
  57. data/vendor/depot_tools/man/man7/depot_tools.7 +0 -5
  58. data/vendor/depot_tools/man/man7/depot_tools_tutorial.7 +2 -2
  59. data/vendor/depot_tools/man/src/git-upstream-diff.txt +21 -3
  60. data/vendor/depot_tools/man/src/make_docs.sh +6 -0
  61. data/vendor/depot_tools/my_activity.py +283 -93
  62. data/vendor/depot_tools/owners.py +9 -4
  63. data/vendor/depot_tools/owners_finder.py +7 -3
  64. data/vendor/depot_tools/post_build_ninja_summary.py +322 -0
  65. data/vendor/depot_tools/presubmit_canned_checks.py +91 -106
  66. data/vendor/depot_tools/presubmit_support.py +219 -157
  67. data/vendor/depot_tools/prpc +13 -0
  68. data/vendor/depot_tools/prpc.bat +8 -0
  69. data/vendor/depot_tools/recipes/OWNERS +3 -1
  70. data/vendor/depot_tools/recipes/README.recipes.md +70 -111
  71. data/vendor/depot_tools/recipes/recipe_modules/bot_update/__init__.py +12 -5
  72. data/vendor/depot_tools/recipes/recipe_modules/bot_update/api.py +36 -68
  73. data/vendor/depot_tools/recipes/recipe_modules/bot_update/examples/full.expected/deprecated_got_revision_mapping.json +0 -8
  74. data/vendor/depot_tools/recipes/recipe_modules/bot_update/examples/full.expected/{trychange_oauth2_json.json → no_apply_patch_on_gclient.json} +64 -10
  75. data/vendor/depot_tools/recipes/recipe_modules/bot_update/examples/full.expected/{no_shallow.json → shallow.json} +1 -1
  76. data/vendor/depot_tools/recipes/recipe_modules/bot_update/examples/full.expected/tryjob.json +0 -8
  77. data/vendor/depot_tools/recipes/recipe_modules/bot_update/examples/full.expected/tryjob_empty_revision.json +0 -8
  78. data/vendor/depot_tools/recipes/recipe_modules/bot_update/examples/full.expected/tryjob_fail.json +0 -6
  79. data/vendor/depot_tools/recipes/recipe_modules/bot_update/examples/full.expected/tryjob_fail_patch.json +0 -7
  80. data/vendor/depot_tools/recipes/recipe_modules/bot_update/examples/full.expected/tryjob_fail_patch_download.json +0 -6
  81. data/vendor/depot_tools/recipes/recipe_modules/bot_update/examples/full.expected/tryjob_gerrit_angle_deprecated.json +44 -0
  82. data/vendor/depot_tools/recipes/recipe_modules/bot_update/examples/full.expected/{trychange_oauth2_buildbot.json → tryjob_gerrit_branch_heads.json} +51 -5
  83. data/vendor/depot_tools/recipes/recipe_modules/bot_update/examples/full.expected/tryjob_v8.json +0 -8
  84. data/vendor/depot_tools/recipes/recipe_modules/bot_update/examples/full.expected/tryjob_v8_head_by_default.json +48 -8
  85. data/vendor/depot_tools/recipes/recipe_modules/bot_update/examples/full.py +19 -26
  86. data/vendor/depot_tools/recipes/recipe_modules/bot_update/resources/bot_update.py +193 -155
  87. data/vendor/depot_tools/recipes/recipe_modules/bot_update/test_api.py +9 -0
  88. data/vendor/depot_tools/recipes/recipe_modules/gclient/api.py +2 -7
  89. data/vendor/depot_tools/recipes/recipe_modules/gclient/config.py +31 -5
  90. data/vendor/depot_tools/recipes/recipe_modules/gclient/examples/full.expected/basic.json +37 -19
  91. data/vendor/depot_tools/recipes/recipe_modules/gclient/examples/full.expected/buildbot.json +37 -19
  92. data/vendor/depot_tools/recipes/recipe_modules/gclient/examples/full.expected/revision.json +37 -19
  93. data/vendor/depot_tools/recipes/recipe_modules/gclient/examples/full.expected/tryserver.json +37 -23
  94. data/vendor/depot_tools/recipes/recipe_modules/gclient/examples/full.py +4 -0
  95. data/vendor/depot_tools/recipes/recipe_modules/gerrit/api.py +40 -8
  96. data/vendor/depot_tools/recipes/recipe_modules/gerrit/examples/full.expected/basic.json +3 -3
  97. data/vendor/depot_tools/recipes/recipe_modules/gerrit/examples/full.py +6 -3
  98. data/vendor/depot_tools/recipes/recipe_modules/gitiles/OWNERS +0 -1
  99. data/vendor/depot_tools/recipes/recipe_modules/tryserver/__init__.py +0 -1
  100. data/vendor/depot_tools/recipes/recipe_modules/tryserver/api.py +7 -56
  101. data/vendor/depot_tools/recipes/recipe_modules/tryserver/examples/full.expected/with_wrong_patch.json +0 -1
  102. data/vendor/depot_tools/recipes/recipe_modules/tryserver/examples/full.py +15 -16
  103. data/vendor/depot_tools/recipes/recipes.py +4 -2
  104. data/vendor/depot_tools/recipes/trigger_recipe_roller.txt +12 -0
  105. data/vendor/depot_tools/roll_dep.py +35 -37
  106. data/vendor/depot_tools/support/chromite_wrapper +1 -1
  107. data/vendor/depot_tools/third_party/logilab/astroid/README.chromium +3 -3
  108. data/vendor/depot_tools/third_party/logilab/astroid/__pkginfo__.py +2 -2
  109. data/vendor/depot_tools/third_party/logilab/astroid/astpeephole.py +86 -0
  110. data/vendor/depot_tools/third_party/logilab/astroid/bases.py +53 -66
  111. data/vendor/depot_tools/third_party/logilab/astroid/brain/py2pytest.py +31 -31
  112. data/vendor/depot_tools/third_party/logilab/astroid/brain/pynose.py +39 -16
  113. data/vendor/depot_tools/third_party/logilab/astroid/brain/pysix_moves.py +225 -189
  114. data/vendor/depot_tools/third_party/logilab/astroid/inference.py +45 -41
  115. data/vendor/depot_tools/third_party/logilab/astroid/manager.py +1 -0
  116. data/vendor/depot_tools/third_party/logilab/astroid/modutils.py +2 -2
  117. data/vendor/depot_tools/third_party/logilab/astroid/node_classes.py +3 -2
  118. data/vendor/depot_tools/third_party/logilab/astroid/nodes.py +1 -0
  119. data/vendor/depot_tools/third_party/logilab/astroid/protocols.py +57 -3
  120. data/vendor/depot_tools/third_party/logilab/astroid/raw_building.py +1 -1
  121. data/vendor/depot_tools/third_party/logilab/astroid/rebuilder.py +21 -1
  122. data/vendor/depot_tools/third_party/logilab/astroid/scoped_nodes.py +58 -33
  123. data/vendor/depot_tools/third_party/pylint/README.chromium +2 -2
  124. data/vendor/depot_tools/third_party/pylint/__pkginfo__.py +3 -3
  125. data/vendor/depot_tools/third_party/pylint/checkers/base.py +6 -18
  126. data/vendor/depot_tools/third_party/pylint/checkers/classes.py +64 -63
  127. data/vendor/depot_tools/third_party/pylint/checkers/design_analysis.py +25 -57
  128. data/vendor/depot_tools/third_party/pylint/checkers/format.py +14 -10
  129. data/vendor/depot_tools/third_party/pylint/checkers/python3.py +142 -37
  130. data/vendor/depot_tools/third_party/pylint/checkers/spelling.py +10 -1
  131. data/vendor/depot_tools/third_party/pylint/checkers/stdlib.py +50 -7
  132. data/vendor/depot_tools/third_party/pylint/checkers/strings.py +1 -1
  133. data/vendor/depot_tools/third_party/pylint/epylint.py +2 -1
  134. data/vendor/depot_tools/third_party/pylint/gui.py +1 -1
  135. data/vendor/depot_tools/third_party/pylint/lint.py +88 -23
  136. data/vendor/depot_tools/third_party/pylint/reporters/html.py +37 -5
  137. data/vendor/depot_tools/third_party/pylint/testutils.py +1 -1
  138. data/vendor/depot_tools/third_party/pylint/utils.py +5 -0
  139. data/vendor/depot_tools/vpython +31 -1
  140. data/vendor/depot_tools/win_toolchain/get_toolchain_if_necessary.py +35 -2
  141. data/vendor/depot_tools/win_toolchain/package_from_installed.py +0 -15
  142. data/vendor/depot_tools/yapf +17 -0
  143. data/vendor/depot_tools/{apply_issue.bat → yapf.bat} +2 -2
  144. metadata +16 -58
  145. data/ext/libv8/compiler.rb +0 -39
  146. data/ext/libv8/compiler/apple_llvm.rb +0 -22
  147. data/ext/libv8/compiler/clang.rb +0 -22
  148. data/ext/libv8/compiler/gcc.rb +0 -22
  149. data/ext/libv8/compiler/generic_compiler.rb +0 -66
  150. data/ext/libv8/make.rb +0 -13
  151. data/ext/libv8/patcher.rb +0 -21
  152. data/patches/0001-Build-a-standalone-static-library.patch +0 -26
  153. data/patches/0002-Don-t-compile-unnecessary-stuff.patch +0 -85
  154. data/patches/0003-Use-the-fPIC-flag-for-the-static-library.patch +0 -25
  155. data/patches/0004-Do-not-embed-debug-symbols-in-macOS-libraries.patch +0 -25
  156. data/patches/0005-Remove-TryInstallOptimizedCode.patch +0 -321
  157. data/patches/mingw-generate-makefiles.sh +0 -97
  158. data/spec/compiler/apple_llvm_spec.rb +0 -37
  159. data/spec/compiler/clang_spec.rb +0 -37
  160. data/spec/compiler/gcc_spec.rb +0 -37
  161. data/spec/compiler/generic_compiler_spec.rb +0 -50
  162. data/spec/compiler_spec.rb +0 -45
  163. data/spec/support/compiler_helpers.rb +0 -47
  164. data/vendor/depot_tools/apply_issue +0 -8
  165. data/vendor/depot_tools/apply_issue.py +0 -315
  166. data/vendor/depot_tools/man/html/git-cherry-pick-upload.html +0 -815
  167. data/vendor/depot_tools/man/man1/git-cherry-pick-upload.1 +0 -80
  168. data/vendor/depot_tools/man/src/_git-cherry-pick-upload_desc.helper.txt +0 -1
  169. data/vendor/depot_tools/man/src/git-cherry-pick-upload.demo.1.sh +0 -17
  170. data/vendor/depot_tools/man/src/git-cherry-pick-upload.txt +0 -35
  171. data/vendor/depot_tools/recipes/recipe_modules/bot_update/examples/full.expected/trychange_oauth2.json +0 -8
  172. data/vendor/depot_tools/recipes/recipe_modules/bot_update/examples/full.expected/trychange_oauth2_json_win.json +0 -196
  173. data/vendor/depot_tools/recipes/recipe_modules/rietveld/__init__.py +0 -6
  174. data/vendor/depot_tools/recipes/recipe_modules/rietveld/api.py +0 -97
  175. data/vendor/depot_tools/recipes/recipe_modules/rietveld/examples/full.expected/basic.json +0 -8
  176. data/vendor/depot_tools/recipes/recipe_modules/rietveld/examples/full.expected/buildbot.json +0 -30
  177. data/vendor/depot_tools/recipes/recipe_modules/rietveld/examples/full.expected/no_auth.json +0 -27
  178. data/vendor/depot_tools/recipes/recipe_modules/rietveld/examples/full.py +0 -38
  179. data/vendor/depot_tools/recipes/recipe_modules/tryserver/examples/full.expected/with_rietveld_patch.json +0 -69
  180. data/vendor/depot_tools/recipes/recipe_modules/tryserver/examples/full.expected/with_rietveld_patch_new.json +0 -69
  181. data/vendor/depot_tools/third_party/cq_client/OWNERS +0 -2
  182. data/vendor/depot_tools/third_party/cq_client/README.depot_tools.md +0 -2
  183. data/vendor/depot_tools/third_party/cq_client/README.md +0 -59
  184. data/vendor/depot_tools/third_party/cq_client/__init__.py +0 -3
  185. data/vendor/depot_tools/third_party/cq_client/v1/__init__.py +0 -3
  186. data/vendor/depot_tools/third_party/cq_client/v1/cq.pb.go +0 -810
  187. data/vendor/depot_tools/third_party/cq_client/v1/cq.proto +0 -281
  188. data/vendor/depot_tools/third_party/cq_client/v1/cq_pb2.py +0 -794
  189. data/vendor/depot_tools/third_party/cq_client/v1/testdata/cq_both.cfg +0 -71
  190. data/vendor/depot_tools/third_party/cq_client/v1/testdata/cq_gerrit.cfg +0 -58
  191. data/vendor/depot_tools/third_party/cq_client/v1/testdata/cq_rietveld.cfg +0 -60
  192. data/vendor/depot_tools/third_party/cq_client/v2/__init__.py +0 -3
  193. data/vendor/depot_tools/third_party/cq_client/v2/cq.pb.go +0 -792
  194. data/vendor/depot_tools/third_party/cq_client/v2/cq.proto +0 -270
  195. data/vendor/depot_tools/third_party/cq_client/v2/cq_pb2.py +0 -841
@@ -12,12 +12,13 @@
12
12
  # this program; if not, write to the Free Software Foundation, Inc.,
13
13
  # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
14
14
  """Check Python 2 code for Python 2/3 source-compatible issues."""
15
- from __future__ import absolute_import
15
+ from __future__ import absolute_import, print_function
16
16
 
17
17
  import re
18
18
  import tokenize
19
19
 
20
20
  import astroid
21
+ from astroid import bases
21
22
  from pylint import checkers, interfaces
22
23
  from pylint.utils import WarningScope
23
24
  from pylint.checkers import utils
@@ -46,6 +47,46 @@ def _check_dict_node(node):
46
47
  return (not inferred_types
47
48
  or any(isinstance(x, astroid.Dict) for x in inferred_types))
48
49
 
50
+ def _is_builtin(node):
51
+ return getattr(node, 'name', None) in ('__builtin__', 'builtins')
52
+
53
+ _accepts_iterator = {'iter', 'list', 'tuple', 'sorted', 'set', 'sum', 'any',
54
+ 'all', 'enumerate', 'dict'}
55
+
56
+ def _in_iterating_context(node):
57
+ """Check if the node is being used as an iterator.
58
+
59
+ Definition is taken from lib2to3.fixer_util.in_special_context().
60
+ """
61
+ parent = node.parent
62
+ # Since a call can't be the loop variant we only need to know if the node's
63
+ # parent is a 'for' loop to know it's being used as the iterator for the
64
+ # loop.
65
+ if isinstance(parent, astroid.For):
66
+ return True
67
+ # Need to make sure the use of the node is in the iterator part of the
68
+ # comprehension.
69
+ elif isinstance(parent, astroid.Comprehension):
70
+ if parent.iter == node:
71
+ return True
72
+ # Various built-ins can take in an iterable or list and lead to the same
73
+ # value.
74
+ elif isinstance(parent, astroid.CallFunc):
75
+ if isinstance(parent.func, astroid.Name):
76
+ parent_scope = parent.func.lookup(parent.func.name)[0]
77
+ if _is_builtin(parent_scope) and parent.func.name in _accepts_iterator:
78
+ return True
79
+ elif isinstance(parent.func, astroid.Getattr):
80
+ if parent.func.attrname == 'join':
81
+ return True
82
+ # If the call is in an unpacking, there's no need to warn,
83
+ # since it can be considered iterating.
84
+ elif (isinstance(parent, astroid.Assign) and
85
+ isinstance(parent.targets[0], (astroid.List, astroid.Tuple))):
86
+ if len(parent.targets[0].elts) > 1:
87
+ return True
88
+ return False
89
+
49
90
 
50
91
  class Python3Checker(checkers.BaseChecker):
51
92
 
@@ -177,13 +218,13 @@ class Python3Checker(checkers.BaseChecker):
177
218
  'W1618': ('import missing `from __future__ import absolute_import`',
178
219
  'no-absolute-import',
179
220
  'Used when an import is not accompanied by '
180
- '`from __future__ import absolute_import`'
181
- ' (default behaviour in Python 3)',
221
+ '``from __future__ import absolute_import`` '
222
+ '(default behaviour in Python 3)',
182
223
  {'maxversion': (3, 0)}),
183
224
  'W1619': ('division w/o __future__ statement',
184
225
  'old-division',
185
226
  'Used for non-floor division w/o a float literal or '
186
- '``from __future__ import division``'
227
+ '``from __future__ import division`` '
187
228
  '(Python 3 returns a float for int division unconditionally)',
188
229
  {'maxversion': (3, 0)}),
189
230
  'W1620': ('Calling a dict.iter*() method',
@@ -244,14 +285,7 @@ class Python3Checker(checkers.BaseChecker):
244
285
  'Used when a __cmp__ method is defined '
245
286
  '(method is not used by Python 3)',
246
287
  {'maxversion': (3, 0)}),
247
- 'W1631': ('map is used as implicitly evaluated call',
248
- 'implicit-map-evaluation',
249
- 'Used when the map builtin is used as implicitly '
250
- 'evaluated call, as in "map(func, args)" on a single line. '
251
- 'This behaviour will not work in Python 3, where '
252
- 'map is a generator and must be evaluated. '
253
- 'Prefer a for-loop as alternative.',
254
- {'maxversion': (3, 0)}),
288
+ # 'W1631': replaced by W1636
255
289
  'W1632': ('input built-in referenced',
256
290
  'input-builtin',
257
291
  'Used when the input built-in is referenced '
@@ -262,6 +296,44 @@ class Python3Checker(checkers.BaseChecker):
262
296
  'Used when the round built-in is referenced '
263
297
  '(backwards-incompatible semantics in Python 3)',
264
298
  {'maxversion': (3, 0)}),
299
+ 'W1634': ('intern built-in referenced',
300
+ 'intern-builtin',
301
+ 'Used when the intern built-in is referenced '
302
+ '(Moved to sys.intern in Python 3)',
303
+ {'maxversion': (3, 0)}),
304
+ 'W1635': ('unichr built-in referenced',
305
+ 'unichr-builtin',
306
+ 'Used when the unichr built-in is referenced '
307
+ '(Use chr in Python 3)',
308
+ {'maxversion': (3, 0)}),
309
+ 'W1636': ('map built-in referenced when not iterating',
310
+ 'map-builtin-not-iterating',
311
+ 'Used when the map built-in is referenced in a non-iterating '
312
+ 'context (returns an iterator in Python 3)',
313
+ {'maxversion': (3, 0),
314
+ 'old_names': [('W1631', 'implicit-map-evaluation')]}),
315
+ 'W1637': ('zip built-in referenced when not iterating',
316
+ 'zip-builtin-not-iterating',
317
+ 'Used when the zip built-in is referenced in a non-iterating '
318
+ 'context (returns an iterator in Python 3)',
319
+ {'maxversion': (3, 0)}),
320
+ 'W1638': ('range built-in referenced when not iterating',
321
+ 'range-builtin-not-iterating',
322
+ 'Used when the range built-in is referenced in a non-iterating '
323
+ 'context (returns an iterator in Python 3)',
324
+ {'maxversion': (3, 0)}),
325
+ 'W1639': ('filter built-in referenced when not iterating',
326
+ 'filter-builtin-not-iterating',
327
+ 'Used when the filter built-in is referenced in a non-iterating '
328
+ 'context (returns an iterator in Python 3)',
329
+ {'maxversion': (3, 0)}),
330
+ 'W1640': ('Using the cmp argument for list.sort / sorted',
331
+ 'using-cmp-argument',
332
+ 'Using the cmp argument for list.sort or the sorted '
333
+ 'builtin should be avoided, since it was removed in '
334
+ 'Python 3. Using either `key` or `functools.cmp_to_key` '
335
+ 'should be preferred.',
336
+ {'maxversion': (3, 0)}),
265
337
  }
266
338
 
267
339
  _bad_builtins = frozenset([
@@ -273,11 +345,13 @@ class Python3Checker(checkers.BaseChecker):
273
345
  'execfile',
274
346
  'file',
275
347
  'input', # Not missing, but incompatible semantics
348
+ 'intern',
276
349
  'long',
277
350
  'raw_input',
278
351
  'reduce',
279
352
  'round', # Not missing, but incompatible semantics
280
353
  'StandardError',
354
+ 'unichr',
281
355
  'unicode',
282
356
  'xrange',
283
357
  'reload',
@@ -299,6 +373,11 @@ class Python3Checker(checkers.BaseChecker):
299
373
  self._future_absolute_import = False
300
374
  super(Python3Checker, self).__init__(*args, **kwargs)
301
375
 
376
+ def visit_module(self, node): # pylint: disable=unused-argument
377
+ """Clear checker state after previous module."""
378
+ self._future_division = False
379
+ self._future_absolute_import = False
380
+
302
381
  def visit_function(self, node):
303
382
  if node.is_method() and node.name in self._unused_magic_methods:
304
383
  method_name = node.name
@@ -312,19 +391,10 @@ class Python3Checker(checkers.BaseChecker):
312
391
  if isinstance(arg, astroid.Tuple):
313
392
  self.add_message('parameter-unpacking', node=arg)
314
393
 
315
- @utils.check_messages('implicit-map-evaluation')
316
- def visit_discard(self, node):
317
- if (isinstance(node.value, astroid.CallFunc) and
318
- isinstance(node.value.func, astroid.Name) and
319
- node.value.func.name == 'map'):
320
- module = node.value.func.lookup('map')[0]
321
- if getattr(module, 'name', None) == '__builtin__':
322
- self.add_message('implicit-map-evaluation', node=node)
323
-
324
394
  def visit_name(self, node):
325
395
  """Detect when a "bad" built-in is referenced."""
326
396
  found_node = node.lookup(node.name)[0]
327
- if getattr(found_node, 'name', None) == '__builtin__':
397
+ if _is_builtin(found_node):
328
398
  if node.name in self._bad_builtins:
329
399
  message = node.name.lower() + '-builtin'
330
400
  self.add_message(message, node=node)
@@ -363,22 +433,57 @@ class Python3Checker(checkers.BaseChecker):
363
433
  else:
364
434
  self.add_message('old-division', node=node)
365
435
 
366
- @utils.check_messages('next-method-called',
367
- 'dict-iter-method',
368
- 'dict-view-method')
436
+ def _check_cmp_argument(self, node):
437
+ # Check that the `cmp` argument is used
438
+ args = []
439
+ if (isinstance(node.func, astroid.Getattr)
440
+ and node.func.attrname == 'sort'):
441
+ inferred = utils.safe_infer(node.func.expr)
442
+ if not inferred:
443
+ return
444
+
445
+ builtins_list = "{}.list".format(bases.BUILTINS)
446
+ if (isinstance(inferred, astroid.List)
447
+ or inferred.qname() == builtins_list):
448
+ args = node.args
449
+
450
+ elif (isinstance(node.func, astroid.Name)
451
+ and node.func.name == 'sorted'):
452
+ inferred = utils.safe_infer(node.func)
453
+ if not inferred:
454
+ return
455
+
456
+ builtins_sorted = "{}.sorted".format(bases.BUILTINS)
457
+ if inferred.qname() == builtins_sorted:
458
+ args = node.args
459
+
460
+ for arg in args:
461
+ if isinstance(arg, astroid.Keyword) and arg.arg == 'cmp':
462
+ self.add_message('using-cmp-argument', node=node)
463
+ return
464
+
369
465
  def visit_callfunc(self, node):
370
- if not isinstance(node.func, astroid.Getattr):
371
- return
372
- if any([node.args, node.starargs, node.kwargs]):
373
- return
374
- if node.func.attrname == 'next':
375
- self.add_message('next-method-called', node=node)
376
- else:
377
- if _check_dict_node(node.func.expr):
378
- if node.func.attrname in ('iterkeys', 'itervalues', 'iteritems'):
379
- self.add_message('dict-iter-method', node=node)
380
- elif node.func.attrname in ('viewkeys', 'viewvalues', 'viewitems'):
381
- self.add_message('dict-view-method', node=node)
466
+ self._check_cmp_argument(node)
467
+
468
+ if isinstance(node.func, astroid.Getattr):
469
+ if any([node.args, node.starargs, node.kwargs]):
470
+ return
471
+ if node.func.attrname == 'next':
472
+ self.add_message('next-method-called', node=node)
473
+ else:
474
+ if _check_dict_node(node.func.expr):
475
+ if node.func.attrname in ('iterkeys', 'itervalues', 'iteritems'):
476
+ self.add_message('dict-iter-method', node=node)
477
+ elif node.func.attrname in ('viewkeys', 'viewvalues', 'viewitems'):
478
+ self.add_message('dict-view-method', node=node)
479
+ elif isinstance(node.func, astroid.Name):
480
+ found_node = node.func.lookup(node.func.name)[0]
481
+ if _is_builtin(found_node):
482
+ if node.func.name in ('filter', 'map', 'range', 'zip'):
483
+ if not _in_iterating_context(node):
484
+ checker = '{}-builtin-not-iterating'.format(node.func.name)
485
+ self.add_message(checker, node=node)
486
+
382
487
 
383
488
  @utils.check_messages('indexing-exception')
384
489
  def visit_subscript(self, node):
@@ -61,6 +61,9 @@ class SpellingChecker(BaseTokenChecker):
61
61
  '%s\nDid you mean: \'%s\'?',
62
62
  'wrong-spelling-in-docstring',
63
63
  'Used when a word in docstring is not spelled correctly.'),
64
+ 'C0403': ('Invalid characters %r in a docstring',
65
+ 'invalid-characters-in-docstring',
66
+ 'Used when a word in docstring cannot be checked by enchant.'),
64
67
  }
65
68
  options = (('spelling-dict',
66
69
  {'default' : '', 'type' : 'choice', 'metavar' : '<dict name>',
@@ -168,7 +171,13 @@ class SpellingChecker(BaseTokenChecker):
168
171
  word = word[2:]
169
172
 
170
173
  # If it is a known word, then continue.
171
- if self.spelling_dict.check(word):
174
+ try:
175
+ if self.spelling_dict.check(word):
176
+ continue
177
+ except enchant.errors.Error:
178
+ # this can only happen in docstrings, not comments
179
+ self.add_message('invalid-characters-in-docstring',
180
+ line=line_num, args=(word,))
172
181
  continue
173
182
 
174
183
  # Store word to private dict or raise a message.
@@ -15,7 +15,6 @@
15
15
  # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16
16
  """Checkers for various standard library functions."""
17
17
 
18
- import re
19
18
  import six
20
19
  import sys
21
20
 
@@ -27,10 +26,15 @@ from pylint.checkers import BaseChecker
27
26
  from pylint.checkers import utils
28
27
 
29
28
 
29
+ TYPECHECK_COMPARISON_OPERATORS = frozenset(('is', 'is not', '==', '!=', 'in', 'not in'))
30
+ LITERAL_NODE_TYPES = (astroid.Const, astroid.Dict, astroid.List, astroid.Set)
31
+
30
32
  if sys.version_info >= (3, 0):
31
33
  OPEN_MODULE = '_io'
34
+ TYPE_QNAME = 'builtins.type'
32
35
  else:
33
36
  OPEN_MODULE = '__builtin__'
37
+ TYPE_QNAME = '__builtin__.type'
34
38
 
35
39
 
36
40
  def _check_mode_str(mode):
@@ -50,7 +54,6 @@ def _check_mode_str(mode):
50
54
  reading = "r" in modes
51
55
  writing = "w" in modes
52
56
  appending = "a" in modes
53
- updating = "+" in modes
54
57
  text = "t" in modes
55
58
  binary = "b" in modes
56
59
  if "U" in modes:
@@ -76,6 +79,15 @@ def _check_mode_str(mode):
76
79
  return True
77
80
 
78
81
 
82
+ def _is_one_arg_pos_call(call):
83
+ """Is this a call with exactly 1 argument,
84
+ where that argument is positional?
85
+ """
86
+ return (isinstance(call, astroid.CallFunc)
87
+ and len(call.args) == 1
88
+ and not isinstance(call.args[0], astroid.Keyword))
89
+
90
+
79
91
  class StdlibChecker(BaseChecker):
80
92
  __implements__ = (IAstroidChecker,)
81
93
  name = 'stdlib'
@@ -88,7 +100,7 @@ class StdlibChecker(BaseChecker):
88
100
  'See http://docs.python.org/2/library/functions.html#open'),
89
101
  'W1502': ('Using datetime.time in a boolean context.',
90
102
  'boolean-datetime',
91
- 'Using datetetime.time in a boolean context can hide '
103
+ 'Using datetime.time in a boolean context can hide '
92
104
  'subtle bugs when the time they represent matches '
93
105
  'midnight UTC. This behaviour was fixed in Python 3.5. '
94
106
  'See http://bugs.python.org/issue13936 for reference.',
@@ -96,10 +108,16 @@ class StdlibChecker(BaseChecker):
96
108
  'W1503': ('Redundant use of %s with constant '
97
109
  'value %r',
98
110
  'redundant-unittest-assert',
99
- 'The first argument of assertTrue and assertFalse is'
100
- 'a condition. If a constant is passed as parameter, that'
111
+ 'The first argument of assertTrue and assertFalse is '
112
+ 'a condition. If a constant is passed as parameter, that '
101
113
  'condition will be always true. In this case a warning '
102
- 'should be emitted.')
114
+ 'should be emitted.'),
115
+ 'W1504': ('Using type() instead of isinstance() for a typecheck.',
116
+ 'unidiomatic-typecheck',
117
+ 'The idiomatic way to perform an explicit typecheck in '
118
+ 'Python is to use isinstance(x, Y) rather than '
119
+ 'type(x) == Y, type(x) is Y. Though there are unusual '
120
+ 'situations where these give different results.')
103
121
  }
104
122
 
105
123
  @utils.check_messages('bad-open-mode', 'redundant-unittest-assert')
@@ -132,6 +150,14 @@ class StdlibChecker(BaseChecker):
132
150
  for value in node.values:
133
151
  self._check_datetime(value)
134
152
 
153
+ @utils.check_messages('unidiomatic-typecheck')
154
+ def visit_compare(self, node):
155
+ operator, right = node.ops[0]
156
+ if operator in TYPECHECK_COMPARISON_OPERATORS:
157
+ left = node.left
158
+ if _is_one_arg_pos_call(left):
159
+ self._check_type_x_is_y(node, left, operator, right)
160
+
135
161
  def _check_redundant_assert(self, node, infer):
136
162
  if (isinstance(infer, astroid.BoundMethod) and
137
163
  node.args and isinstance(node.args[0], astroid.Const) and
@@ -152,7 +178,6 @@ class StdlibChecker(BaseChecker):
152
178
  infered.qname() == 'datetime.time'):
153
179
  self.add_message('boolean-datetime', node=node)
154
180
 
155
-
156
181
  def _check_open_mode(self, node):
157
182
  """Check that the mode argument of an open or file call is valid."""
158
183
  try:
@@ -167,6 +192,24 @@ class StdlibChecker(BaseChecker):
167
192
  self.add_message('bad-open-mode', node=node,
168
193
  args=mode_arg.value)
169
194
 
195
+ def _check_type_x_is_y(self, node, left, operator, right):
196
+ """Check for expressions like type(x) == Y."""
197
+ left_func = utils.safe_infer(left.func)
198
+ if not (isinstance(left_func, astroid.Class)
199
+ and left_func.qname() == TYPE_QNAME):
200
+ return
201
+
202
+ if operator in ('is', 'is not') and _is_one_arg_pos_call(right):
203
+ right_func = utils.safe_infer(right.func)
204
+ if (isinstance(right_func, astroid.Class)
205
+ and right_func.qname() == TYPE_QNAME):
206
+ # type(x) == type(a)
207
+ right_arg = utils.safe_infer(right.args[0])
208
+ if not isinstance(right_arg, LITERAL_NODE_TYPES):
209
+ # not e.g. type(x) == type([])
210
+ return
211
+ self.add_message('unidiomatic-typecheck', node=node)
212
+
170
213
 
171
214
  def register(linter):
172
215
  """required method to auto register this checker """
@@ -181,7 +181,7 @@ def parse_format_method_string(format_string):
181
181
  if isinstance(keyname, numbers.Number):
182
182
  # In Python 2 it will return long which will lead
183
183
  # to different output between 2 and 3
184
- manual_pos_arg.add(keyname)
184
+ manual_pos_arg.add(str(keyname))
185
185
  keyname = int(keyname)
186
186
  keys.append((keyname, list(fielditerator)))
187
187
  else:
@@ -1,4 +1,5 @@
1
- # -*- coding: utf-8; mode: python; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=python:et:sw=4:ts=4:sts=4
1
+ # -*- coding: utf-8; mode: python; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4
2
+ # -*- vim:fenc=utf-8:ft=python:et:sw=4:ts=4:sts=4
2
3
  # Copyright (c) 2003-2013 LOGILAB S.A. (Paris, FRANCE).
3
4
  # http://www.logilab.fr/ -- mailto:contact@logilab.fr
4
5
  #
@@ -38,7 +38,7 @@ from pylint.reporters.guireporter import GUIReporter
38
38
 
39
39
  HOME = os.path.expanduser('~/')
40
40
  HISTORY = '.pylint-gui-history'
41
- COLORS = {'(I)':'lightblue',
41
+ COLORS = {'(I)':'green',
42
42
  '(C)':'blue', '(R)':'darkblue',
43
43
  '(W)':'black', '(E)':'darkred',
44
44
  '(F)':'red'}
@@ -48,7 +48,7 @@ from logilab.common import optik_ext
48
48
  from logilab.common import interface
49
49
  from logilab.common import textutils
50
50
  from logilab.common import ureports
51
- from logilab.common.__pkginfo__ import version as common_version
51
+ from logilab.common import __version__ as common_version
52
52
  import six
53
53
 
54
54
  from pylint import checkers
@@ -60,6 +60,10 @@ from pylint.__pkginfo__ import version
60
60
 
61
61
 
62
62
  MANAGER = astroid.MANAGER
63
+ INCLUDE_IDS_HELP = ("Deprecated. It was used to include message\'s "
64
+ "id in output. Use --msg-template instead.")
65
+ SYMBOLS_HELP = ("Deprecated. It was used to include symbolic ids of "
66
+ "messages in output. Use --msg-template instead.")
63
67
 
64
68
  def _get_new_args(message):
65
69
  location = (
@@ -105,6 +109,24 @@ def _merge_stats(stats):
105
109
  return merged
106
110
 
107
111
 
112
+ @contextlib.contextmanager
113
+ def _patch_sysmodules():
114
+ # Context manager that permits running pylint, on Windows, with -m switch
115
+ # and with --jobs, as in 'python -2 -m pylint .. --jobs'.
116
+ # For more details why this is needed,
117
+ # see Python issue http://bugs.python.org/issue10845.
118
+
119
+ mock_main = __name__ != '__main__' # -m switch
120
+ if mock_main:
121
+ sys.modules['__main__'] = sys.modules[__name__]
122
+
123
+ try:
124
+ yield
125
+ finally:
126
+ if mock_main:
127
+ sys.modules.pop('__main__')
128
+
129
+
108
130
  # Python Linter class #########################################################
109
131
 
110
132
  MSGS = {
@@ -177,10 +199,10 @@ MSGS = {
177
199
  }
178
200
 
179
201
 
180
- def _deprecated_option(shortname, opt_type):
202
+ def _deprecated_option(shortname, opt_type, help_msg):
181
203
  def _warn_deprecated(option, optname, *args): # pylint: disable=unused-argument
182
204
  sys.stderr.write('Warning: option %s is deprecated and ignored.\n' % (optname,))
183
- return {'short': shortname, 'help': 'DEPRECATED', 'hide': True,
205
+ return {'short': shortname, 'help': help_msg, 'hide': True,
184
206
  'type': opt_type, 'action': 'callback', 'callback': _warn_deprecated}
185
207
 
186
208
 
@@ -190,6 +212,8 @@ if multiprocessing is not None:
190
212
  tasks_queue, results_queue, self._config = self._args # pylint: disable=no-member
191
213
 
192
214
  self._config["jobs"] = 1 # Child does not parallelize any further.
215
+ self._python3_porting_mode = self._config.pop(
216
+ 'python3_porting_mode', None)
193
217
 
194
218
  # Run linter for received files/modules.
195
219
  for file_or_module in iter(tasks_queue.get, 'STOP'):
@@ -197,7 +221,8 @@ if multiprocessing is not None:
197
221
  try:
198
222
  results_queue.put(result)
199
223
  except Exception as ex:
200
- print("internal error with sending report for module %s" % file_or_module, file=sys.stderr)
224
+ print("internal error with sending report for module %s" %
225
+ file_or_module, file=sys.stderr)
201
226
  print(ex, file=sys.stderr)
202
227
  results_queue.put({})
203
228
 
@@ -212,6 +237,13 @@ if multiprocessing is not None:
212
237
  linter.load_configuration(**self._config)
213
238
  linter.set_reporter(reporters.CollectingReporter())
214
239
 
240
+ # Enable the Python 3 checker mode. This option is
241
+ # passed down from the parent linter up to here, since
242
+ # the Python 3 porting flag belongs to the Run class,
243
+ # instead of the Linter class.
244
+ if self._python3_porting_mode:
245
+ linter.python3_porting_mode()
246
+
215
247
  # Run the checks.
216
248
  linter.check(file_or_module)
217
249
 
@@ -350,8 +382,9 @@ class PyLinter(configuration.OptionsManagerMixIn,
350
382
  'See doc for all details')
351
383
  }),
352
384
 
353
- ('include-ids', _deprecated_option('i', 'yn')),
354
- ('symbols', _deprecated_option('s', 'yn')),
385
+ ('include-ids', _deprecated_option('i', 'yn',
386
+ INCLUDE_IDS_HELP)),
387
+ ('symbols', _deprecated_option('s', 'yn', SYMBOLS_HELP)),
355
388
 
356
389
  ('jobs',
357
390
  {'type' : 'int', 'metavar': '<n-processes>',
@@ -373,6 +406,19 @@ class PyLinter(configuration.OptionsManagerMixIn,
373
406
  ' loading into the active Python interpreter and may run'
374
407
  ' arbitrary code')}
375
408
  ),
409
+
410
+ ('optimize-ast',
411
+ {'type': 'yn', 'metavar': '<yn>', 'default': False,
412
+ 'help': ('Allow optimization of some AST trees. This will '
413
+ 'activate a peephole AST optimizer, which will '
414
+ 'apply various small optimizations. For instance, '
415
+ 'it can be used to obtain the result of joining '
416
+ 'multiple strings with the addition operator. '
417
+ 'Joining a lot of strings can lead to a maximum '
418
+ 'recursion error in Pylint and this flag can prevent '
419
+ 'that. It has one side effect, the resulting AST '
420
+ 'will be different than the one from reality.')}
421
+ ),
376
422
  )
377
423
 
378
424
  option_groups = (
@@ -427,6 +473,8 @@ class PyLinter(configuration.OptionsManagerMixIn,
427
473
  )
428
474
  self.register_checker(self)
429
475
  self._dynamic_plugins = set()
476
+ self._python3_porting_mode = False
477
+ self._error_mode = False
430
478
  self.load_provider_defaults()
431
479
  if reporter:
432
480
  self.set_reporter(reporter)
@@ -555,11 +603,34 @@ class PyLinter(configuration.OptionsManagerMixIn,
555
603
 
556
604
  def error_mode(self):
557
605
  """error mode: enable only errors; no reports, no persistent"""
606
+ self._error_mode = True
558
607
  self.disable_noerror_messages()
559
608
  self.disable('miscellaneous')
609
+ if self._python3_porting_mode:
610
+ self.disable('all')
611
+ for msg_id in self._checker_messages('python3'):
612
+ if msg_id.startswith('E'):
613
+ self.enable(msg_id)
614
+ else:
615
+ self.disable('python3')
560
616
  self.set_option('reports', False)
561
617
  self.set_option('persistent', False)
562
618
 
619
+ def python3_porting_mode(self):
620
+ """Disable all other checkers and enable Python 3 warnings."""
621
+ self.disable('all')
622
+ self.enable('python3')
623
+ if self._error_mode:
624
+ # The error mode was activated, using the -E flag.
625
+ # So we'll need to enable only the errors from the
626
+ # Python 3 porting checker.
627
+ for msg_id in self._checker_messages('python3'):
628
+ if msg_id.startswith('E'):
629
+ self.enable(msg_id)
630
+ else:
631
+ self.disable(msg_id)
632
+ self._python3_porting_mode = True
633
+
563
634
  # block level option handling #############################################
564
635
  #
565
636
  # see func_block_disable_msg.py test case for expected behaviour
@@ -596,7 +667,8 @@ class PyLinter(configuration.OptionsManagerMixIn,
596
667
  except KeyError:
597
668
  meth = self._bw_options_methods[opt]
598
669
  # found a "(dis|en)able-msg" pragma deprecated suppresssion
599
- self.add_message('deprecated-pragma', line=start[0], args=(opt, opt.replace('-msg', '')))
670
+ self.add_message('deprecated-pragma', line=start[0],
671
+ args=(opt, opt.replace('-msg', '')))
600
672
  for msgid in textutils.splitstrip(value):
601
673
  # Add the line where a control pragma was encountered.
602
674
  if opt in control_pragmas:
@@ -604,7 +676,8 @@ class PyLinter(configuration.OptionsManagerMixIn,
604
676
 
605
677
  try:
606
678
  if (opt, msgid) == ('disable', 'all'):
607
- self.add_message('deprecated-pragma', line=start[0], args=('disable=all', 'skip-file'))
679
+ self.add_message('deprecated-pragma', line=start[0],
680
+ args=('disable=all', 'skip-file'))
608
681
  self.add_message('file-ignored', line=start[0])
609
682
  self._ignore_file = True
610
683
  return
@@ -674,19 +747,9 @@ class PyLinter(configuration.OptionsManagerMixIn,
674
747
  with fix_import_path(files_or_modules):
675
748
  self._do_check(files_or_modules)
676
749
  else:
677
- # Hack that permits running pylint, on Windows, with -m switch
678
- # and with --jobs, as in 'python -2 -m pylint .. --jobs'.
679
- # For more details why this is needed,
680
- # see Python issue http://bugs.python.org/issue10845.
681
-
682
- mock_main = __name__ != '__main__' # -m switch
683
- if mock_main:
684
- sys.modules['__main__'] = sys.modules[__name__]
685
- try:
750
+ with _patch_sysmodules():
686
751
  self._parallel_check(files_or_modules)
687
- finally:
688
- if mock_main:
689
- sys.modules.pop('__main__')
752
+
690
753
 
691
754
  def _parallel_task(self, files_or_modules):
692
755
  # Prepare configuration for child linters.
@@ -697,6 +760,7 @@ class PyLinter(configuration.OptionsManagerMixIn,
697
760
  for optname, optdict, val in opt_providers.options_and_values():
698
761
  if optname not in filter_options:
699
762
  config[optname] = configuration.format_option_value(optdict, val)
763
+ config['python3_porting_mode'] = self._python3_porting_mode
700
764
 
701
765
  childs = []
702
766
  manager = multiprocessing.Manager() # pylint: disable=no-member
@@ -805,7 +869,8 @@ class PyLinter(configuration.OptionsManagerMixIn,
805
869
  self.current_file = ast_node.file # pylint: disable=maybe-no-member
806
870
  self.check_astroid_module(ast_node, walker, rawcheckers, tokencheckers)
807
871
  # warn about spurious inline messages handling
808
- for msgid, line, args in self.file_state.iter_spurious_suppression_messages(self.msgs_store):
872
+ spurious_messages = self.file_state.iter_spurious_suppression_messages(self.msgs_store)
873
+ for msgid, line, args in spurious_messages:
809
874
  self.add_message(msgid, line, None, args)
810
875
  # notify global end
811
876
  self.stats['statement'] = walker.nbstatements
@@ -889,6 +954,7 @@ class PyLinter(configuration.OptionsManagerMixIn,
889
954
  self.stats = {'by_module' : {},
890
955
  'by_msg' : {},
891
956
  }
957
+ MANAGER.optimize_ast = self.config.optimize_ast
892
958
  MANAGER.always_load_extensions = self.config.unsafe_load_any_extension
893
959
  MANAGER.extension_package_whitelist.update(
894
960
  self.config.extension_pkg_whitelist)
@@ -1315,8 +1381,7 @@ group are mutually exclusive.'),
1315
1381
 
1316
1382
  def cb_python3_porting_mode(self, *args, **kwargs):
1317
1383
  """Activate only the python3 porting checker."""
1318
- self.linter.disable('all')
1319
- self.linter.enable('python3')
1384
+ self.linter.python3_porting_mode()
1320
1385
 
1321
1386
 
1322
1387
  def cb_list_confidence_levels(option, optname, value, parser):