Search code examples
pythonpycharm

Unclear suggestion: "This dictionary could be written as dictionary litteral."


I'm using PyCharm to write automated tests for an API. PyCharm highlights one line in my tests and suggests:

This dictionary could be written as dictionary litteral.

Is there a better a "style" to do this to make this message disappear?

def test_get_products_combination_2(self):
    """
    TC-586:GET Products - combination 2 valid
    """
    params = {} # <--- this line is highlighted with the message above
    params["start_at_document"] = "100"
    params["document_limit"] = "2"
    path = "/v1/users/%s/products" % self.user_id
    r = self.client.request(path, params)
    self.assertEqual(r.status_code, 200)

Solution

  • If you change params to dictionary literal it should fix the warning:

    params = {
        "start_at_document": "100",
        "document_limit": "2"
    }