Skip to content

Document how to write aliases that are recognized by mypy#650

Merged
hynek merged 2 commits intomasterfrom
docs-fake-mypy-plugin
Jul 20, 2020
Merged

Document how to write aliases that are recognized by mypy#650
hynek merged 2 commits intomasterfrom
docs-fake-mypy-plugin

Conversation

@hynek
Copy link
Copy Markdown
Member

@hynek hynek commented Jun 8, 2020

This fIxEs #630 as far as we can fix it. I would love to add a more concrete example (a minimal example that people can just drop in and that explains how to drop in) but I guess I'll leave that as a contribution opportunity to someone else since I don't have the bandwidth for that ATM.

@hynek hynek requested a review from euresti June 8, 2020 06:26
Copy link
Copy Markdown
Contributor

@euresti euresti left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just some nits and a question.

Thanks for doing this.

Comment thread docs/extending.rst
Comment thread docs/extending.rst
Comment thread docs/extending.rst
@Tinche
Copy link
Copy Markdown
Member

Tinche commented Jun 8, 2020

I actually had issues getting mypy to recognize my wrappers. I think the package implementing the wrappers needs to contain a py.typed marker file.

@euresti
Copy link
Copy Markdown
Contributor

euresti commented Jun 8, 2020

Also, what would make us not hold our nose? I have a couple of ideas:

  1. Add a new decorator that does nothing but it lets mypy know that this method overrides an attrs method. Something like:
@class_maker(auto_attribs_default=True)
def my_class_maker(...):
   ...

This looks great but is probably pretty hard in mypy. Also how many defaults do we allow to set. We'd want to iterate on the API.

  1. Add a method that lets us not feel like it's not modifying a global. e.g.
from mypy.plugins.attrs import register_extra_makers

class MyPlugin(Plugin):
    def __init__(self, options: Options) -> None:
        register_extra_makers(dataclass=..., attrs=..., attrib=...)
        super().__init__(options)        

def plugin(version):
    return MyPlugin
  1. Maybe there's a way to do this in mypy.ini? But this is not something I've investigated. The mypy team might have special rules for what's allowed in the mypy.ini file.

@wsanchez wsanchez added the Typing Typing/stub/Mypy/PyRight related bugs. label Jun 8, 2020
@hynek hynek force-pushed the docs-fake-mypy-plugin branch from 92027b6 to 4f84e13 Compare July 20, 2020 07:45
@hynek
Copy link
Copy Markdown
Member Author

hynek commented Jul 20, 2020

Also, what would make us not hold our nose? I have a couple of ideas:

This seems worth a news ticket I think!

I like both but someone intimate with mypy has to investigate what you wrote. :|

@hynek hynek merged commit cab4557 into master Jul 20, 2020
@hynek hynek deleted the docs-fake-mypy-plugin branch July 20, 2020 08:10
@hynek
Copy link
Copy Markdown
Member Author

hynek commented Aug 21, 2020

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

Labels

Documentation Typing Typing/stub/Mypy/PyRight related bugs.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Way to change defaults?

4 participants