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
@@ -28,7 +28,7 @@ from astroid.manager import AstroidManager
28
28
  from astroid.exceptions import (AstroidError, InferenceError, NoDefault,
29
29
  NotFoundError, UnresolvableName)
30
30
  from astroid.bases import (YES, Instance, InferenceContext,
31
- _infer_stmts, path_wrapper,
31
+ _infer_stmts, copy_context, path_wrapper,
32
32
  raise_if_nothing_infered)
33
33
  from astroid.protocols import (
34
34
  _arguments_infer_argname,
@@ -175,89 +175,92 @@ def infer_name(self, context=None):
175
175
 
176
176
  if not stmts:
177
177
  raise UnresolvableName(self.name)
178
- return _infer_stmts(stmts, context, frame, self.name)
178
+ context = context.clone()
179
+ context.lookupname = self.name
180
+ return _infer_stmts(stmts, context, frame)
179
181
  nodes.Name._infer = path_wrapper(infer_name)
180
182
  nodes.AssName.infer_lhs = infer_name # won't work with a path wrapper
181
183
 
182
184
 
183
185
  def infer_callfunc(self, context=None):
184
186
  """infer a CallFunc node by trying to guess what the function returns"""
185
- if context is None:
186
- context = InferenceContext()
187
+ callcontext = context.clone()
188
+ callcontext.callcontext = CallContext(self.args, self.starargs, self.kwargs)
189
+ callcontext.boundnode = None
187
190
  for callee in self.func.infer(context):
188
- with context.scope(
189
- callcontext=CallContext(self.args, self.starargs, self.kwargs),
190
- boundnode=None,
191
- ):
192
- if callee is YES:
193
- yield callee
194
- continue
195
- try:
196
- if hasattr(callee, 'infer_call_result'):
197
- for infered in callee.infer_call_result(self, context):
198
- yield infered
199
- except InferenceError:
200
- ## XXX log error ?
201
- continue
191
+ if callee is YES:
192
+ yield callee
193
+ continue
194
+ try:
195
+ if hasattr(callee, 'infer_call_result'):
196
+ for infered in callee.infer_call_result(self, callcontext):
197
+ yield infered
198
+ except InferenceError:
199
+ ## XXX log error ?
200
+ continue
202
201
  nodes.CallFunc._infer = path_wrapper(raise_if_nothing_infered(infer_callfunc))
203
202
 
204
203
 
205
- def infer_import(self, context=None, asname=True, lookupname=None):
204
+ def infer_import(self, context=None, asname=True):
206
205
  """infer an Import node: return the imported module/object"""
207
- if lookupname is None:
206
+ name = context.lookupname
207
+ if name is None:
208
208
  raise InferenceError()
209
209
  if asname:
210
- yield self.do_import_module(self.real_name(lookupname))
210
+ yield self.do_import_module(self.real_name(name))
211
211
  else:
212
- yield self.do_import_module(lookupname)
212
+ yield self.do_import_module(name)
213
213
  nodes.Import._infer = path_wrapper(infer_import)
214
214
 
215
215
  def infer_name_module(self, name):
216
216
  context = InferenceContext()
217
- return self.infer(context, asname=False, lookupname=name)
217
+ context.lookupname = name
218
+ return self.infer(context, asname=False)
218
219
  nodes.Import.infer_name_module = infer_name_module
219
220
 
220
221
 
221
- def infer_from(self, context=None, asname=True, lookupname=None):
222
+ def infer_from(self, context=None, asname=True):
222
223
  """infer a From nodes: return the imported module/object"""
223
- if lookupname is None:
224
+ name = context.lookupname
225
+ if name is None:
224
226
  raise InferenceError()
225
227
  if asname:
226
- lookupname = self.real_name(lookupname)
228
+ name = self.real_name(name)
227
229
  module = self.do_import_module()
228
230
  try:
229
- return _infer_stmts(module.getattr(lookupname, ignore_locals=module is self.root()), context, lookupname=lookupname)
231
+ context = copy_context(context)
232
+ context.lookupname = name
233
+ return _infer_stmts(module.getattr(name, ignore_locals=module is self.root()), context)
230
234
  except NotFoundError:
231
- raise InferenceError(lookupname)
235
+ raise InferenceError(name)
232
236
  nodes.From._infer = path_wrapper(infer_from)
233
237
 
234
238
 
235
239
  def infer_getattr(self, context=None):
236
240
  """infer a Getattr node by using getattr on the associated object"""
237
- if not context:
238
- context = InferenceContext()
239
241
  for owner in self.expr.infer(context):
240
242
  if owner is YES:
241
243
  yield owner
242
244
  continue
243
245
  try:
244
- with context.scope(boundnode=owner):
245
- for obj in owner.igetattr(self.attrname, context):
246
- yield obj
246
+ context.boundnode = owner
247
+ for obj in owner.igetattr(self.attrname, context):
248
+ yield obj
249
+ context.boundnode = None
247
250
  except (NotFoundError, InferenceError):
248
- pass
251
+ context.boundnode = None
249
252
  except AttributeError:
250
253
  # XXX method / function
251
- pass
254
+ context.boundnode = None
252
255
  nodes.Getattr._infer = path_wrapper(raise_if_nothing_infered(infer_getattr))
253
256
  nodes.AssAttr.infer_lhs = raise_if_nothing_infered(infer_getattr) # # won't work with a path wrapper
254
257
 
255
258
 
256
- def infer_global(self, context=None, lookupname=None):
257
- if lookupname is None:
259
+ def infer_global(self, context=None):
260
+ if context.lookupname is None:
258
261
  raise InferenceError()
259
262
  try:
260
- return _infer_stmts(self.root().getattr(lookupname), context)
263
+ return _infer_stmts(self.root().getattr(context.lookupname), context)
261
264
  except NotFoundError:
262
265
  raise InferenceError()
263
266
  nodes.Global._infer = path_wrapper(infer_global)
@@ -349,10 +352,11 @@ def infer_binop(self, context=None):
349
352
  nodes.BinOp._infer = path_wrapper(infer_binop)
350
353
 
351
354
 
352
- def infer_arguments(self, context=None, lookupname=None):
353
- if lookupname is None:
355
+ def infer_arguments(self, context=None):
356
+ name = context.lookupname
357
+ if name is None:
354
358
  raise InferenceError()
355
- return _arguments_infer_argname(self, lookupname, context)
359
+ return _arguments_infer_argname(self, name, context)
356
360
  nodes.Arguments._infer = infer_arguments
357
361
 
358
362
 
@@ -90,6 +90,7 @@ class AstroidManager(OptionsProviderMixIn):
90
90
  self.transforms = collections.defaultdict(list)
91
91
  self._failed_import_hooks = []
92
92
  self.always_load_extensions = False
93
+ self.optimize_ast = False
93
94
  self.extension_package_whitelist = set()
94
95
 
95
96
  def ast_from_file(self, filepath, modname=None, fallback=True, source=False):
@@ -65,11 +65,11 @@ try:
65
65
  # with the prefix from which the virtualenv was created. This throws
66
66
  # off the detection logic for standard library modules, thus the
67
67
  # workaround.
68
- STD_LIB_DIRS = {
68
+ STD_LIB_DIRS = set([
69
69
  get_python_lib(standard_lib=True, prefix=sys.prefix),
70
70
  # Take care of installations where exec_prefix != prefix.
71
71
  get_python_lib(standard_lib=True, prefix=sys.exec_prefix),
72
- get_python_lib(standard_lib=True)}
72
+ get_python_lib(standard_lib=True)])
73
73
  if os.name == 'nt':
74
74
  STD_LIB_DIRS.add(os.path.join(sys.prefix, 'dlls'))
75
75
  try:
@@ -130,7 +130,8 @@ class LookupMixIn(object):
130
130
  the lookup method
131
131
  """
132
132
  frame, stmts = self.lookup(name)
133
- return _infer_stmts(stmts, None, frame)
133
+ context = InferenceContext()
134
+ return _infer_stmts(stmts, context, frame)
134
135
 
135
136
  def _filter_stmts(self, stmts, frame, offset):
136
137
  """filter statements to remove ignorable statements.
@@ -308,7 +309,7 @@ class Arguments(NodeNG, AssignTypeMixin):
308
309
  @cachedproperty
309
310
  def fromlineno(self):
310
311
  lineno = super(Arguments, self).fromlineno
311
- return max(lineno, self.parent.fromlineno)
312
+ return max(lineno, self.parent.fromlineno or 0)
312
313
 
313
314
  def format_args(self):
314
315
  """return arguments formatted as string"""
@@ -34,6 +34,7 @@ on From and Import :
34
34
 
35
35
 
36
36
  """
37
+ # pylint: disable=unused-import
37
38
 
38
39
  __docformat__ = "restructuredtext en"
39
40
 
@@ -20,10 +20,11 @@ where it makes sense.
20
20
  """
21
21
 
22
22
  __doctype__ = "restructuredtext en"
23
+ import collections
23
24
 
24
25
  from astroid.exceptions import InferenceError, NoDefault, NotFoundError
25
26
  from astroid.node_classes import unpack_infer
26
- from astroid.bases import InferenceContext, \
27
+ from astroid.bases import InferenceContext, copy_context, \
27
28
  raise_if_nothing_infered, yes_if_nothing_infered, Instance, YES
28
29
  from astroid.nodes import const_factory
29
30
  from astroid import nodes
@@ -282,8 +283,7 @@ def _arguments_infer_argname(self, name, context):
282
283
  # if there is a default value, yield it. And then yield YES to reflect
283
284
  # we can't guess given argument value
284
285
  try:
285
- if context is None:
286
- context = InferenceContext()
286
+ context = copy_context(context)
287
287
  for infered in self.default_value(name).infer(context):
288
288
  yield infered
289
289
  yield YES
@@ -295,6 +295,8 @@ def arguments_assigned_stmts(self, node, context, asspath=None):
295
295
  if context.callcontext:
296
296
  # reset call context/name
297
297
  callcontext = context.callcontext
298
+ context = copy_context(context)
299
+ context.callcontext = None
298
300
  return callcontext.infer_argument(self.parent, node.name, context)
299
301
  return _arguments_infer_argname(self, node.name, context)
300
302
  nodes.Arguments.assigned_stmts = arguments_assigned_stmts
@@ -359,3 +361,55 @@ def with_assigned_stmts(self, node, context=None, asspath=None):
359
361
  nodes.With.assigned_stmts = raise_if_nothing_infered(with_assigned_stmts)
360
362
 
361
363
 
364
+ def starred_assigned_stmts(self, node=None, context=None, asspath=None):
365
+ stmt = self.statement()
366
+ if not isinstance(stmt, (nodes.Assign, nodes.For)):
367
+ raise InferenceError()
368
+
369
+ if isinstance(stmt, nodes.Assign):
370
+ value = stmt.value
371
+ lhs = stmt.targets[0]
372
+
373
+ if sum(1 for node in lhs.nodes_of_class(nodes.Starred)) > 1:
374
+ # Too many starred arguments in the expression.
375
+ raise InferenceError()
376
+
377
+ if context is None:
378
+ context = InferenceContext()
379
+ try:
380
+ rhs = next(value.infer(context))
381
+ except InferenceError:
382
+ yield YES
383
+ return
384
+ if rhs is YES or not hasattr(rhs, 'elts'):
385
+ # Not interested in inferred values without elts.
386
+ yield YES
387
+ return
388
+
389
+ elts = collections.deque(rhs.elts[:])
390
+ if len(lhs.elts) > len(rhs.elts):
391
+ # a, *b, c = (1, 2)
392
+ raise InferenceError()
393
+
394
+ # Unpack iteratively the values from the rhs of the assignment,
395
+ # until the find the starred node. What will remain will
396
+ # be the list of values which the Starred node will represent
397
+ # This is done in two steps, from left to right to remove
398
+ # anything before the starred node and from right to left
399
+ # to remvoe anything after the starred node.
400
+
401
+ for index, node in enumerate(lhs.elts):
402
+ if not isinstance(node, nodes.Starred):
403
+ elts.popleft()
404
+ continue
405
+ lhs_elts = collections.deque(reversed(lhs.elts[index:]))
406
+ for node in lhs_elts:
407
+ if not isinstance(node, nodes.Starred):
408
+ elts.pop()
409
+ continue
410
+ # We're done
411
+ for elt in elts:
412
+ yield elt
413
+ break
414
+
415
+ nodes.Starred.assigned_stmts = starred_assigned_stmts
@@ -154,7 +154,7 @@ def object_build_function(node, member, localname):
154
154
  if varkw is not None:
155
155
  args.append(varkw)
156
156
  func = build_function(getattr(member, '__name__', None) or localname, args,
157
- defaults, member.func_code.co_flags, member.__doc__)
157
+ defaults, six.get_function_code(member).co_flags, member.__doc__)
158
158
  node.add_local_node(func, localname)
159
159
 
160
160
  def object_build_datadescriptor(node, member, name):
@@ -23,7 +23,7 @@ import sys
23
23
  from _ast import (
24
24
  Expr as Discard, Str,
25
25
  # binary operators
26
- Add, Div, FloorDiv, Mod, Mult, Pow, Sub, BitAnd, BitOr, BitXor,
26
+ Add, BinOp, Div, FloorDiv, Mod, Mult, Pow, Sub, BitAnd, BitOr, BitXor,
27
27
  LShift, RShift,
28
28
  # logical operators
29
29
  And, Or,
@@ -34,6 +34,7 @@ from _ast import (
34
34
  )
35
35
 
36
36
  from astroid import nodes as new
37
+ from astroid import astpeephole
37
38
 
38
39
 
39
40
  _BIN_OP_CLASSES = {Add: '+',
@@ -136,6 +137,7 @@ class TreeRebuilder(object):
136
137
  self._delayed_assattr = []
137
138
  self._visit_meths = {}
138
139
  self._transform = manager.transform
140
+ self._peepholer = astpeephole.ASTPeepholeOptimizer()
139
141
 
140
142
  def visit_module(self, node, modname, modpath, package):
141
143
  """visit a Module node by returning a fresh instance of it"""
@@ -281,6 +283,24 @@ class TreeRebuilder(object):
281
283
 
282
284
  def visit_binop(self, node, parent):
283
285
  """visit a BinOp node by returning a fresh instance of it"""
286
+ if isinstance(node.left, BinOp) and self._manager.optimize_ast:
287
+ # Optimize BinOp operations in order to remove
288
+ # redundant recursion. For instance, if the
289
+ # following code is parsed in order to obtain
290
+ # its ast, then the rebuilder will fail with an
291
+ # infinite recursion, the same will happen with the
292
+ # inference engine as well. There's no need to hold
293
+ # so many objects for the BinOp if they can be reduced
294
+ # to something else (also, the optimization
295
+ # might handle only Const binops, which isn't a big
296
+ # problem for the correctness of the program).
297
+ #
298
+ # ("a" + "b" + # one thousand more + "c")
299
+ newnode = self._peepholer.optimize_binop(node)
300
+ if newnode:
301
+ _lineno_parent(node, newnode, parent)
302
+ return newnode
303
+
284
304
  newnode = new.BinOp()
285
305
  _lineno_parent(node, newnode, parent)
286
306
  newnode.left = self.visit(node.left, newnode)
@@ -39,8 +39,8 @@ from astroid.exceptions import NotFoundError, \
39
39
  AstroidBuildingException, InferenceError, ResolveError
40
40
  from astroid.node_classes import Const, DelName, DelAttr, \
41
41
  Dict, From, List, Pass, Raise, Return, Tuple, Yield, YieldFrom, \
42
- LookupMixIn, const_factory as cf, unpack_infer, Name, CallFunc
43
- from astroid.bases import NodeNG, InferenceContext, Instance,\
42
+ LookupMixIn, const_factory as cf, unpack_infer, CallFunc
43
+ from astroid.bases import NodeNG, InferenceContext, Instance, copy_context, \
44
44
  YES, Generator, UnboundMethod, BoundMethod, _infer_stmts, \
45
45
  BUILTINS
46
46
  from astroid.mixins import FilterStmtsMixin
@@ -376,10 +376,10 @@ class Module(LocalsDictNodeNG):
376
376
  """inferred getattr"""
377
377
  # set lookup name since this is necessary to infer on import nodes for
378
378
  # instance
379
- if not context:
380
- context = InferenceContext()
379
+ context = copy_context(context)
380
+ context.lookupname = name
381
381
  try:
382
- return _infer_stmts(self.getattr(name, context), context, frame=self, lookupname=name)
382
+ return _infer_stmts(self.getattr(name, context), context, frame=self)
383
383
  except NotFoundError:
384
384
  raise InferenceError(name)
385
385
 
@@ -822,7 +822,8 @@ class Function(Statement, Lambda):
822
822
  c = Class('temporary_class', None)
823
823
  c.hide = True
824
824
  c.parent = self
825
- c.bases = [next(b.infer(context)) for b in caller.args[1:]]
825
+ bases = [next(b.infer(context)) for b in caller.args[1:]]
826
+ c.bases = [base for base in bases if base != YES]
826
827
  c._metaclass = metaclass
827
828
  yield c
828
829
  return
@@ -1036,7 +1037,21 @@ class Class(Statement, LocalsDictNodeNG, FilterStmtsMixin):
1036
1037
  yield Instance(self)
1037
1038
 
1038
1039
  def scope_lookup(self, node, name, offset=0):
1039
- if node in self.bases:
1040
+ if any(node == base or base.parent_of(node)
1041
+ for base in self.bases):
1042
+ # Handle the case where we have either a name
1043
+ # in the bases of a class, which exists before
1044
+ # the actual definition or the case where we have
1045
+ # a Getattr node, with that name.
1046
+ #
1047
+ # name = ...
1048
+ # class A(name):
1049
+ # def name(self): ...
1050
+ #
1051
+ # import name
1052
+ # class A(name.Name):
1053
+ # def name(self): ...
1054
+
1040
1055
  frame = self.parent.frame()
1041
1056
  # line offset to avoid that class A(A) resolve the ancestor to
1042
1057
  # the defined class
@@ -1070,29 +1085,33 @@ class Class(Statement, LocalsDictNodeNG, FilterStmtsMixin):
1070
1085
  return
1071
1086
 
1072
1087
  for stmt in self.bases:
1073
- try:
1074
- for baseobj in stmt.infer(context):
1075
- if not isinstance(baseobj, Class):
1076
- if isinstance(baseobj, Instance):
1077
- baseobj = baseobj._proxied
1078
- else:
1079
- # duh ?
1080
- continue
1081
- if not baseobj.hide:
1082
- if baseobj in yielded:
1083
- continue # cf xxx above
1084
- yielded.add(baseobj)
1085
- yield baseobj
1086
- if recurs:
1087
- for grandpa in baseobj.ancestors(recurs=True,
1088
- context=context):
1089
- if grandpa in yielded:
1088
+ with context.restore_path():
1089
+ try:
1090
+ for baseobj in stmt.infer(context):
1091
+ if not isinstance(baseobj, Class):
1092
+ if isinstance(baseobj, Instance):
1093
+ baseobj = baseobj._proxied
1094
+ else:
1095
+ # duh ?
1096
+ continue
1097
+ if not baseobj.hide:
1098
+ if baseobj in yielded:
1090
1099
  continue # cf xxx above
1091
- yielded.add(grandpa)
1092
- yield grandpa
1093
- except InferenceError:
1094
- # XXX log error ?
1095
- continue
1100
+ yielded.add(baseobj)
1101
+ yield baseobj
1102
+ if recurs:
1103
+ for grandpa in baseobj.ancestors(recurs=True,
1104
+ context=context):
1105
+ if grandpa is self:
1106
+ # This class is the ancestor of itself.
1107
+ break
1108
+ if grandpa in yielded:
1109
+ continue # cf xxx above
1110
+ yielded.add(grandpa)
1111
+ yield grandpa
1112
+ except InferenceError:
1113
+ # XXX log error ?
1114
+ continue
1096
1115
 
1097
1116
  def local_attr_ancestors(self, name, context=None):
1098
1117
  """return an iterator on astroid representation of parent classes
@@ -1187,11 +1206,11 @@ class Class(Statement, LocalsDictNodeNG, FilterStmtsMixin):
1187
1206
  """
1188
1207
  # set lookup name since this is necessary to infer on import nodes for
1189
1208
  # instance
1190
- if not context:
1191
- context = InferenceContext()
1209
+ context = copy_context(context)
1210
+ context.lookupname = name
1192
1211
  try:
1193
1212
  for infered in _infer_stmts(self.getattr(name, context), context,
1194
- frame=self, lookupname=name):
1213
+ frame=self):
1195
1214
  # yield YES object instead of descriptors when necessary
1196
1215
  if not isinstance(infered, Const) and isinstance(infered, Instance):
1197
1216
  try:
@@ -1398,6 +1417,10 @@ class Class(Statement, LocalsDictNodeNG, FilterStmtsMixin):
1398
1417
  Also, it will return None in the case the slots weren't inferred.
1399
1418
  Otherwise, it will return a list of slot names.
1400
1419
  """
1420
+ if not self.newstyle:
1421
+ raise NotImplementedError(
1422
+ "The concept of slots is undefined for old-style classes.")
1423
+
1401
1424
  slots = self._islots()
1402
1425
  try:
1403
1426
  first = next(slots)
@@ -1453,7 +1476,9 @@ class Class(Statement, LocalsDictNodeNG, FilterStmtsMixin):
1453
1476
  "Could not obtain mro for old-style classes.")
1454
1477
 
1455
1478
  bases = list(self._inferred_bases(context=context))
1456
- unmerged_mro = [[self]] + [base.mro() for base in bases] + [bases]
1479
+ unmerged_mro = ([[self]] +
1480
+ [base.mro() for base in bases if base is not self] +
1481
+ [bases])
1457
1482
 
1458
1483
  _verify_duplicates_mro(unmerged_mro)
1459
1484
  return _c3_merge(unmerged_mro)