Skip to content

Pyrefly says explicit Any type parameters can be subclassed but not **kwargs entries with explicit Any type #5422

Open

Description

@willy-b

Describe the Bug

Hello Pyrefly team!
Thanks so much for all you do. I am sharing the following bug report in the hopes it is useful to you in achieving consistency in the tool behavior and parity with other type checkers like pyright.

In Python and passing some other type checkers (e.g. pyright 1.1.414 commandline and the pyright playground ) it is ok to subclass an entry passed within the **kwargs which is typed as Any, but Pyrefly is rejecting it (seems like a bug).

from typing import Unpack, TypedDict, Any, reveal_type
class Person(TypedDict):
    name: str
    age: int
    some_any_field: Any

def foo(arg: bool, arg_any: Any, **kwargs: Unpack[Person]) -> None:
    reveal_type(kwargs['name'])
    reveal_type(arg_any)
    reveal_type(kwargs['some_any_field'])

    class Sub0(arg_any): pass # pyrefly says this Any typed argument is ok as a base class
    class Sub1(kwargs['some_any_field']): pass # like mypy (a bug I think) and unlike pyright, pyrefly does not recognize a kwargs entry with an explicit `Any` type as a valid base (a bug I think)
    # comment out just the Sub1 declaration and Pyrefly will say this is ok

Python: 3.12

See also #5397 for analogous problem with *args entries which are explicitly Any typed not being allowed as class bases.

Compare to e.g. Pyright at https://pyright-play.net/?code=GYJw9gtgBALgngBwJYDsDmUkQWEMoCqKCAhgMYDWANFACqICmAJgCJJkw0CCKcNIDAG4MSAGwD68BAwBQZUSQDOiqAAUGIRWBQAKetNbsYASgBcMqJagoSEBqaiKYIC1ZJp7mFDFeWtd8RJecWAkBlEmBx44GRkmBmAoYDAwHRIQNAcAIxTRGnS0QN4o3hoAKjKKAHcCxQciUkoAbXVNbQBdYygAWgA%2BKAA5bXtfKAFhMUlGHWrapoByGzt5ztHxkQkpBjSMorhjNaENqekZmozFBf8GPZCwiJWD0fklFQBlAFcsgAYdwqD9g5SMooABiKAIOACYCiOCOEhwFQwAAWSBU0VgjCYUAKHzs3kwKjAFBxKhIUCySgYUBeymeChBnyyAEYznN5tdbqFwkxHkDXmCoKIkBRqRBEHC0hSPhgAJKwVEoChdILYj4oYWiiFQpBoZGcbXQ2FQJhgBgqFBgfACMhgNAoJAAL2p5NmFygDG8IDhVSQKJxKA9AA8EMKyH6oAADaKRzHSUk4qCCMRIbGUxTUqVZGVQeUo1DK0bg20QfH4MAffAAKw%2BTgV1KZzJNDBeIBIMCQ2gD2NUUISxt9olE8Lh%2BZUaKgxJkQA where even though inheritance base validity is being checked pyright says subclassing the kwargs entry (with explicit Any type) is fine.

Thanks in advance for your response/evaluation of this issue in confirming whether it is a bug or not.

Sandbox Link

https://pyrefly.org/sandbox/?project=v2.pVVBTsMwEPzKSjmkIETg2h9wq4Q4lYq6ieWYpHZU25TwesbrJGoiqIQ4Wl7vzu7OjP9gmS-mE2UzMyt20Zn_JIltMAIQeIocaRUXfKFRoXDCztLJWWxfmP6N_WQdk0-SsHbFSjrAMlhUMZBD7uj2tsFUFMSeEG5T9d2SfBc4V-nFNo-A8h3osgwYSvxwMz6dw-UkKTiN4DkcHqYsa2YMZTQwhpzoHfkaWkULcc6yil2FozQ-Ktg2kYeCDgIKGyxvlvvxdxxTsVY3ko5919MKmYKip1jSNDeETVMwfA9EWtXY5QitsjB5UBBNl1YZ_SWBIxUjoDv1dNa-RgqSn12rSwh6jyb23EVCDcvQVcK-qJy6yPAlHLlVGzy9B-dxLbkteAd6xIfEUgTMzQDrrNs2ji1NjUfEKlhoMJseDHRGKYhXhZTy_tVk-N4k1d53bl0U43N7UoU0RWVLV8xeFCDficSH0PxzztORZc9wSPsf8edJ-_k16edR-Yi4quZv

(Only applicable for extension issues) IDE Information

No response

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions