# Buggy code
def try_infer_partial_type_from_indexed_assignment(
    self, lvalue: IndexExpr, rvalue: Node
) -> None:
    # TODO: Should we share some of this with try_infer_partial_type?
    if isinstance(lvalue.base, RefExpr):
        var = cast(Var, lvalue.base.node)
        if var is not None and isinstance(var.type, PartialType):
            type_type = var.type.type
            if type_type is None:
                return  # The partial type is None.
            partial_types = self.find_partial_types(var)
            if partial_types is None:
                return
            typename = type_type.fullname()
            if typename == "builtins.dict":
                # TODO: Don't infer things twice.
                key_type = self.accept(lvalue.index)
                value_type = self.accept(rvalue)
                if is_valid_inferred_type(key_type) and is_valid_inferred_type(
                    value_type
                ):
                    if not self.current_node_deferred:
                        var.type = self.named_generic_type(
                            "builtins.dict", [key_type, value_type]
                        )
                    del partial_types[var]


# Traceback (AttributeError)
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

# Fixed code
def try_infer_partial_type_from_indexed_assignment(
    self, lvalue: IndexExpr, rvalue: Node
) -> None:
    # TODO: Should we share some of this with try_infer_partial_type?
    if isinstance(lvalue.base, RefExpr) and isinstance(lvalue.base.node, Var):
        var = cast(Var, lvalue.base.node)
        if var is not None and isinstance(var.type, PartialType):
            type_type = var.type.type
            if type_type is None:
                return  # The partial type is None.
            partial_types = self.find_partial_types(var)
            if partial_types is None:
                return
            typename = type_type.fullname()
            if typename == "builtins.dict":
                # TODO: Don't infer things twice.
                key_type = self.accept(lvalue.index)
                value_type = self.accept(rvalue)
                if is_valid_inferred_type(key_type) and is_valid_inferred_type(
                    value_type
                ):
                    if not self.current_node_deferred:
                        var.type = self.named_generic_type(
                            "builtins.dict", [key_type, value_type]
                        )
                    del partial_types[var]