Skip to content

Investigate mypy warning alt.theme.register #3789

Closed

Description

@dangotbanned

What happened?

Causing an upstream warning in https://github.com/narwhals-dev/narwhals/actions/runs/13154290048/job/36707803255

altair/theme.py:251: error: ParamSpec "P" is unbound  [valid-type]
            def wrapper(*args: P.args, **kwargs: P.kwargs) -> ThemeConfig:
            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Found 1 error in 1 file (checked 383 source files)

altair/altair/theme.py

Lines 250 to 252 in 7fce53d

@_wraps(func)
def wrapper(*args: P.args, **kwargs: P.kwargs) -> ThemeConfig:
return func(*args, **kwargs)

Seems like mypy has suddenly decided it doesn't know about

P = ParamSpec("P")

What would you like to happen instead?

Not trigger a failure in narwhals

Which version of Altair are you using?

7fce53d

Activity

  1. dangotbanned commented on Feb 5, 2025

    @dangotbanned
    MemberAuthor

    Maybe resolvable by replacing alt.theme.P with:

    R = TypeVar("R")
    Plugin = TypeAliasType("Plugin", Callable[..., R], type_params=(R,))

    Edit 1

    Or changing Plugin to this, playing with PEP 696 and importing alt.utils.plugin_registry.P:

    P = ParamSpec("P")
    R = TypeVar("R")
    Plugin = TypeAliasType("Plugin", Callable[P, R], type_params=(P, R))

    Edit 2

    python/mypy#18278 (comment)

    Hello hello! There's nothing that puts P into scope / nothing that tells a type checker what P is meant to match.

    If you changed def decorate(func: Plugin[ThemeConfig], /) -> Plugin[ThemeConfig]: to def decorate(func: Callable[P, ThemeConfig], /) -> Callable[P, ThemeConfig]: that would do the job and actually provide better type checking to callers. (Looks like Plugin is basically just an alias for Callable that loses track of parameter types)

    It's also unclear to me why you need an inner function at all. Seems like you could just return func from decorate and not bother with wrapper. This would also be a fix.

  2. added a commit that references this issue on Feb 5, 2025
    554ed8a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions