Way to specify KW_ONLY location in the constructor like in dataclass.KW_ONLY
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 35/100
- Issue type
- Feature
- Clarity
- Mostly clear
- Activity status
- Stale
- Tech stack
- python
- Domain
- developer-experience
Research direction
Use the linked Python dataclasses.KW_ONLY documentation and the two examples as the behavioral reference. Inspect attrs' constructor generation and existing keyword-only and inheritance tests; done means attrs can express the requested marker behavior, preserves the shown constructor ordering, and has coverage for both examples.
Written by the indexing model from the issue text.
Description
dataclass in python 3.10 and above got KW_ONLY sentinel value
it allows you to mark where the constructor will start the KWARGS in the class
https://docs.python.org/3/library/dataclasses.html#dataclasses.KW_ONLY
i did not found a way to do this in attrs package
@dataclass()
class Foo():
x:str=field(default="a")
_:KW_ONLY
y:bool
the function signature of the init will be
(x: str = "a", *, y: bool) -> None
the dataclass one will re order the items order in the constructor and handle inheritance properly(if needed)
https://docs.python.org/3/library/dataclasses.html#re-ordering-of-keyword-only-parameters-in-init
from dataclasses import dataclass,KW_ONLY,field
@dataclass
class Base:
x: float = 15.0
_: KW_ONLY
y: int = 0
w: int = 1
@dataclass
class D(Base):
z: int = 10
_: KW_ONLY
t: int = field(kw_only=False, default=0)
function signature:
(x: float = 15, z: int = 10, t: int = 0, *, y: int = 0, w: int = 1) -> None
- Dominant language
- Python
- Stars
- 5.8k
- Forks
- 490
- Avg merge
- 1h 45m
- Merged PRs (30d)
- 1
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing 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.
More from python-attrs/attrs
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
python-attrs/attrs#1627 ·
Maintainers usually reply within 1 day
-
Difficulty 5/5 Over a week Newbie friendliness 20/100
python-attrs/attrs#1620 ·
Maintainers usually reply within 1 day
-
Difficulty 3/5 1-2 days Newbie friendliness 55/100
python-attrs/attrs#1596 · 2 comments · 1 reaction ·
Maintainers usually reply within 1 day
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
python-attrs/attrs#1549 · 3 comments ·
Maintainers usually reply within 1 day
-
Difficulty 4/5 3-5 days Newbie friendliness 38/100
python-attrs/attrs#1543 · 2 comments ·
Maintainers usually reply within 1 day
All issues in python-attrs/attrs
Similar issues
-
Difficulty 1/5 Under an hour Newbie friendliness 92/100
raullenchai/Rapid-MLX#4042 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
LearningCircuit/local-deep-research#7067 ·
Maintainers usually reply within 1 day
-
#bug
Difficulty 1/5 Under an hour Newbie friendliness 92/100
apache/superset#44923 · 1 comment ·
Maintainers usually reply within 2 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
lawndoc/stack-back#123 ·