Skip to content

bad-unpacking error when unpacking a TypedDict that inherits another TypedDict #1351

@macintacos

Description

@macintacos

Describe the Bug

I have the following minimal reproducer:

import typing_extensions as te


class InheritFromMe(te.TypedDict):
    foo: bool


class TestBadUnpackingError(InheritFromMe):
    bar: bool


unpack_this: InheritFromMe = {"foo": True}
test1: TestBadUnpackingError = {"bar": True, **unpack_this}
test2: TestBadUnpackingError = {"bar": True, "foo": True}

print(f"{ test1 = }")
print(f"{ test2 = }")

The output of the program is:

$ python test.py
test1 = {'bar': True, 'foo': True}
test2 = {'bar': True, 'foo': True}

They're functionally equivalent, as far as I can tell. However, pyrefly reports the first as a bad-unpacking error:

$ pyrefly check test.py
ERROR Unpacked `TypedDict[InheritFromMe]` is not assignable to `TypedDict[TestBadUnpackingError]` [bad-unpacking]
  --> /Users/macinburrito/GitLocal/Work/semaphore/test.py:13:48
   |
13 | test1: TestBadUnpackingError = {"bar": True, **unpack_this}
   |                                                ^^^^^^^^^^^
   |
 INFO 1 error

I think that this shouldn't be a bad-unpacking error, but perhaps I'm missing some nuance of the type system here?

Sandbox Link

https://pyrefly.org/sandbox/?project=N4IgZglgNgpgziAXKOBDAdgEwEYHsAeAdAA4CeSIAxAAQDqMUAxrgLYzUAuunAFuwAqkATjDBRS1AMoYcBADS8IcakuqpqxVAHMYAHXQ0A7nxHVSuAK7VGGaoaEQOMBXB6pTM6rHfo1eCxycpMQQ6FoqvoIcPLjohPqUCdQAEjAeHtaWxLDUYDCoHBYiyrhgispoWHj4iEkAtNQA4jCBIqhQdRwQbEHE7Ix8jADWoeF5MDiow-XUAKpw7CIAbvlQAPocwTAAFACUnNyhcH2MgaF5QiKYvfAzMPh9DmzogYaOPLzsAJIAIgCiuXyhWKvAKdnYcAsxGIuCEgW2MEIWkIagCuGYLGyLWc1C0uE6%2BMwolCjggsQUMRWQgULUYuxmtAcTjUWGoQgskVI0VimSJ1EwEBEp3EETMliE1GwQlwhgWQn0%2Bm6MLhvVGa3uTnQcDJWrUyicCvQ%2BkYUFQcGUX3QJkcADFpSwALI7JyEAAqW0wPwgp12tV81ADYFwuEQkuDUENxtN5uorvgHAAQqhMLN0JphqM-pdYdtLdaOHbWE7ffoAwHsO5Q3hcBGjXWOemhhseEpQ3m0rb7U7qABeajAXTgYOD0Ou9kwAC%2B%2BiccA4AEZR-Gkym01MRmEs9KJX2ByAK-KkLHxwoAFQnhtr5tKKcveMAJkXs%2BXqcbmez2-7g-3I6PFhxg6DXAfzHP8b30YgHBebYwEHYBOHjOde2oKcQHpNNII4aDYPg2c7yQlC0P0ZZVg2LZthnec0OI9pSL6cj7zQkA5BAAJoDgEhyEQKg5i6KBHAkMAOVOHU4ENIkyiDIQWAKNZ0AsFhsDSbYagiDh9jqAA%2BahZyEP0yzZFoil8GCQAAOXkxTdP7fAUP0JiQDIEQxFIQguBYKAKBoQQnJFSpZHwTJ0EgLQigKHV4gMKQYHYHgOA4Yg4EQAB6JLHNEcRCFhLQkpgdAkswdE4CS5ggogEKhDC2IktyWE1CWVBoFQbAchK4LQq6HlcGIDqtQishuXQOoqW1Hk%2B0HABmQg5zvQc7InZipi6FYbWgGAKD86oOJACcgA

(Only applicable for extension issues) IDE Information

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions