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

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

Open
OddBloke opened this issue Aug 22, 2017 · 6 comments

Comments

@OddBloke
Copy link
Contributor

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.

@OddBloke
Copy link
Contributor Author

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.

@OddBloke OddBloke changed the title Conflicting names of types should be disambiguated MessageBuilder.format_distinctly doesn't make generic types distinct from non-generic types Aug 22, 2017
@OddBloke OddBloke 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 Aug 22, 2017
@OddBloke
Copy link
Contributor Author

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

@gvanrossum
Copy link
Member

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

@OddBloke
Copy link
Contributor Author

Yep, I'll definitely take a look.

@ilevkivskyi
Copy link
Member

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

@OddBloke
Copy link
Contributor Author

OddBloke commented Sep 2, 2017 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants