Skip to content

Only first __getitem__ inference result is used #1335

Open
@eugene57

Description

@eugene57

Steps to reproduce

import astroid

code = """
class Test:
  def __getitem__(self, key):
    if key == 1:
      return 42
    else:
      return None

x = Test()
result = x[42]  #@
"""

node = astroid.extract_node(code)
x = node.value.inferred()
print(x)

Current behavior

Only int is inferred:

[<Const.int l.5 at 0x7fffe8958640>]

Expected behavior

I expect to see both int and None as possible values.

python -c "from astroid import __pkginfo__; print(__pkginfo__.version)" output

2.7.3

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions