Skip to content

Confusing errors with anonymous TypedDict #3210

@QEDady

Description

@QEDady

Describe the Bug

Pyrefly constructs an anonymous TypedDict for any small literal dict where all keys are literal strings, but this can lead to confusing error messages e.g.

d = {'a': 42}
d['a'] = 'b'

errors with

Literal['b'] is not assignable to TypedDict key a with type int [bad-typed-dict-key]

I think this is confusing since the user didn't specify any TypedDict. I would personally prefer a bad-assignment or bad-argument-type. Other type checkers produce one of these two, or equivalent.

Sandbox Link

https://pyrefly.org/sandbox/?project=N4IgZglgNgpgziAXKOBDAdgEwEYHsAeAdAA4CeSIAxAAQDqMUAxrgLYzUAuunAFuwAqkATjDBRS1AMoYcBADS8IcakuqpqxVAHMYAHXQ0A7nxHVSuAK7VGGaoaEQOMBXB6pTM6rHfo1eCxycpMQQ6FoqvoIcPLjohPqUCdQAEjAeHtaWxLDUYDCoHBYiyrhgispoWHj4iEkAtNQA4jCBIqhQdRwQbEHE7Ix8jADWoeF5MDiow-XUAKpw7CIAbvlQAPocwTAAFACUnNyhcH2MgaF5QiKYvfAzMPh9DmzogYaOPLzsAJIAIgCiuXyhWKvAKdnYcAsxGIuCEgW2MEIWkIagCuGYLGyLWc1C0uE6%2BMwolCjggsQUMRWQgULUYuxmtAcTjUWGoQgskVI0VimSJ1EwEBEp3EETMliE1GwQlwhgWQn0%2BjA0pYvVGKkxsMCACoFayALzUYAAclQRsQ1AALAAmAC%2B%2BkwAG0TUaALrUA1G7BGkByEBkERiUiELgsKAUGiCAMiyqyfCZdCQLRFApkuJJSQwdg8DgcYhwRAAegL-tE4kIsK0BZg6ALmHRcALzATECTQhTsQLuVhaiWqGgqGwOSbieTXR5uGIY-QcHi6DI3PQdSpcFT7uouhAAGZCABGK0b-QOtLSoRwF36DndGFwiZ1AVCrorNdGlvoWEwI36N8cOoiACOFiCreQwwKQdRTIw8DKB6hg%2BJ%2B6AgDavpTI%2BMAAGLQDAFAxtUJDkDaQA

(Only applicable for extension issues) IDE Information

No response

Metadata

Metadata

Assignees

Labels

Type

No fields configured for Bug.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions