-
Notifications
You must be signed in to change notification settings - Fork 525
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
list.insert() causes inconsistent error messages #358
Comments
The output of |
@xiaxinmeng As @learnforpractice noted, that is the expected behavior. There are two different lists: the first is of type a: List[Optional] = [None]
n = a[0]
print(type(n) is Optional) # True
temp = {'abc': 5}
a: List[Optional[Dict[str, int]]] = []
a.append(None)
a.append(temp)
n = a[0] # None
d = a[1] # {'abc': 5}
print(type(n) is Optional) # False
print(type(n) is Optional[Dict[str, int]]) # True
print(type(d) is Optional) # False
print(type(d) is Optional[Dict[str, int]]) # True
l = [None]
l[0] = {'abc': 5} # List[Optional[Dict[str, int]]]
l.insert(0, None)
n = l[0] # None
d = l[1] # {'abc': 5}
print(type(n) is Optional) # False
print(type(n) is Optional[Dict[str, int]]) # True
print(type(d) is Optional) # False
print(type(d) is Optional[Dict[str, int]]) # True |
Yes, this is the expected behaviour as Better error messaging is added to #604. |
In the following we define two function-equivalent code snippets, i.e., test1.py and test2.py. "if 'abc' in a:pass" uses the same value of a, i.e., None, while the error messages are different for the two test programs. I think the output of test2.py is the expected behavior.
test1.py
The output of test1.py
test2.py
The output of test2.py:
test.py:355:4-14: error: 'NoneType' object has no attribute '__contains__'
Reproduce step:
Environment:
Ubuntu 18.04
Codon v0.16.0
The text was updated successfully, but these errors were encountered: