-
Notifications
You must be signed in to change notification settings - Fork 239
Closed
Labels
userBugs reported by external users that should be prioritisedBugs reported by external users that should be prioritised
Description
Describe the Bug
I'm not sure how exactly to describe this, but it isn't working as I expect.
Even though I have guarded my key variable with a Literal, pyrefly does not seem to respect the None check.
This works as expected when my key is the actual string.
from typing import Any, TypedDict, Literal
class MyDict(TypedDict):
my_key: list[str] | None
def fun1():
data: MyDict = {'my_key': None}
if data['my_key'] is None:
data['my_key'] = []
else:
data['my_key'].append('data')
def fun2():
data: MyDict = {'my_key': None}
key: Literal['my_key'] = 'my_key'
if data[key] is None:
data[key] = []
else:
data[key].append('data') # this fails
data['my_key'].append('data') # also fails
Sandbox Link
(Only applicable for extension issues) IDE Information
No response
Metadata
Metadata
Assignees
Labels
userBugs reported by external users that should be prioritisedBugs reported by external users that should be prioritised