Skip to content

Usage of self=None in class Carousel triggers type checkers #190

@marshmallowsunshinekitten1234

Description

Describe the bug

class Carousel in pywa/types/templates.py, defines params in a way, that is not acceptable for type checkers. The usage of self=None to check whether or not the function is called as a class function or an instance function (same as other template components like BodyText.params(), HeaderText.params(), etc.) works at runtime, but type checkers report that None is invalid in place of self.

Faulty source code:

def params(self=None, *, cards: list[CarouselCard._Params]) -> Carousel._Params:
        """
        Fill the parameters for the carousel component.

        Args:
            [...]
        """
        [...]

All other template components work with class-level calls without type errors:

BodyText.params("hello")        # Works - no type error
HeaderImage.params(image="url") # Works - no type error  
Carousel.params(cards=[...])    # Type error: "None" not assignable to "self"

The difference is that Carousel uses explicit self=None parameter while others use the *positionals pattern in a private _params helper.

To Reproduce

import pywa.types.templates as pywa_template
# Class-level call - this triggers type error
carousel_params = pywa_template.Carousel.params(cards=[])

Actual Result (type checker):
Argument of type "None" cannot be assigned to parameter "self" of type "Carousel" in function "params"
Image

Expected behavior

No type error; should work like other template components.

pywa version

3.9.0

python version

3.13.13

os

Debian GNU/Linux 13 (image -> python:3.13-slim)

Additional context

Suggested Fix: Change implementation to use *args-style pattern like other components.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions