python / python/mypy

Allow to register new class/dataclass/attribute makers in attrs plugin

Open
#5,406 6 comments 10 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

feature priority-1-normal topic-attrs
Dominant language
Python
Stars
20.6k
Forks
3.3k
PR merge metrics
PR metrics pending

Description

This is a feature request.

attrs is very much intended to be composable (e.g. https://github.com/hynek/environ_config) but currently the attrs plugin only works on the core library's functions: https://github.com/python/mypy/blob/b2d61741623f2a0573f2b1bdb8391ceed862cf69/mypy/plugins/attrs.py#L24-L37

I would like to be able to signal somehow to mypy, that some function is a wrapper around @attr.s/@attr.ib/@attr.dataclass. Not only would third-party applications benefit, but I could really use it while experimenting on https://github.com/python-attrs/attrs/issues/408.

Any ideas/plans how we could achieve that?

cc also @euresti & @chadrik

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with mypy/plugins/attrs.py, especially the core-library functions listed around lines 24–37, and trace how the attrs plugin recognizes @attr.s, @attr.ib, and @attr.dataclass. Review the linked attrs issue for the motivating wrapper use case. Done means a documented, tested way for third-party wrappers to register equivalent class, dataclass, or attribute-maker behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
devtools
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.