Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6915781
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:31:04+00:00 2026-05-27T09:31:04+00:00

When initializing a dictionary with d = {} Pycharm’s code inspector generates a warning,

  • 0

When initializing a dictionary with d = {} Pycharm’s code inspector generates a warning, saying

This dictionary creation could be rewritten as a dictionary literal.

If I rewrite it d = dict() the warning goes away. Since {} already is a dictionary literal, I’m pretty sure the message is erroneous. Furthermore, it seems like both d = {} and d = dict() are valid and Pythonic.

This related question seems to conclude that the choice is just a matter of style/preference:
differences between "d = dict()" and "d = {}"

Why would Pycharm complain about d = {}?

UPDATE:

Mac nailed it. The warning actually applied to multiple lines, not just the one that was flagged.

Pycharm seems to look for a sequence of consecutive statements where you initialize a dictionary and then set values in the dictionary. For example, this will trigger the warning:

d = {}
d['a'] = 1

But this code will not:

d = {}
pass
d['a'] = 1
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T09:31:05+00:00Added an answer on May 27, 2026 at 9:31 am

    What is the code following 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 dict(). This doesn’t necessarily mean that pycharm believes dict() is a literal. It could just mean that it doesn’t complain about it:

    dic = dict()
    dic['aaa'] = 5
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am initializing a map map<string,int> ex; in C++. I could not find contains_key
I just came across this question about initializing local variables. Many of the answers
Is it OK to reference this when initializing a field? public class MainClass {
So I am looping through some objects and initializing a Dictionary> object. So first
I see this idiom of initializing instance variables quite a bit public class Test{
Here is the code initializing my Table: <table cellspacing=0> <caption id=title4> Sprinkles (5 -
I am initializing my gesture recognizers with the following code when I initialize a
I'm initializing Entity Framework Object context, and this gives me the keyword not supported
I am initializing a GridView, text box and a button via code to a
I'm initializing an UIImagePickerController like this: self.cameraController = [[UIImagePickerController alloc] init]; self.cameraController.sourceType = UIImagePickerControllerSourceTypeCamera;

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.