Skip to content

HelpTheme subclasses cannot use with_(), dark() or light() #225

Description

@kdeldycke

Bug description

#163 turned HelpTheme into a dataclass so it could be subclassed (#159).

But a subclass that adds a slot only half works and with_(), dark() and light() fails.

To Reproduce

>>> import dataclasses
>>> from cloup import HelpTheme, Style
>>> from cloup.styling import IStyle
>>> def identity(s: str) -> str:
...     return s
...
>>> @dataclasses.dataclass(frozen=True)
... class MyTheme(HelpTheme):
...     metavar: IStyle = identity
...
>>> type(MyTheme.dark()).__name__
'HelpTheme'
>>> MyTheme.dark().metavar
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'HelpTheme' object has no attribute 'metavar'
>>> MyTheme().with_(metavar=Style(fg="cyan"))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: HelpTheme.with_() got an unexpected keyword argument 'metavar'

Screenshots

I had to reimplement reimplements with_() in Click Extra to bypass the issue: https://github.com/kdeldycke/click-extra/blob/b4200f4b90dfdf69266cd3af77262919c3394492/click_extra/theme.py#L254-L279

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions