Typing decorators which enrich a class
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 1.8k
- Forks
- 302
- Avg merge
- 23h
- Merged PRs (30d)
- 8
Description
Hi
I would like to type a decorator which takes as input a class and returns the same class with added attributes, i.e., a subclass.
Example:
import typing
_T = typing.TypeVar("_T")
def config(*, /, prefix: str) -> typing.Callable[[typing.Type[_T], ???]:
def wrap(cls: typing.Type[_T]) -> ???:
class Subclass(cls): # or could do cls.prefix = prefix instead of subclassing
prefix: str = prefix
return Subclass
return wrap
@config(prefix="test")
class A:
...
print(A.prefix)
Been searching for an answer and experimenting for a few days now and can't find anything concrete. Any help would be much appreciated
Thank you
Contributor guide
No contributing guide indexed for this repository
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
No files, tests, or entry points are named. Start by reviewing the current guidance for typing class decorators and the behavior of type checkers for the shown config and wrap signatures; done should mean there is a documented, accepted way to preserve the input class type while exposing the added prefix attribute.
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
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100