Repository: python/mypy
Pull request: Better error message for assignments and returns incompatible due to invariance
The tests are failing probably because I'm checking  the `INCOMPATIBLE_TYPES_IN_ASSIGNMENT ` not at the right part of this method. 

I also not sure if the type expected by  `append_invariance_notes` that I am passing to it, the `subtype` and the `supertype` because the test that I created work but it do not work for several other tests.

Most of the error are something like: `AttributeError: 'TypeType' object has no attribute 'type'`

Can someone help me with it?

Here are two examples: 
```
__________________________________ testTypeUsingTypeCTypeAnyMember __________________________________
[gw0] darwin -- Python 3.7.3 /Users/felipe/.local/share/virtualenvs/mypy-WvJTD_Lt/bin/python3.7
data: /Users/felipe/projects/python/mypy/test-data/unit/check-classes.test:3018:
SystemExit: 2
--------------------------------------- Captured stdout call ----------------------------------------
main:6: error: Revealed type is 'Any'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "<string>", line 8, in <module>
  File "/Users/felipe/.local/share/virtualenvs/mypy-WvJTD_Lt/lib/python3.7/site-packages/execnet/gateway_base.py", line 1525, in serve
    SlaveGateway(io=io, id=id, _startcount=2).serve()
  File "/Users/felipe/.local/share/virtualenvs/mypy-WvJTD_Lt/lib/python3.7/site-packages/execnet/gateway_base.py", line 1038, in serve
    self._execpool.integrate_as_primary_thread()
  File "/Users/felipe/.local/share/virtualenvs/mypy-WvJTD_Lt/lib/python3.7/site-packages/execnet/gateway_base.py", line 250, in integrate_as_primary_thread
    self._perform_spawn(reply)
  File "/Users/felipe/.local/share/virtualenvs/mypy-WvJTD_Lt/lib/python3.7/site-packages/execnet/gateway_base.py", line 268, in _perform_spawn
    reply.run()
  File "/Users/felipe/.local/share/virtualenvs/mypy-WvJTD_Lt/lib/python3.7/site-packages/execnet/gateway_base.py", line 204, in run
    self._result = func(*args, **kwargs)
  File "/Users/felipe/.local/share/virtualenvs/mypy-WvJTD_Lt/lib/python3.7/site-packages/execnet/gateway_base.py", line 1063, in executetask
    do_exec(co, loc)  # noqa
  File "<string>", line 1, in do_exec
  File "<remote exec>", line 249, in <module>
  File "/Users/felipe/.local/share/virtualenvs/mypy-WvJTD_Lt/lib/python3.7/site-packages/pluggy/hooks.py", line 289, in __call__
    return self._hookexec(self, self.get_hookimpls(), kwargs)
  File "/Users/felipe/.local/share/virtualenvs/mypy-WvJTD_Lt/lib/python3.7/site-packages/pluggy/manager.py", line 87, in _hookexec
    return self._inner_hookexec(hook, methods, kwargs)
  File "/Users/felipe/.local/share/virtualenvs/mypy-WvJTD_Lt/lib/python3.7/site-packages/pluggy/manager.py", line 81, in <lambda>
    firstresult=hook.spec.opts.get("firstresult") if hook.spec else False,
  File "/Users/felipe/.local/share/virtualenvs/mypy-WvJTD_Lt/lib/python3.7/site-packages/pluggy/callers.py", line 187, in _multicall
    res = hook_impl.function(*args)
  File "/Users/felipe/.local/share/virtualenvs/mypy-WvJTD_Lt/lib/python3.7/site-packages/_pytest/main.py", line 242, in pytest_cmdline_main
    return wrap_session(config, _main)
  File "/Users/felipe/.local/share/virtualenvs/mypy-WvJTD_Lt/lib/python3.7/site-packages/_pytest/main.py", line 209, in wrap_session
    session.exitstatus = doit(config, session) or 0
  File "/Users/felipe/.local/share/virtualenvs/mypy-WvJTD_Lt/lib/python3.7/site-packages/_pytest/main.py", line 249, in _main
    config.hook.pytest_runtestloop(session=session)
  File "/Users/felipe/.local/share/virtualenvs/mypy-WvJTD_Lt/lib/python3.7/site-packages/pluggy/hooks.py", line 289, in __call__
    return self._hookexec(self, self.get_hookimpls(), kwargs)
  File "/Users/felipe/.local/share/virtualenvs/mypy-WvJTD_Lt/lib/python3.7/site-packages/pluggy/manager.py", line 87, in _hookexec
    return self._inner_hookexec(hook, methods, kwargs)
  File "/Users/felipe/.local/share/virtualenvs/mypy-WvJTD_Lt/lib/python3.7/site-packages/pluggy/manager.py", line 81, in <lambda>
    firstresult=hook.spec.opts.get("firstresult") if hook.spec else False,
  File "/Users/felipe/.local/share/virtualenvs/mypy-WvJTD_Lt/lib/python3.7/site-packages/pluggy/callers.py", line 187, in _multicall
    res = hook_impl.function(*args)
  File "<remote exec>", line 67, in pytest_runtestloop
  File "<remote exec>", line 84, in run_one_test
  File "/Users/felipe/.local/share/virtualenvs/mypy-WvJTD_Lt/lib/python3.7/site-packages/pluggy/hooks.py", line 289, in __call__
    return self._hookexec(self, self.get_hookimpls(), kwargs)
  File "/Users/felipe/.local/share/virtualenvs/mypy-WvJTD_Lt/lib/python3.7/site-packages/pluggy/manager.py", line 87, in _hookexec
    return self._inner_hookexec(hook, methods, kwargs)
  File "/Users/felipe/.local/share/virtualenvs/mypy-WvJTD_Lt/lib/python3.7/site-packages/pluggy/manager.py", line 81, in <lambda>
    firstresult=hook.spec.opts.get("firstresult") if hook.spec else False,
  File "/Users/felipe/.local/share/virtualenvs/mypy-WvJTD_Lt/lib/python3.7/site-packages/pluggy/callers.py", line 187, in _multicall
    res = hook_impl.function(*args)
  File "/Users/felipe/.local/share/virtualenvs/mypy-WvJTD_Lt/lib/python3.7/site-packages/_pytest/runner.py", line 78, in pytest_runtest_protocol
    runtestprotocol(item, nextitem=nextitem)
  File "/Users/felipe/.local/share/virtualenvs/mypy-WvJTD_Lt/lib/python3.7/site-packages/_pytest/runner.py", line 93, in runtestprotocol
    reports.append(call_and_report(item, "call", log))
  File "/Users/felipe/.local/share/virtualenvs/mypy-WvJTD_Lt/lib/python3.7/site-packages/_pytest/runner.py", line 173, in call_and_report
    call = call_runtest_hook(item, when, **kwds)
  File "/Users/felipe/.local/share/virtualenvs/mypy-WvJTD_Lt/lib/python3.7/site-packages/_pytest/runner.py", line 198, in call_runtest_hook
    lambda: ihook(item=item, **kwds), when=when, reraise=reraise
  File "/Users/felipe/.local/share/virtualenvs/mypy-WvJTD_Lt/lib/python3.7/site-packages/_pytest/runner.py", line 226, in from_call
    result = func()
  File "/Users/felipe/.local/share/virtualenvs/mypy-WvJTD_Lt/lib/python3.7/site-packages/_pytest/runner.py", line 198, in <lambda>
    lambda: ihook(item=item, **kwds), when=when, reraise=reraise
  File "/Users/felipe/.local/share/virtualenvs/mypy-WvJTD_Lt/lib/python3.7/site-packages/pluggy/hooks.py", line 289, in __call__
    return self._hookexec(self, self.get_hookimpls(), kwargs)
  File "/Users/felipe/.local/share/virtualenvs/mypy-WvJTD_Lt/lib/python3.7/site-packages/pluggy/manager.py", line 87, in _hookexec
    return self._inner_hookexec(hook, methods, kwargs)
  File "/Users/felipe/.local/share/virtualenvs/mypy-WvJTD_Lt/lib/python3.7/site-packages/pluggy/manager.py", line 81, in <lambda>
    firstresult=hook.spec.opts.get("firstresult") if hook.spec else False,
  File "/Users/felipe/.local/share/virtualenvs/mypy-WvJTD_Lt/lib/python3.7/site-packages/pluggy/callers.py", line 187, in _multicall
    res = hook_impl.function(*args)
  File "/Users/felipe/.local/share/virtualenvs/mypy-WvJTD_Lt/lib/python3.7/site-packages/_pytest/runner.py", line 123, in pytest_runtest_call
    item.runtest()
  File "/Users/felipe/projects/python/mypy/mypy/test/data.py", line 223, in runtest
    suite.run_case(self)
  File "/Users/felipe/projects/python/mypy/mypy/test/testcheck.py", line 123, in run_case
    self.run_case_once(testcase)
  File "/Users/felipe/projects/python/mypy/mypy/test/testcheck.py", line 185, in run_case_once
    alt_lib_path=test_temp_dir)
  File "/Users/felipe/projects/python/mypy/mypy/build.py", line 164, in build
    result = _build(sources, options, alt_lib_path, flush_errors, fscache)
  File "/Users/felipe/projects/python/mypy/mypy/build.py", line 220, in _build
    graph = dispatch(sources, manager)
  File "/Users/felipe/projects/python/mypy/mypy/build.py", line 2490, in dispatch
    process_graph(graph, manager)
  File "/Users/felipe/projects/python/mypy/mypy/build.py", line 2802, in process_graph
    process_stale_scc(graph, scc, manager)
  File "/Users/felipe/projects/python/mypy/mypy/build.py", line 2909, in process_stale_scc
    graph[id].type_check_first_pass()
  File "/Users/felipe/projects/python/mypy/mypy/build.py", line 2022, in type_check_first_pass
    self.type_checker().check_first_pass()
  File "/Users/felipe/projects/python/mypy/mypy/checker.py", line 284, in check_first_pass
    self.accept(d)
  File "/Users/felipe/projects/python/mypy/mypy/checker.py", line 395, in accept
    stmt.accept(self)
  File "/Users/felipe/projects/python/mypy/mypy/nodes.py", line 655, in accept
    return visitor.visit_func_def(self)
  File "/Users/felipe/projects/python/mypy/mypy/checker.py", line 706, in visit_func_def
    self._visit_func_def(defn)
  File "/Users/felipe/projects/python/mypy/mypy/checker.py", line 710, in _visit_func_def
    self.check_func_item(defn, name=defn.name())
  File "/Users/felipe/projects/python/mypy/mypy/checker.py", line 772, in check_func_item
    self.check_func_def(defn, typ, name)
  File "/Users/felipe/projects/python/mypy/mypy/checker.py", line 938, in check_func_def
    self.accept(item.body)
  File "/Users/felipe/projects/python/mypy/mypy/checker.py", line 395, in accept
    stmt.accept(self)
  File "/Users/felipe/projects/python/mypy/mypy/nodes.py", line 978, in accept
    return visitor.visit_block(self)
  File "/Users/felipe/projects/python/mypy/mypy/checker.py", line 1769, in visit_block
    self.accept(s)
  File "/Users/felipe/projects/python/mypy/mypy/checker.py", line 395, in accept
    stmt.accept(self)
  File "/Users/felipe/projects/python/mypy/mypy/nodes.py", line 1036, in accept
    return visitor.visit_assignment_stmt(self)
  File "/Users/felipe/projects/python/mypy/mypy/checker.py", line 1777, in visit_assignment_stmt
    self.check_assignment(s.lvalues[-1], s.rvalue, s.type is None, s.new_syntax)
  File "/Users/felipe/projects/python/mypy/mypy/checker.py", line 1879, in check_assignment
    rvalue_type = self.check_simple_assignment(lvalue_type, rvalue, lvalue)
  File "/Users/felipe/projects/python/mypy/mypy/checker.py", line 2582, in check_simple_assignment
    '{} has type'.format(lvalue_name))
  File "/Users/felipe/projects/python/mypy/mypy/checker.py", line 3566, in check_subtype
    notes = append_invariance_notes([], subtype,  supertype)
  File "/Users/felipe/projects/python/mypy/mypy/messages.py", line 1612, in append_invariance_notes
    if (arg_type.type.fullname() == 'builtins.list' and
AttributeError: 'TypeType' object has no attribute 'type'
--------------------------------------- Captured stderr call ----------------------------------------
main:8: error: INTERNAL ERROR -- please report a bug at https://github.com/python/mypy/issues version: 0.710+dev.a55d2ad3266c8357d22c8cae1545e815949f2225
main:8: : note: use --pdb to drop into pdb
_________________________________ testInstanceMethodOverwriteError __________________________________
[gw1] darwin -- Python 3.7.3 /Users/felipe/.local/share/virtualenvs/mypy-WvJTD_Lt/bin/python3.7
data: /Users/felipe/projects/python/mypy/test-data/unit/check-classes.test:3860:
SystemExit: 2
--------------------------------------- Captured stdout call ----------------------------------------
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "<string>", line 8, in <module>
  File "/Users/felipe/.local/share/virtualenvs/mypy-WvJTD_Lt/lib/python3.7/site-packages/execnet/gateway_base.py", line 1525, in serve
    SlaveGateway(io=io, id=id, _startcount=2).serve()
  File "/Users/felipe/.local/share/virtualenvs/mypy-WvJTD_Lt/lib/python3.7/site-packages/execnet/gateway_base.py", line 1038, in serve
    self._execpool.integrate_as_primary_thread()
  File "/Users/felipe/.local/share/virtualenvs/mypy-WvJTD_Lt/lib/python3.7/site-packages/execnet/gateway_base.py", line 250, in integrate_as_primary_thread
    self._perform_spawn(reply)
  File "/Users/felipe/.local/share/virtualenvs/mypy-WvJTD_Lt/lib/python3.7/site-packages/execnet/gateway_base.py", line 268, in _perform_spawn
    reply.run()
  File "/Users/felipe/.local/share/virtualenvs/mypy-WvJTD_Lt/lib/python3.7/site-packages/execnet/gateway_base.py", line 204, in run
    self._result = func(*args, **kwargs)
  File "/Users/felipe/.local/share/virtualenvs/mypy-WvJTD_Lt/lib/python3.7/site-packages/execnet/gateway_base.py", line 1063, in executetask
    do_exec(co, loc)  # noqa
  File "<string>", line 1, in do_exec
  File "<remote exec>", line 249, in <module>
  File "/Users/felipe/.local/share/virtualenvs/mypy-WvJTD_Lt/lib/python3.7/site-packages/pluggy/hooks.py", line 289, in __call__
    return self._hookexec(self, self.get_hookimpls(), kwargs)
  File "/Users/felipe/.local/share/virtualenvs/mypy-WvJTD_Lt/lib/python3.7/site-packages/pluggy/manager.py", line 87, in _hookexec
    return self._inner_hookexec(hook, methods, kwargs)
  File "/Users/felipe/.local/share/virtualenvs/mypy-WvJTD_Lt/lib/python3.7/site-packages/pluggy/manager.py", line 81, in <lambda>
    firstresult=hook.spec.opts.get("firstresult") if hook.spec else False,
  File "/Users/felipe/.local/share/virtualenvs/mypy-WvJTD_Lt/lib/python3.7/site-packages/pluggy/callers.py", line 187, in _multicall
    res = hook_impl.function(*args)
  File "/Users/felipe/.local/share/virtualenvs/mypy-WvJTD_Lt/lib/python3.7/site-packages/_pytest/main.py", line 242, in pytest_cmdline_main
    return wrap_session(config, _main)
  File "/Users/felipe/.local/share/virtualenvs/mypy-WvJTD_Lt/lib/python3.7/site-packages/_pytest/main.py", line 209, in wrap_session
    session.exitstatus = doit(config, session) or 0
  File "/Users/felipe/.local/share/virtualenvs/mypy-WvJTD_Lt/lib/python3.7/site-packages/_pytest/main.py", line 249, in _main
    config.hook.pytest_runtestloop(session=session)
  File "/Users/felipe/.local/share/virtualenvs/mypy-WvJTD_Lt/lib/python3.7/site-packages/pluggy/hooks.py", line 289, in __call__
    return self._hookexec(self, self.get_hookimpls(), kwargs)
  File "/Users/felipe/.local/share/virtualenvs/mypy-WvJTD_Lt/lib/python3.7/site-packages/pluggy/manager.py", line 87, in _hookexec
    return self._inner_hookexec(hook, methods, kwargs)
  File "/Users/felipe/.local/share/virtualenvs/mypy-WvJTD_Lt/lib/python3.7/site-packages/pluggy/manager.py", line 81, in <lambda>
    firstresult=hook.spec.opts.get("firstresult") if hook.spec else False,
  File "/Users/felipe/.local/share/virtualenvs/mypy-WvJTD_Lt/lib/python3.7/site-packages/pluggy/callers.py", line 187, in _multicall
    res = hook_impl.function(*args)
  File "<remote exec>", line 67, in pytest_runtestloop
  File "<remote exec>", line 84, in run_one_test
  File "/Users/felipe/.local/share/virtualenvs/mypy-WvJTD_Lt/lib/python3.7/site-packages/pluggy/hooks.py", line 289, in __call__
    return self._hookexec(self, self.get_hookimpls(), kwargs)
  File "/Users/felipe/.local/share/virtualenvs/mypy-WvJTD_Lt/lib/python3.7/site-packages/pluggy/manager.py", line 87, in _hookexec
    return self._inner_hookexec(hook, methods, kwargs)
  File "/Users/felipe/.local/share/virtualenvs/mypy-WvJTD_Lt/lib/python3.7/site-packages/pluggy/manager.py", line 81, in <lambda>
    firstresult=hook.spec.opts.get("firstresult") if hook.spec else False,
  File "/Users/felipe/.local/share/virtualenvs/mypy-WvJTD_Lt/lib/python3.7/site-packages/pluggy/callers.py", line 187, in _multicall
    res = hook_impl.function(*args)
  File "/Users/felipe/.local/share/virtualenvs/mypy-WvJTD_Lt/lib/python3.7/site-packages/_pytest/runner.py", line 78, in pytest_runtest_protocol
    runtestprotocol(item, nextitem=nextitem)
  File "/Users/felipe/.local/share/virtualenvs/mypy-WvJTD_Lt/lib/python3.7/site-packages/_pytest/runner.py", line 93, in runtestprotocol
    reports.append(call_and_report(item, "call", log))
  File "/Users/felipe/.local/share/virtualenvs/mypy-WvJTD_Lt/lib/python3.7/site-packages/_pytest/runner.py", line 173, in call_and_report
    call = call_runtest_hook(item, when, **kwds)
  File "/Users/felipe/.local/share/virtualenvs/mypy-WvJTD_Lt/lib/python3.7/site-packages/_pytest/runner.py", line 198, in call_runtest_hook
    lambda: ihook(item=item, **kwds), when=when, reraise=reraise
  File "/Users/felipe/.local/share/virtualenvs/mypy-WvJTD_Lt/lib/python3.7/site-packages/_pytest/runner.py", line 226, in from_call
    result = func()
  File "/Users/felipe/.local/share/virtualenvs/mypy-WvJTD_Lt/lib/python3.7/site-packages/_pytest/runner.py", line 198, in <lambda>
    lambda: ihook(item=item, **kwds), when=when, reraise=reraise
  File "/Users/felipe/.local/share/virtualenvs/mypy-WvJTD_Lt/lib/python3.7/site-packages/pluggy/hooks.py", line 289, in __call__
    return self._hookexec(self, self.get_hookimpls(), kwargs)
  File "/Users/felipe/.local/share/virtualenvs/mypy-WvJTD_Lt/lib/python3.7/site-packages/pluggy/manager.py", line 87, in _hookexec
    return self._inner_hookexec(hook, methods, kwargs)
  File "/Users/felipe/.local/share/virtualenvs/mypy-WvJTD_Lt/lib/python3.7/site-packages/pluggy/manager.py", line 81, in <lambda>
    firstresult=hook.spec.opts.get("firstresult") if hook.spec else False,
  File "/Users/felipe/.local/share/virtualenvs/mypy-WvJTD_Lt/lib/python3.7/site-packages/pluggy/callers.py", line 187, in _multicall
    res = hook_impl.function(*args)
  File "/Users/felipe/.local/share/virtualenvs/mypy-WvJTD_Lt/lib/python3.7/site-packages/_pytest/runner.py", line 123, in pytest_runtest_call
    item.runtest()
  File "/Users/felipe/projects/python/mypy/mypy/test/data.py", line 223, in runtest
    suite.run_case(self)
  File "/Users/felipe/projects/python/mypy/mypy/test/testcheck.py", line 123, in run_case
    self.run_case_once(testcase)
  File "/Users/felipe/projects/python/mypy/mypy/test/testcheck.py", line 185, in run_case_once
    alt_lib_path=test_temp_dir)
  File "/Users/felipe/projects/python/mypy/mypy/build.py", line 164, in build
    result = _build(sources, options, alt_lib_path, flush_errors, fscache)
  File "/Users/felipe/projects/python/mypy/mypy/build.py", line 220, in _build
    graph = dispatch(sources, manager)
  File "/Users/felipe/projects/python/mypy/mypy/build.py", line 2490, in dispatch
    process_graph(graph, manager)
  File "/Users/felipe/projects/python/mypy/mypy/build.py", line 2802, in process_graph
    process_stale_scc(graph, scc, manager)
  File "/Users/felipe/projects/python/mypy/mypy/build.py", line 2909, in process_stale_scc
    graph[id].type_check_first_pass()
  File "/Users/felipe/projects/python/mypy/mypy/build.py", line 2022, in type_check_first_pass
    self.type_checker().check_first_pass()
  File "/Users/felipe/projects/python/mypy/mypy/checker.py", line 284, in check_first_pass
    self.accept(d)
  File "/Users/felipe/projects/python/mypy/mypy/checker.py", line 395, in accept
    stmt.accept(self)
  File "/Users/felipe/projects/python/mypy/mypy/nodes.py", line 913, in accept
    return visitor.visit_class_def(self)
  File "/Users/felipe/projects/python/mypy/mypy/checker.py", line 1582, in visit_class_def
    self.accept(defn.defs)
  File "/Users/felipe/projects/python/mypy/mypy/checker.py", line 395, in accept
    stmt.accept(self)
  File "/Users/felipe/projects/python/mypy/mypy/nodes.py", line 978, in accept
    return visitor.visit_block(self)
  File "/Users/felipe/projects/python/mypy/mypy/checker.py", line 1769, in visit_block
    self.accept(s)
  File "/Users/felipe/projects/python/mypy/mypy/checker.py", line 395, in accept
    stmt.accept(self)
  File "/Users/felipe/projects/python/mypy/mypy/nodes.py", line 1036, in accept
    return visitor.visit_assignment_stmt(self)
  File "/Users/felipe/projects/python/mypy/mypy/checker.py", line 1777, in visit_assignment_stmt
    self.check_assignment(s.lvalues[-1], s.rvalue, s.type is None, s.new_syntax)
  File "/Users/felipe/projects/python/mypy/mypy/checker.py", line 1837, in check_assignment
    if self.check_compatibility_all_supers(lvalue, lvalue_type, rvalue):
  File "/Users/felipe/projects/python/mypy/mypy/checker.py", line 1951, in check_compatibility_all_supers
    base_node):
  File "/Users/felipe/projects/python/mypy/mypy/checker.py", line 2012, in check_compatibility_super
    'base class "%s" defined the type as' % base.name())
  File "/Users/felipe/projects/python/mypy/mypy/checker.py", line 3566, in check_subtype
    notes = append_invariance_notes([], subtype,  supertype)
  File "/Users/felipe/projects/python/mypy/mypy/messages.py", line 1612, in append_invariance_notes
    if (arg_type.type.fullname() == 'builtins.list' and
AttributeError: 'CallableType' object has no attribute 'type'
--------------------------------------- Captured stderr call ----------------------------------------
main:5: error: INTERNAL ERROR -- please report a bug at https://github.com/python/mypy/issues version: 0.710+dev.a55d2ad3266c8357d22c8cae1545e815949f2225
main:5: : note: use --pdb to drop into pdb
 ```

Fixes: https://github.com/python/mypy/issues/4186

Problem statement:
Better error message for assignments incompatible due to invariance
There seems to be a problem with enums when inferred and used inside lists. This happens with both mypy 0.540 and mypy 0.520.

Code:

```python
class Magic(Enum):
    ISSUER = 1
    ISSUER_EXCHANGE = 2
    ASSIGNEE = 3
    ALL = 3

boo = [c for c in Magic if c not in [Magic.ISSUER]]
boo_explicit: List[Enum] = [c for c in Magic if c not in [Magic.ISSUER]]
spam1: Dict[str, List[Enum]] = {'abc': boo} # Fails with: Dict entry 0 has incompatible type "str": "List[Magic]"; expected "str": "List[Enum]"
spam2: Dict[str, List[Enum]] = {'abc': boo_explicit} # works when typed explicitly
spam3: Dict[str, List[Enum]] = {'abc': [Magic.ISSUER]} # works when done inline
spam4: Dict[str, List[Enum]] = {'abc': [c for c in Magic if c not in [Magic.ISSUER]]} # works when done inline, even with a list comp.
spam5: Dict[str, Enum] = {'abc': Magic.ISSUER} # works Works for single enums.
```

Let me know what other info you need, or any other steps I should take.

Thanks for all the work on such an awesome project.

Hints from issue discussion:
This is not related to enums and I don't think it's a bug; it's because of invariance. Because the `List` type is invariant, `List[B]` is not allowed for `List[A]` when `B` is a subclass of `A`. As your examples, show mypy uses special logic to infer `List[A]` instead of `List[B]` in some cases.
This is not a bug, ``List`` is invariant. It is however strange that you didn't get a note explaining this. Also the bug is that you _don't_ get an error on the comprehension line, see https://github.com/python/mypy/issues/3210

I am keeping this open so that we can give a better error message, for some reasons it does not work with enums.
OK, the problem is that we give the better error message only for incompatible arguments, not in assignments. This is therefore easy to fix.
I taking a look at this.

Commit message: Fix the test for List variants error with more information

Patch to review:
diff --git a/mypy/checker.py b/mypy/checker.py
index e25368a19d0c..d625ae85f250 100644
--- a/mypy/checker.py
+++ b/mypy/checker.py
@@ -36,7 +36,7 @@
     is_optional, remove_optional
 )
 from mypy.sametypes import is_same_type
-from mypy.messages import MessageBuilder, make_inferred_type_note
+from mypy.messages import MessageBuilder, make_inferred_type_note, append_invariance_notes
 import mypy.checkexpr
 from mypy.checkmember import (
     map_type_from_supertype, bind_self, erase_to_bound, type_object_type,
@@ -3569,6 +3569,7 @@ def check_subtype(self, subtype: Type, supertype: Type, context: Context,
                 return False
             extra_info = []  # type: List[str]
             note_msg = ''
+            notes = []
             if subtype_label is not None or supertype_label is not None:
                 subtype_str, supertype_str = self.msg.format_distinctly(subtype, supertype)
                 if subtype_label is not None:
@@ -3577,9 +3578,14 @@ def check_subtype(self, subtype: Type, supertype: Type, context: Context,
                     extra_info.append(supertype_label + ' ' + supertype_str)
                 note_msg = make_inferred_type_note(context, subtype,
                                                    supertype, supertype_str)
+                if msg == message_registry.INCOMPATIBLE_TYPES_IN_ASSIGNMENT:
+                    notes = append_invariance_notes([], subtype,  supertype)
             if extra_info:
                 msg += ' (' + ', '.join(extra_info) + ')'
             self.fail(msg, context)
+            if notes:
+                for note in notes:
+                    self.msg.note(note, context)
             if note_msg:
                 self.note(note_msg, context)
             if (isinstance(supertype, Instance) and supertype.type.is_protocol and
diff --git a/test-data/unit/check-basic.test b/test-data/unit/check-basic.test
index 629d6bf291d2..e362a4850d14 100644
--- a/test-data/unit/check-basic.test
+++ b/test-data/unit/check-basic.test
@@ -372,3 +372,12 @@ none = None
 b = none.__bool__()
 reveal_type(b)  # E: Revealed type is 'builtins.bool'
 [builtins fixtures/bool.pyi]
+
+[case testAssignmentInvariantNote]
+from typing import List
+x: List[int]
+y: List[float]
+y = x # E: Incompatible types in assignment (expression has type "List[int]", variable has type "List[float]") \
+     # N: "List" is invariant -- see http://mypy.readthedocs.io/en/latest/common_issues.html#variance \
+     # N: Consider using "Sequence" instead, which is covariant
+[builtins fixtures/list.pyi]


Code review comments:
diff_hunk: @@ -3577,9 +3578,14 @@ def check_subtype(self, subtype: Type, supertype: Type, context: Context,
                     extra_info.append(supertype_label + ' ' + supertype_str)
                 note_msg = make_inferred_type_note(context, subtype,
                                                    supertype, supertype_str)
+                if msg == message_registry.INCOMPATIBLE_TYPES_IN_ASSIGNMENT:
+                    notes = append_invariance_notes([], subtype,  supertype)
path: mypy/checker.py
text: @user1:
You need to do this _only_ if `isinstance(subtype, Instance)` and `isinstance(supertype, Instance)`, see the signature of `append_invariance_notes`. By the way this error would be caught statically by mypy during self-check. To run it use `python runtests.py self`.

@user1:
Please note that you didn't address this issue, which is probably most important one since it causes all your test failures.

@author:
I'm fixing it. I'm trying to have a deeper understanding so I can understand why and not just. I want to be able to under better the project and contribute more often.

@author:
Now I have just one test failing called `testCoberturaParser`

```
(mypy) ➜  mypy git:(better-error-message-for-assignments-incompatible-due-to-invariance) ✗ pytest --ff
=========================================================================================== test session starts ============================================================================================
platform darwin -- Python 3.7.3, pytest-4.4.1, py-1.8.0, pluggy-0.10.0
rootdir: /Users/felipe/projects/python/mypy, inifile: pytest.ini, testpaths: mypy/test
plugins: forked-1.0.2, xdist-1.28.0, cov-2.7.1
gw0 [7577] / gw1 [7577] / gw2 [7577] / gw3 [7577]
...........................s........................................................................................................................................................................ [  2%]
.................................................................................................................................................................................................... [  5%]
.................................................................................................................................................................................................... [  7%]
.......................................................................................................s............................................................................................ [ 10%]
........................................s.....................................................................s..................................................................s.................. [ 12%]
.................................................................................................................................................................................................... [ 15%]
.....................................................................s....................................................................................................s......................... [ 18%]
...............................................................................................................................................................................s.................... [ 20%]
..........................................s.................................................s........................................................................................................ [ 23%]
.............................................................s...............................ss.s.........................................s......................................................... [ 25%]
............................................................s....................................................................................................................................... [ 28%]
..................................................................................................................................................................................................... [ 30%]
..................................................................................................................................................................................................... [ 33%]
.................................................................................................................................................................................................... [ 36%]
.................................................................................................................................................................................................... [ 38%]
.................................................................................................................................................................................................... [ 41%]
.................................................................................................................................................................................................s.. [ 43%]
...........s........................................................................................................................................................................................ [ 46%]
...........................s...........................................................s........................................................................s................................... [ 48%]
...................s.........................................................................................................ss..................................................................... [ 51%]
..................................................................................................................s................................................................................. [ 54%]
...............................................................................................................................................................................s.................... [ 56%]
.........................................................................s.....................s......................s............................................................................. [ 59%]
...................sss.sssss................................................................................................s................................................s...................... [ 61%]
......................................................................s.................s...................s.......sss.......s....s.......s.........s...................s...sss.s................s. [ 64%]
.....s............................s........s...........s........................s.ss.................sss......sssssssss.....................sss..s....ss......ss.s.s........s.s.....s....s...ss..... [ 66%]
s.s.....ss..................................s................s......s..............s.................ssss.....sss....sssssss......s...s...s.................................s....................... [ 69%]
...................................sss.ss.....................................s.s................................................................................................................... [ 72%]
............s........s..............................s................................................................sss..........................................................s.....s...ssssssss [ 74%]
s.sssssss.s.ssssssssss.ss......................................................................................................s..s......................................s..s...s.ss.s.............. [ 77%]
....s.s.....s.....s..s.sss.........s...ssss.s.ss.....ss............................................................................................................................................. [ 79%]
.................................................................................................................................................................................................... [ 82%]
.................................................................................................................................................................................................... [ 84%]
.................................................................................................................................................................................................... [ 87%]
.................................................................................................................................................................................................... [ 89%]
..................................................................................................................................................................................s................. [ 92%]
..............................................................................s....sss..........................s.....................................s............................................. [ 95%]
...............................s...........................................................F........................................................................................................ [ 97%]
............................................................................s.................................................
============================================= FAILURES ==============================================
________________________________________ testCoberturaParser ________________________________________
[gw2] darwin -- Python 3.7.3 /Users/felipe/.local/share/virtualenvs/mypy-WvJTD_Lt/bin/python3.7
data: /Users/felipe/projects/python/mypy/test-data/unit/reports.test:17:
/Users/felipe/projects/python/mypy/mypy/test/testcmdline.py:36: in run_case
    test_python_cmdline(testcase, step)
/Users/felipe/projects/python/mypy/mypy/test/testcmdline.py:100: in test_python_cmdline
    path, ' on step %d' % step if testcase.output2 else ''))
/Users/felipe/projects/python/mypy/mypy/test/helpers.py:115: in assert_string_arrays_equal
    raise AssertionError(msg)
E   AssertionError: Output file tmp/build/cobertura.xml did not match its expected output
--------------------------------------- Captured stderr call ----------------------------------------
Expected:
  <coverage timestamp="$TIMESTAMP" version="$VERSION" line-rate="0.8000" branch-rate="0"> (diff)
    <sources>
      <source>$PWD</source>
    </sources>
    <packages>
  ...
Actual:
  <coverage timestamp="$TIMESTAMP" version="$VERSION.62a6c672c8545399e7f3dec328b5a910e1dc5f26" line-rate="0.8000" branch-rate="0"> (diff)
    <sources>
      <source>$PWD</source>
    </sources>
    <packages>
  ...

Alignment of first line difference:
  E: ...P" version="$VERSION" line-rate="0.8000" branch-rate="0">...
  A: ...P" version="$VERSION.62a6c672c8545399e7f3dec328b5a910e1dc5f26" line-r...
                            ^
========================================= warnings summary ==========================================
main:2
  main:2: DeprecationWarning: invalid escape sequence \u

main:1
  main:1: DeprecationWarning: <> not supported in 3.x; use !=

-- Docs: https://docs.pytest.org/en/latest/warnings.html
================= 1 failed, 7381 passed, 195 skipped, 2 warnings in 617.66 seconds ==================
```

@user1:
This is not a real failure (for example you don't see it in CI), this is just because you made a commit while test was running. The only failure is currently failing flake8 linter (run `python runtests.py lint` to run locally).

@author:
Thank you. I fixed the flake8 error.

diff_hunk: @@ -3577,9 +3578,14 @@ def check_subtype(self, subtype: Type, supertype: Type, context: Context,
                     extra_info.append(supertype_label + ' ' + supertype_str)
                 note_msg = make_inferred_type_note(context, subtype,
                                                    supertype, supertype_str)
+                if msg == message_registry.INCOMPATIBLE_TYPES_IN_ASSIGNMENT:
+                    notes = append_invariance_notes([], subtype,  supertype)
             if extra_info:
                 msg += ' (' + ', '.join(extra_info) + ')'
             self.fail(msg, context)
+            if notes:
path: mypy/checker.py
text: @user1:
This `if` is redundant. If the list is empty, the loop body will simply not run.

@author:
Good I refactored it but I didn't improve this part. Thank you.

diff_hunk: @@ -3569,6 +3569,7 @@ def check_subtype(self, subtype: Type, supertype: Type, context: Context,
                 return False
             extra_info = []  # type: List[str]
             note_msg = ''
+            notes = []
path: mypy/checker.py
text: @user1:
You might need to add an explicit type comment `List[str]` here, otherwise self-check may fail.