What is the following code to your dictionary declaration?
I think PyCharm will trigger the error if you have something like:
dic = {}
dic['aaa'] = 5
as you could have written
dic = {'aaa': 5}
Note: The fact that the error goes away if you use the function doesn't necessarily mean that pycharm believes dict()
is a literal. It could just mean that it doesn't complain for:
dic = dict()
dic['aaa'] = 5
This can be disabled in the Project Settings or Default Settings.
for those who like (just like me) to initialize dictionaries with single operation
d = {
'a': 12,
'b': 'foo',
'c': 'bar'
}
instead of many lines like
d = dict()
d['a'] = 12
d['b'] = ....
in the end I ended up with this:
d = dict()
d.update({
'a': 12,
'b': 'foo',
'c': 'bar'
})
Pycharm is not complaining on this
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With