Skip to content

MessageBuilder.format_distinctly doesn't make identically named (but different) types distinct when one is generic #3860

Open

Description

@OddBloke

I've been playing around with the plugin interface, and was hitting a strange error with the following (minimal) example plugin:

from typing import Callable, Optional, Type

from mypy.plugin import MethodContext, Plugin


class DummyPlugin(Plugin):

    def get_method_hook(
            self, fullname: str) -> Optional[Callable[[MethodContext], Type]]:
        return dummy_callback


def dummy_callback(ctx: MethodContext) -> Type:
    return ctx.default_return_type


plugin = lambda _: DummyPlugin
dummy_plugin.py:8: error: Return type of "get_method_hook" incompatible with supertype "Plugin"
dummy_plugin.py:14: error: Incompatible return value type (got "Type", expected Type[Any])

It took a while of staring confusedly at my code to realise that the fix is quite simple:

--- dummy_plugin.py.old	2017-08-22 14:58:55.739834119 -0400
+++ dummy_plugin.py	2017-08-22 14:59:11.407829264 -0400
@@ -1,6 +1,7 @@
-from typing import Callable, Optional, Type
+from typing import Callable, Optional
 
 from mypy.plugin import MethodContext, Plugin
+from mypy.types import Type
 
 
 class DummyPlugin(Plugin):

It would be good to have a bit more information about where the types come from in this case.

Activity

  1. OddBloke commented on Aug 22, 2017

    @OddBloke
    ContributorAuthor

    Hmm, it looks like this is handled in the general case, I'm just hitting it because one of the types is generic (and so the string representations are different in the first comparison in MessageBuilder.format_distinctly).

    Let me update the issue title.

  2. changed the title [-]Conflicting names of types should be disambiguated[/-] [+]MessageBuilder.format_distinctly doesn't make generic types distinct from non-generic types[/+] on Aug 22, 2017
  3. changed the title [-]MessageBuilder.format_distinctly doesn't make generic types distinct from non-generic types[/-] [+]MessageBuilder.format_distinctly doesn't make identically named (but different) types distinct when one is generic[/+] on Aug 22, 2017
  4. OddBloke commented on Aug 22, 2017

    @OddBloke
    ContributorAuthor

    I started looking at this, but I think it'll be much easier after #3430 has landed.

  5. gvanrossum commented on Aug 22, 2017

    @gvanrossum
    Member

    Hm, maybe you can help with #3430? That PR seems to have ended up in a bit of quicksand...

  6. OddBloke commented on Aug 24, 2017

    @OddBloke
    ContributorAuthor

    Yep, I'll definitely take a look.

  7. ilevkivskyi commented on Sep 2, 2017

    @ilevkivskyi
    Member

    I thin this one can be fixed now, since the PR superseding #3430 is now merged.

  8. OddBloke commented on Sep 2, 2017

    @OddBloke
    ContributorAuthor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions