# Buggy code
def analyze_overloaded_func_def(self, defn: OverloadedFuncDef) -> None:
    # OverloadedFuncDef refers to any legitimate situation where you have
    # more than one declaration for the same function in a row.  This occurs
    # with a @property with a setter or a deleter, and for a classic
    # @overload.

    defn._fullname = self.qualified_name(defn.name())
    # TODO: avoid modifying items.
    defn.items = defn.unanalyzed_items.copy()

    first_item = defn.items[0]
    first_item.is_overload = True
    first_item.accept(self)

    if isinstance(first_item, Decorator) and first_item.func.is_property:
        # This is a property.
        first_item.func.is_overload = True
        self.analyze_property_with_multi_part_definition(defn)
        typ = function_type(first_item.func, self.builtin_type("builtins.function"))
        assert isinstance(typ, CallableType)
        types = [typ]
    else:
        # This is an a normal overload. Find the item signatures, the
        # implementation (if outside a stub), and any missing @overload
        # decorators.
        types, impl, non_overload_indexes = self.analyze_overload_sigs_and_impl(defn)
        defn.impl = impl
        if non_overload_indexes:
            self.handle_missing_overload_decorators(
                defn, non_overload_indexes, some_overload_decorators=len(types) > 0
            )
        # If we found an implementation, remove it from the overload item list,
        # as it's special.
        if impl is not None:
            assert impl is defn.items[-1]
            defn.items = defn.items[:-1]
        elif not non_overload_indexes:
            self.handle_missing_overload_implementation(defn)

    if types:
        defn.type = Overloaded(types)
        defn.type.line = defn.line

    if not defn.items:
        # It was not a real overload after all, but function redefinition. We've
        # visited the redefinition(s) already.
        return

    # We know this is an overload def. Infer properties and perform some checks.
    self.process_final_in_overload(defn)
    self.process_static_or_class_method_in_overload(defn)

    self.add_symbol(defn.name(), defn, defn)


# Traceback (AssertionError)
(tildes) vagrant@ubuntu-xenial:/opt/tildes$ mypy --new-semantic-analyzer --show-traceback test_mypy.py
test_mypy.py:16: error: Cannot assign to a method
test_mypy.py:16: error: INTERNAL ERROR -- Please try using mypy master on Github:
https://mypy.rtfd.io/en/latest/common_issues.html#using-development-mypy-build
Please report a bug at https://github.com/python/mypy/issues
version: 0.720+dev.48916e63403645730a584d6898fbe925d513a841
Traceback (most recent call last):
File "/opt/venvs/tildes/bin/mypy", line 10, in <module>
sys.exit(console_entry())
File "/opt/venvs/tildes/lib/python3.7/site-packages/mypy/__main__.py", line 8, in console_entry
main(None, sys.stdout, sys.stderr)
File "/opt/venvs/tildes/lib/python3.7/site-packages/mypy/main.py", line 83, in main
res = build.build(sources, options, None, flush_errors, fscache, stdout, stderr)
File "/opt/venvs/tildes/lib/python3.7/site-packages/mypy/build.py", line 164, in build
result = _build(sources, options, alt_lib_path, flush_errors, fscache, stdout, stderr)
File "/opt/venvs/tildes/lib/python3.7/site-packages/mypy/build.py", line 224, in _build
graph = dispatch(sources, manager, stdout)
File "/opt/venvs/tildes/lib/python3.7/site-packages/mypy/build.py", line 2567, in dispatch
process_graph(graph, manager)
File "/opt/venvs/tildes/lib/python3.7/site-packages/mypy/build.py", line 2880, in process_graph
process_stale_scc(graph, scc, manager)
File "/opt/venvs/tildes/lib/python3.7/site-packages/mypy/build.py", line 2987, in process_stale_scc
graph[id].type_check_first_pass()
File "/opt/venvs/tildes/lib/python3.7/site-packages/mypy/build.py", line 2096, in type_check_first_pass
self.type_checker().check_first_pass()
File "/opt/venvs/tildes/lib/python3.7/site-packages/mypy/checker.py", line 281, in check_first_pass
self.accept(d)
File "/opt/venvs/tildes/lib/python3.7/site-packages/mypy/checker.py", line 392, in accept
stmt.accept(self)
File "/opt/venvs/tildes/lib/python3.7/site-packages/mypy/nodes.py", line 913, in accept
return visitor.visit_class_def(self)
File "/opt/venvs/tildes/lib/python3.7/site-packages/mypy/checker.py", line 1596, in visit_class_def
self.accept(defn.defs)
File "/opt/venvs/tildes/lib/python3.7/site-packages/mypy/checker.py", line 392, in accept
stmt.accept(self)
File "/opt/venvs/tildes/lib/python3.7/site-packages/mypy/nodes.py", line 978, in accept
return visitor.visit_block(self)
File "/opt/venvs/tildes/lib/python3.7/site-packages/mypy/checker.py", line 1785, in visit_block
self.accept(s)
File "/opt/venvs/tildes/lib/python3.7/site-packages/mypy/checker.py", line 392, in accept
stmt.accept(self)
File "/opt/venvs/tildes/lib/python3.7/site-packages/mypy/nodes.py", line 655, in accept
return visitor.visit_func_def(self)
File "/opt/venvs/tildes/lib/python3.7/site-packages/mypy/checker.py", line 703, in visit_func_def
self._visit_func_def(defn)
File "/opt/venvs/tildes/lib/python3.7/site-packages/mypy/checker.py", line 707, in _visit_func_def
self.check_func_item(defn, name=defn.name())
File "/opt/venvs/tildes/lib/python3.7/site-packages/mypy/checker.py", line 769, in check_func_item
self.check_func_def(defn, typ, name)
File "/opt/venvs/tildes/lib/python3.7/site-packages/mypy/checker.py", line 935, in check_func_def
self.accept(item.body)
File "/opt/venvs/tildes/lib/python3.7/site-packages/mypy/checker.py", line 392, in accept
stmt.accept(self)
File "/opt/venvs/tildes/lib/python3.7/site-packages/mypy/nodes.py", line 978, in accept
return visitor.visit_block(self)
File "/opt/venvs/tildes/lib/python3.7/site-packages/mypy/checker.py", line 1785, in visit_block
self.accept(s)
File "/opt/venvs/tildes/lib/python3.7/site-packages/mypy/checker.py", line 392, in accept
stmt.accept(self)
File "/opt/venvs/tildes/lib/python3.7/site-packages/mypy/nodes.py", line 1036, in accept
return visitor.visit_assignment_stmt(self)
File "/opt/venvs/tildes/lib/python3.7/site-packages/mypy/checker.py", line 1793, in visit_assignment_stmt
self.check_assignment(s.lvalues[-1], s.rvalue, s.type is None, s.new_syntax)
File "/opt/venvs/tildes/lib/python3.7/site-packages/mypy/checker.py", line 1834, in check_assignment
lvalue_type, index_lvalue, inferred = self.check_lvalue(lvalue)
File "/opt/venvs/tildes/lib/python3.7/site-packages/mypy/checker.py", line 2479, in check_lvalue
True)
File "/opt/venvs/tildes/lib/python3.7/site-packages/mypy/checkexpr.py", line 1766, in analyze_ordinary_member_access
in_literal_context=self.is_literal_context())
File "/opt/venvs/tildes/lib/python3.7/site-packages/mypy/checkmember.py", line 103, in analyze_member_access
result = _analyze_member_access(name, typ, mx, override_info)
File "/opt/venvs/tildes/lib/python3.7/site-packages/mypy/checkmember.py", line 117, in _analyze_member_access
return analyze_instance_member_access(name, typ, mx, override_info)
File "/opt/venvs/tildes/lib/python3.7/site-packages/mypy/checkmember.py", line 179, in analyze_instance_member_access
signature = function_type(method, mx.builtin_type('builtins.function'))
File "/opt/venvs/tildes/lib/python3.7/site-packages/mypy/types.py", line 2188, in function_type
assert isinstance(func, mypy.nodes.FuncItem), str(func)
AssertionError: OverloadedFuncDef:7(
Decorator:11(
Var(name)
MemberExpr:11(
NameExpr(name [test_mypy.FirstNameOnly.name])
setter)
FuncDef:12(
name
Args(
Var(self)
Var(value))
def (self: test_mypy.FirstNameOnly, value: builtins.str)
Block:12(
AssignmentStmt:13(
MemberExpr:13(
NameExpr(self [l])
first_name)
NameExpr(value [l]))))))

# Fixed code
def analyze_overloaded_func_def(self, defn: OverloadedFuncDef) -> None:
    # OverloadedFuncDef refers to any legitimate situation where you have
    # more than one declaration for the same function in a row.  This occurs
    # with a @property with a setter or a deleter, and for a classic
    # @overload.

    defn._fullname = self.qualified_name(defn.name())
    # TODO: avoid modifying items.
    defn.items = defn.unanalyzed_items.copy()

    first_item = defn.items[0]
    first_item.is_overload = True
    first_item.accept(self)

    if isinstance(first_item, Decorator) and first_item.func.is_property:
        # This is a property.
        first_item.func.is_overload = True
        self.analyze_property_with_multi_part_definition(defn)
        typ = function_type(first_item.func, self.builtin_type("builtins.function"))
        assert isinstance(typ, CallableType)
        types = [typ]
    else:
        # This is an a normal overload. Find the item signatures, the
        # implementation (if outside a stub), and any missing @overload
        # decorators.
        types, impl, non_overload_indexes = self.analyze_overload_sigs_and_impl(defn)
        defn.impl = impl
        if non_overload_indexes:
            self.handle_missing_overload_decorators(
                defn, non_overload_indexes, some_overload_decorators=len(types) > 0
            )
        # If we found an implementation, remove it from the overload item list,
        # as it's special.
        if impl is not None:
            assert impl is defn.items[-1]
            defn.items = defn.items[:-1]
        elif not non_overload_indexes:
            self.handle_missing_overload_implementation(defn)

    if types:
        defn.type = Overloaded(types)
        defn.type.line = defn.line

    if not defn.items:
        # It was not a real overload after all, but function redefinition. We've
        # visited the redefinition(s) already.
        return

    # We know this is an overload def. Infer properties and perform some checks.
    self.process_final_in_overload(defn)
    self.process_static_or_class_method_in_overload(defn)