Skip to content

bug: Undetected LSP violation in method override with **kwargs: object annotation #10815

@RBerga06

Description

@RBerga06

This came up in ManimCommunity/manim#4398 (comment).

I believe the class definition class B(A): ... should not be allowed by pyright (especially in strict mode), because it can lead to unsoundness, as demostrated in the example below. In fact, mypy currently rejects this (mypy playground)

Describe the bug
A clear and concise description of the behavior you are seeing and the expected behavior along with steps to reproduce it.

Code or Screenshots
Code sample in pyright playground

class A:
    def foo(self, /, **kwargs: object) -> None: ...

class B(A):
    def foo(self, /, *, x: int = 3, **kwargs: object) -> None:
        assert isinstance(x, int)   # of course, right?

def use_a(a: A):
    a.foo(x="hello")  # ok because "hello": str <: object

use_a(A())  # all fine
use_a(B())  # woops, AssertionError!

VS Code extension or command-line
Observed in the Pyright playground (online) and verified its run-time behaviour with Python 3.12.11 (macOS arm64)

Metadata

Metadata

Assignees

No one assigned

    Labels

    addressed in next versionIssue is fixed and will appear in next published versionbugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions