python-attrs / python-attrs/attrs

Typing not working properly when positional argument is defined in subclass with redefined kwargs

Open
#1,023 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Typing
Dominant language
Python
Stars
5.8k
Forks
480
Avg merge
2h 15m
Merged PRs (30d)
2

Description

Describe the bug
Using pyright for type checking produces the following errors:

from attrs import define


@define
class A:
    foo: int
    bar: str = "baz"


@define
class B(A):
    zoo: float
    bar: str = "zaz"


b = B(1, 2.7)
print(b)
>>> B(foo=1, zoo=2.7, bar='zaz')

image
image

Not sure whether the problem is with attrs type definitions or with pyright, so will create issues in both places.

Perhaps types are not defined properly somewhere?

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 by reproducing the provided attrs example with pyright and confirm which call-site errors occur for the subclass constructor. Then inspect whether attrs' typing definitions or pyright's handling of redefined kwargs is responsible; done means the responsible project is identified and the example type-checks correctly.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
developer-experience
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.