Skip to content

Crash when attempting to access a builtin's __code__ #6539

@jacobtylerwalls

Description

@jacobtylerwalls

Bug description

Simplified from an example in cloudpickle, where it was guarded by if PYPY:

Updated to remove the use of a pylint extension.

a = type(float.__new__.__code__)

Configuration

n/a

Command used

pylint a.py

Pylint output

Exception on node <AssignName.a l.1 at 0x10c91c580> in file '/Users/.../pylint/a.py'
Traceback (most recent call last):
  File "/Users/.../astroid/astroid/inference_tip.py", line 37, in _inference_tip_cached
    result = _cache[func, node]
KeyError: (<function register_builtin_transform.<locals>._transform_wrapper at 0x10c339630>, <Call l.1 at 0x10c91c640>)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/.../pylint/pylint/utils/ast_walker.py", line 89, in walk
    callback(astroid)
  File "/Users/.../pylint/pylint/checkers/base/name_checker/checker.py", line 394, in visit_assignname
    inferred_assign_type = utils.safe_infer(assign_type.value)
  File "/Users/.../pylint/pylint/checkers/utils.py", line 1247, in safe_infer
    value = next(infer_gen)
  File "/Users/.../astroid/astroid/nodes/node_ng.py", line 156, in infer
    results = list(self._explicit_inference(self, context, **kwargs))
  File "/Users/.../astroid/astroid/inference_tip.py", line 44, in _inference_tip_cached
    result = _cache[func, node] = list(func(*args, **kwargs))
  File "/Users/.../astroid/astroid/brain/brain_builtin_inference.py", line 172, in _transform_wrapper
    result = transform(node, context=context)
  File "/Users/.../astroid/astroid/brain/brain_builtin_inference.py", line 599, in infer_type
    return helpers.object_type(node.args[0], context)
  File "/Users/.../astroid/astroid/helpers.py", line 73, in object_type
    types = set(_object_type(node, context))
  File "/Users/.../astroid/astroid/helpers.py", line 59, in _object_type
    yield inferred._proxied
AttributeError: 'Unknown' object has no attribute '_proxied'

Expected behavior

no crash

Pylint version

Not caused recently.

pylint 2.14.0-dev0
astroid 2.12.0-dev0
Python 3.10.1 (v3.10.1:2cd268a3a9, Dec  6 2021, 14:28:59) [Clang 13.0.0 (clang-1300.0.29.3)]

OS / Environment

Use s CPython interpreter instead of PyPy so that __code__ is missing:

AttributeError: 'builtin_function_or_method' object has no attribute '__code__'. Did you mean: '__call__'?

Additional dependencies

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    AstroidRelated to astroidCrash 💥A bug that makes pylint crashNeeds astroid updateNeeds an astroid update (probably a release too) before being mergable

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions