Skip to content

Pyright not recognizing metaclass keyword arguments #2436

Closed

Description

Describe the bug
Pyright doesn't recognize the keyword arguments of a metaclass when passing them in the class definition, though it does for classes with __init_subclass__ defined.

Screenshots or Code

from typing import TypeVar, Tuple, Dict, Any, Type, TYPE_CHECKING

CMT = TypeVar('CMT', bound='CommandMeta')

class BaseCommand:
    if TYPE_CHECKING:
        __foo__: int
        __bar__: str

    def __init_subclass__(cls, *, foo: int, bar: str) -> None: ...

class CommandMeta(type):
    if TYPE_CHECKING:
        __foo__: int
        __bar__: str

    def __new__(
        cls: Type[CMT],
        cls_name: str,
        bases: Tuple[type, ...],
        attrs: Dict[str, Any],
        *,
        foo: int,
        bar: str,
    ) -> CMT: ...


class One(BaseCommand, foo=1): ...  # Argument missing for parameter "bar"
class Two(metaclass=CommandMeta, foo=''): ...  # No error for the incorrect type or the missing parameter

VS Code extension or command-line
Are you running pyright as a VS Code extension or a command-line tool?
Command line (version 1.1.178)

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

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions