Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Internal error on overloaded __getitem__ #1269

Closed
mgeisler opened this issue Mar 4, 2016 · 2 comments
Closed

Internal error on overloaded __getitem__ #1269

mgeisler opened this issue Mar 4, 2016 · 2 comments
Labels
bug mypy got something wrong

Comments

@mgeisler
Copy link

mgeisler commented Mar 4, 2016

I was testing how to make a generic Sequence with an overloaded __getitem__ and had these input files:

# test.py
import overload
c = overload.Container
c[10] = 20
# overload.py
class Container:
    def __getitem__(self, key):
        pass
# overload.pyi
from typing import TypeVar, Generic, Sequence, overload
T = TypeVar('T')

class Container(Generic[T], Sequence[T]):

    @overload
    def __getitem__(self, key: int) -> T: ...

    @overload
    def __getitem__(self, key: slice) -> Sequence[T]: ...

Running mypy test.py produces

Traceback (most recent call last):
  File "/home/mg/.virtualenvs/mypy/bin/mypy", line 6, in <module>
    exec(compile(open(__file__).read(), __file__, 'exec'))
  File "/home/mg/src/mypy/scripts/mypy", line 6, in <module>
    main(__file__)
  File "/home/mg/src/mypy/mypy/main.py", line 50, in main
    type_check_only(sources, bin_dir, options)
  File "/home/mg/src/mypy/mypy/main.py", line 94, in type_check_only
    python_path=options.python_path)
  File "/home/mg/src/mypy/mypy/build.py", line 210, in build
    result = manager.process(initial_states)
  File "/home/mg/src/mypy/mypy/build.py", line 425, in process
    next.process()
  File "/home/mg/src/mypy/mypy/build.py", line 930, in process
    self.type_checker().visit_file(self.tree, self.tree.path)
  File "/home/mg/src/mypy/mypy/checker.py", line 409, in visit_file
    self.accept(d)
  File "/home/mg/src/mypy/mypy/checker.py", line 450, in accept
    typ = node.accept(self)
  File "/home/mg/src/mypy/mypy/nodes.py", line 564, in accept
    return visitor.visit_assignment_stmt(self)
  File "/home/mg/src/mypy/mypy/checker.py", line 1122, in visit_assignment_stmt
    self.check_assignment(s.lvalues[-1], s.rvalue, s.type is None)
  File "/home/mg/src/mypy/mypy/checker.py", line 1167, in check_assignment
    self.check_indexed_assignment(index_lvalue, rvalue, rvalue)
  File "/home/mg/src/mypy/mypy/checker.py", line 1499, in check_indexed_assignment
    self.try_infer_partial_type_from_indexed_assignment(lvalue, rvalue)
  File "/home/mg/src/mypy/mypy/checker.py", line 1513, in try_infer_partial_type_from_indexed_assignment
    if var is not None and isinstance(var.type, PartialType):
AttributeError: 'TypeInfo' object has no attribute 'type'

*** INTERNAL ERROR ***

test.py:4: error: Internal error

Testing some more, I see the same error when I remove the overloaded __getitem__ method and test with

# overload.pyi
from typing import TypeVar, Generic, Sequence
T = TypeVar('T')


class Container(Generic[T], Sequence[T]):
    pass

This is with mypy 0ec0cb4.

@JukkaL JukkaL added the bug mypy got something wrong label Mar 6, 2016
@JukkaL
Copy link
Collaborator

JukkaL commented Mar 6, 2016

Thanks for reporting the bug! I was able to reproduce it using the latest master.

@gvanrossum gvanrossum modified the milestone: 0.3.3 Mar 24, 2016
@gvanrossum
Copy link
Member

gvanrossum commented Apr 27, 2016

One-file repro:

from typing import TypeVar, Generic, Sequence

T = TypeVar('T')

class Container(Sequence[T]):
    pass

Container[10] = 20

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong
Projects
None yet
Development

No branches or pull requests

3 participants