Skip to content
Discussion options

You must be logged in to vote

OK, I was able to dynamically create subclasses within the __new__ method of my Column class, satisfying Textual's expectations:

class Column(Container):
    _count = 0

    def __new__(cls, *args, **kwargs) -> Column:
        Column._count += 1
        bindings = kwargs.pop("bindings", [])
        custom_column_class = type(f"Column{Column._count}", (Column,), {"BINDINGS": bindings})
        return super().__new__(custom_column_class)

    def __init__(
        self,
        *,
        title: str,
        headers: Sequence[str],
        producer: Callable,
        consumer: Callable | None = None,
        bindings: list[tuple[str, str, str]] | None = None,  # noqa: ARG002
        **kwargs,…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by pawamoy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant