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

Feature request: support common metaclass usage #1868

Closed
Diggsey opened this issue Jul 14, 2016 · 4 comments
Closed

Feature request: support common metaclass usage #1868

Diggsey opened this issue Jul 14, 2016 · 4 comments

Comments

@Diggsey
Copy link

Diggsey commented Jul 14, 2016

It's common to use meta classes as a way to define models, eg:

class Model(Base):
    my_column = Column(SomeType, ...)

This sort of pattern occurs in many places including ORMs and serialisation libraries, basically anything where a schema of some kind is needed.
What they all share is that the RHS of assignments in the class definition describe the type of those attributes on instances of the class, rather than the value of those attributes.

I think it would be worthwhile special-casing this usage: allow annotating a meta class with a type signature which tells mypy how to handle members. For the example above:

class BaseMeta(type):
    # field-generator: (Column[T]) -> T
    ...

This would give mypy the information it needs to determine the correct type of my_column.

@gvanrossum
Copy link
Member

gvanrossum commented Jul 15, 2016 via email

@Diggsey
Copy link
Author

Diggsey commented Jul 15, 2016

That seems reasonable, but there doesn't seem to be any documentation or examples about how to write plugins for mypy. I think I've read most of the documentation and until you mentioned it was unaware that mypy even supported plugins?

@JukkaL
Copy link
Collaborator

JukkaL commented Jul 15, 2016

There's no way to write mypy plugins yet. We don't even have a concrete plan. See #1240 for some discussion.

@gvanrossum
Copy link
Member

Let's close this as a dupe of the plugins issue (#1240).

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

No branches or pull requests

3 participants