Mypy fails on usage of attrs package
Open
Nobody has claimed this yet.
bug
topic-attrs
topic-disallow-any
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
On the following file name.py
from attr import attrs, attrib
@attrs(frozen=True)
class Name:
name: str = attrib(converter=str.lower)
def __str__(self) -> str:
return self.name
calling mypy as follows
mypy src --disallow-untyped-calls --disallow-untyped-defs --disallow-untyped-decorators --disallow-incomplete-defs --disallow-any-expr --warn-redundant-casts --warn-unreachable
results in the following errors
name.py:4: error: Expression type contains "Any" (has type "Type[Name]")
name.py:6: error: Unsupported converter, only named functions and types are currently supported
I think both errors are incorrect.
If you agree then please fix!
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the reproducible example in name.py and run the supplied mypy command to confirm both diagnostics. Trace how mypy handles the attrs decorator and converter, then verify the example no longer reports these two errors while preserving the intended type checking behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100