Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

False positive with inline TypedDict and postponed annotations #5935

Closed
object-Object opened this issue Sep 12, 2023 · 2 comments
Closed

False positive with inline TypedDict and postponed annotations #5935

object-Object opened this issue Sep 12, 2023 · 2 comments
Labels
addressed in next version Issue is fixed and will appear in next published version bug Something isn't working

Comments

@object-Object
Copy link

Describe the bug

When using from __future__ import annotations with the experimental inline TypedDict syntax, Pyright gives what I think is a false reportUndefinedVariable error for non-string forward references.

Code or Screenshots

Code:

from __future__ import annotations
from typing import TypedDict

string: dict[{"forward_ref": "ForwardRefType"}]

# note: `value = dict[{"forward_ref": ForwardRefType}]` *does* raise NameError
non_string: dict[{"forward_ref": ForwardRefType}]  # Pyright error occurs here

class TypedDictType(TypedDict):
    forward_ref: ForwardRefType

ForwardRefType = str

Error:

(venv) PS D:\Users\redacted> python test.py
(venv) PS D:\Users\redacted> pyright test.py
D:\Users\redacted\test.py
  D:\Users\redacted\test.py:7:34 - error: "ForwardRefType" is not defined (reportUndefinedVariable)
1 error, 0 warnings, 0 informations

VS Code extension or command-line

Tested using the command line tool.
Pyright: 1.1.326
Python: 3.11.3

@object-Object object-Object added the bug Something isn't working label Sep 12, 2023
@erictraut
Copy link
Collaborator

Inlined TypedDict is an experimental feature intended to gather feedback about a potential future extension to the type system. It's likely to change or be removed, so please don't make use of it in any production code.

Given the status of this feature, I don't generally entertain bug fixes (especially edge cases), but this one happens to be trivial to fix, so I'll do so.

erictraut pushed a commit that referenced this issue Sep 12, 2023
…side of an inlined TypedDict when `from __future__ import annotations` is in effect. This addresses #5935.
@erictraut erictraut added the addressed in next version Issue is fixed and will appear in next published version label Sep 12, 2023
@erictraut
Copy link
Collaborator

This is addressed in pyright 1.1.327, which I just published. It will also be included in an upcoming release of pylance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
addressed in next version Issue is fixed and will appear in next published version bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants