Skip to content

Extend R1735 use-dict-literal to highlight all usages of dict that can be replaced with a literal #7691

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

Merged
merged 1 commit into from
Nov 9, 2022
Merged

Conversation

hofrob
Copy link
Contributor

@hofrob hofrob commented Oct 30, 2022

Type of Changes

Type
✨ New feature

Description

Refs #7690

Closes #7690

@hofrob
Copy link
Contributor Author

hofrob commented Oct 30, 2022

  1. This could very well be added to the existing R1735 check. I don't know what the general consensus is on extending existing messages.
  2. The naming is kind of confusing now because use-dict-literal only covers empty dicts (dict()). So I decided to use use-dict-literal-without-kwargs for now though I think it adds to the confusion.
  3. I'm not using a neat pylint feature right now: show how the code would look like if the suggestion is applied. I'd probably need some pointers to accomplish that.

@Pierre-Sassoulas Pierre-Sassoulas added Enhancement ✨ Improvement to a component Needs design proposal 🔒 This is a huge feature, some discussion should happen before a PR is proposed labels Oct 30, 2022
Copy link
Member

@Pierre-Sassoulas Pierre-Sassoulas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for bringing a proof of concept with the issue 👌

I was also wondering if we should just extend what the existing message is doing or create another one. The former prevent user that don't want the new thing to disable it, but the second one add confusion. We could also rename the existing message to make things clearer and have the best of both world (?)

Regarding code suggestion, we should be careful to not create a behemoth message if the input dict is big we don't want a 400 lines message.

@coveralls
Copy link

coveralls commented Oct 30, 2022

Pull Request Test Coverage Report for Build 3426938040

  • 21 of 21 (100.0%) changed or added relevant lines in 1 file are covered.
  • 1 unchanged line in 1 file lost coverage.
  • Overall coverage decreased (-0.0007%) to 95.388%

Files with Coverage Reduction New Missed Lines %
pylint/checkers/refactoring/refactoring_checker.py 1 98.13%
Totals Coverage Status
Change from base Build 3422307568: -0.0007%
Covered Lines: 17268
Relevant Lines: 18103

💛 - Coveralls

@hofrob hofrob requested a review from DudeNr33 as a code owner October 30, 2022 16:45
@hofrob
Copy link
Contributor Author

hofrob commented Oct 30, 2022

I was also wondering if we should just extend what the existing message is doing or create another one. The former prevent user that don't want the new thing to disable it, but the second one add confusion. We could also rename the existing message to make things clearer and have the best of both world (?)

My personal opinion would be: Keep the name and code. Extend the functionality of the existing message. The name fits for both situations anyway.

People should expect new lint messages when upgrading the pylint package. But it's easy for me to say 😀 I don't have to work with huge code bases.

@hofrob
Copy link
Contributor Author

hofrob commented Oct 30, 2022

Regarding the failing "readthedocs" build:

/home/docs/checkouts/readthedocs.org/user_builds/pylint/checkouts/7691/doc/whatsnew/2/2.16/index.rst:49: WARNING: Bullet list ends without a blank line; unexpected unindent.

No idea what to do here. My branch is up-to-date. Do I need to add anything else to the docs? Or is this related to the changes in pylint/pyreverse/?

Copy link
Member

@Pierre-Sassoulas Pierre-Sassoulas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made some comments, I'm waiting for other maintainer opinion regarding the new message or the extension of the old one :)

@github-actions

This comment has been minimized.

@Pierre-Sassoulas
Copy link
Member

There is surprisingly few violation on the primer which is a very good sign. The primer for sentry:

    use-dict-literal-without-kwargs:
    *Consider using a dict literal '

class dict(object):
"""dict() -> new empty dictionary
dict(mapping) -> new dictionary initiali...' instead.*

https://github.com/getsentry/sentry/blob/4be98deb27375dac541740b9c8d7ce871ff2bc99/src/sentry/api/endpoints/organization_sdk_updates.py#L44
Seems like something we need to fix though.

@DanielNoord
Copy link
Collaborator

I like the suggestion of extending the previous message!

@Pierre-Sassoulas Pierre-Sassoulas removed the Needs design proposal 🔒 This is a huge feature, some discussion should happen before a PR is proposed label Oct 30, 2022
@Pierre-Sassoulas Pierre-Sassoulas added this to the 2.16.0 milestone Oct 30, 2022
@hofrob
Copy link
Contributor Author

hofrob commented Oct 30, 2022

There is surprisingly few violation on the primer which is a very good sign. The primer for sentry:

    use-dict-literal-without-kwargs:
    *Consider using a dict literal '

class dict(object):
"""dict() -> new empty dictionary
dict(mapping) -> new dictionary initiali...' instead.*

https://github.com/getsentry/sentry/blob/4be98deb27375dac541740b9c8d7ce871ff2bc99/src/sentry/api/endpoints/organization_sdk_updates.py#L44 Seems like something we need to fix though.

I fixed those and added test cases. The code suggestion is now constructed "manually" to be able to handle **kwargs separate from actual keyword=value arguments.

@github-actions

This comment has been minimized.

@hofrob
Copy link
Contributor Author

hofrob commented Oct 30, 2022

I like the suggestion of extending the previous message!

If you have the final say, I will go ahead. Or will others want to chime in?

@DanielNoord
Copy link
Collaborator

I like the suggestion of extending the previous message!

If you have the final say, I will go ahead. Or will others want to chime in?

They obviously can (and are encouraged to do so of course), but I think two maintainers thinking positively about this is a good sign to go ahead 😄

@Pierre-Sassoulas
Copy link
Member

It happened in the past that 2 maintainers agreed on something and another one made an argument so good we changed our mind but it's pretty rare 😄

@hofrob
Copy link
Contributor Author

hofrob commented Oct 30, 2022

Ok, so I did the following:

  • one method that checks all calls to dict (meaning empty dicts are not separate anymore)
  • constructing the suggestion happens in a new private static method
  • I still use a list to construct the suggestion because handling commas would be a PITA otherwise 😁 (and set() won't work because it changes the order on every test run)
  • all tests, examples, docs merged into the existing use-dict-literal files/directories
  • cleaning up code in pylint that was highlighted by the new message resulted in another pylint message showing up (consider-using-namedtuple-or-dataclass), I will disable those

Important! The confidence level of an existing message changes

While it was still a separate message, we set the confidence to INFERENCE. This will change the confidence for existing messages for empty calls to dict(). Just so you're aware.

@hofrob hofrob changed the title Add R1737 use-dict-literal-without-kwargs Extend R1735 use-dict-literal to highlight all usages of dict that can be replaced with a literal Oct 30, 2022
Copy link
Member

@Pierre-Sassoulas Pierre-Sassoulas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks pretty good already, thank you !

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

Copy link
Collaborator

@DudeNr33 DudeNr33 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just some minor comments from my side. Looks good to me overall!
I'm also +1 for extending the existing message.

@hofrob
Copy link
Contributor Author

hofrob commented Nov 1, 2022

I'm still unsure about the wording in doc/data/messages/u/use-dict-literal/details.rst. I'll gladly change this if you have something else in mind.

Btw. because I was curious I did a similar performance test with list joining compared to string concatenation: https://gist.github.com/hofrob/95b0d31ee4e168b876ecf82c92db2df4

Since we're using this in when creating the suggestion, I will leave it is.

@hofrob hofrob requested review from DudeNr33 and Pierre-Sassoulas and removed request for DudeNr33 November 1, 2022 13:10
Copy link
Member

@Pierre-Sassoulas Pierre-Sassoulas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is looking better and better 🔥

Comment on lines +1077 to +1078
self._check_use_list_literal(node)
self._check_use_dict_literal(node)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The call to inferred = utils.safe_infer(node.func) is pretty costly, I think we should keep list/dict together for better performance.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we will prevent any calls to utils.safe_infer in this case. The list-check _check_use_list_literal will only do it if node.as_string() == "list()" and _check_use_dict_literal will always do it if isinstance(node.func, astroid.Name)¹.

The only thing we could improve are the checks _check_use_dict_literal¹, right? Doing both in one method will not have any effect. Or will it?

¹: I added a check there now: node.as_string().startswith("dict(")

Copy link
Contributor Author

@hofrob hofrob Nov 8, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

¹: I added a check there now: node.as_string().startswith("dict(")

That "solution" sucks. I will do node.func.name != 'dict'.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Of course, this won't work for the following code:

foo = dict
new_dict = foo(asdf=1)

But I think we can live with it for performance reasons?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we will prevent any calls to utils.safe_infer in this case. The list-check _check_use_list_literal will only do it if node.as_string() == "list()"

Fair point, I missed that.

Of course, this won't work for the following code:

foo = dict
new_dict = foo(asdf=1)

But I think we can live with it for performance reasons?

Yes definitely. Let's not punish everyone with slower linter to be accurate for those who redefine dict. They don't deserve a linter anyway 😄

@DudeNr33
Copy link
Collaborator

DudeNr33 commented Nov 1, 2022

I'm still unsure about the wording in doc/data/messages/u/use-dict-literal/details.rst. I'll gladly change this if you have something else in mind.

Btw. because I was curious I did a similar performance test with list joining compared to string concatenation: https://gist.github.com/hofrob/95b0d31ee4e168b876ecf82c92db2df4

Since we're using this in when creating the suggestion, I will leave it is.

Sorry for the confusion - I actually liked that concrete number here, as it showed that we are not just talking about a 0.x % increase. I simply meant to add the Python version additionally, so we know in the future to what version this benchmark referred to.
Apart from that no more comments from my side. 😊 👍

DudeNr33
DudeNr33 previously approved these changes Nov 1, 2022
@github-actions

This comment has been minimized.

@hofrob
Copy link
Contributor Author

hofrob commented Nov 6, 2022

Sorry for the delay! I'm dealing with separate things for the moment.

Thanks for the feedback for now! I hope I'll be able to take another look in the course of the next week.

@hofrob
Copy link
Contributor Author

hofrob commented Nov 8, 2022

I'm still unsure about the wording in doc/data/messages/u/use-dict-literal/details.rst. I'll gladly change this if you have something else in mind.
Btw. because I was curious I did a similar performance test with list joining compared to string concatenation: https://gist.github.com/hofrob/95b0d31ee4e168b876ecf82c92db2df4
Since we're using this in when creating the suggestion, I will leave it is.

Sorry for the confusion - I actually liked that concrete number here, as it showed that we are not just talking about a 0.x % increase. I simply meant to add the Python version additionally, so we know in the future to what version this benchmark referred to. Apart from that no more comments from my side. blush +1

Sorry, this was from a quick DM with @Pierre-Sassoulas. I added it back now:

https://gist.github.com/hofrob/ad143aaa84c096f42489c2520a3875f9

This example script shows an 18% increase in performance when using a literal over the
constructor in python version 3.10.6.

@github-actions

This comment has been minimized.

Copy link
Member

@Pierre-Sassoulas Pierre-Sassoulas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The primer looks pretty good now, there's a case when the last argument under a certain length is very long that does not get truncated:

Consider using '{"by": dict(((key, reverse_resolve_tag_value(self._use_case_id, self._organization_id, value, weak=True)) if groupby_alias_to_groupby_column.get(key) not in NON_RESOLVABLE_TAG_VALUES else (key, value) for (key, value) in tags)), … }' instead of a call to 'dict'.

But I think it's acceptable.

Great first contribution @hofrob, this is definitely going in 2.16.0 :)

Comment on lines +1077 to +1078
self._check_use_list_literal(node)
self._check_use_dict_literal(node)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we will prevent any calls to utils.safe_infer in this case. The list-check _check_use_list_literal will only do it if node.as_string() == "list()"

Fair point, I missed that.

Of course, this won't work for the following code:

foo = dict
new_dict = foo(asdf=1)

But I think we can live with it for performance reasons?

Yes definitely. Let's not punish everyone with slower linter to be accurate for those who redefine dict. They don't deserve a linter anyway 😄

@Pierre-Sassoulas
Copy link
Member

This test fail under Windows seems genuine.

@hofrob
Copy link
Contributor Author

hofrob commented Nov 9, 2022

This test fail under Windows seems genuine.

Ah yes. This may have failed because of the ellipsis character in features.rst since it happened during this command: command = ['--rcfile=d:\\a\\pylint\\pylint\\pylint\\testutils\\testing_pylintrc', '--full-documentation']

I replaced it with dots ... now. Can't really run the test locally, so let's see what the pipeline is going to say.

@hofrob
Copy link
Contributor Author

hofrob commented Nov 9, 2022

FYI: I replaced all ellipsis characters with dots since there seems to be an issue with windows.

Details: When running the test test_self with the --full-documentation arg on windows, the following happens and no docs are returned: UnicodeDecodeError: 'utf-8' codec can't decode byte 0x85 in position 47771: invalid start byte

@Pierre-Sassoulas
Copy link
Member

Pierre-Sassoulas commented Nov 9, 2022

Details: When running the test test_self with the --full-documentation arg on windows, the following happens and no docs are returned:

Ha, right, probably the same encoding issue than with emojis in #7612. No need to use a unicode character for ellipsis, three dots are just fine.

@github-actions
Copy link
Contributor

github-actions bot commented Nov 9, 2022

🤖 Effect of this PR on checked open source code: 🤖

Effect on astroid:
The following messages are now emitted:

  1. use-dict-literal:
    Consider using '{"node": self, "unknown": node, "assign_path": assign_path, "context": context, ... }' instead of a call to 'dict'.
    https://github.com/PyCQA/astroid/blob/6cf238d089cf4b6753c94cfc089b4a47487711e5/astroid/protocols.py#L297
  2. use-dict-literal:
    Consider using '{"node": self, "unknown": node, "assign_path": assign_path, "context": context, ... }' instead of a call to 'dict'.
    https://github.com/PyCQA/astroid/blob/6cf238d089cf4b6753c94cfc089b4a47487711e5/astroid/protocols.py#L304
  3. use-dict-literal:
    Consider using '{"node": self, "unknown": node, "assign_path": assign_path, "context": context, ... }' instead of a call to 'dict'.
    https://github.com/PyCQA/astroid/blob/6cf238d089cf4b6753c94cfc089b4a47487711e5/astroid/protocols.py#L457
  4. use-dict-literal:
    Consider using '{"node": self, "unknown": node, "assign_path": assign_path, "context": context, ... }' instead of a call to 'dict'.
    https://github.com/PyCQA/astroid/blob/6cf238d089cf4b6753c94cfc089b4a47487711e5/astroid/protocols.py#L530
  5. use-dict-literal:
    Consider using '{"node": self, "unknown": node, "assign_path": assign_path, "context": context, ... }' instead of a call to 'dict'.
    https://github.com/PyCQA/astroid/blob/6cf238d089cf4b6753c94cfc089b4a47487711e5/astroid/protocols.py#L646
  6. use-dict-literal:
    Consider using '{"node": stmt, "context": context}' instead of a call to 'dict'.
    https://github.com/PyCQA/astroid/blob/6cf238d089cf4b6753c94cfc089b4a47487711e5/astroid/nodes/node_classes.py#L94
  7. use-dict-literal:
    Consider using '{"node": stmt, "context": context}' instead of a call to 'dict'.
    https://github.com/PyCQA/astroid/blob/6cf238d089cf4b6753c94cfc089b4a47487711e5/astroid/nodes/node_classes.py#L99
  8. use-dict-literal:
    Consider using '{"node": stmt, "context": context}' instead of a call to 'dict'.
    https://github.com/PyCQA/astroid/blob/6cf238d089cf4b6753c94cfc089b4a47487711e5/astroid/nodes/node_classes.py#L107

Effect on flask:
The following messages are now emitted:

  1. use-dict-literal:
    Consider using '{"key_derivation": self.key_derivation, "digest_method": self.digest_method, ... }' instead of a call to 'dict'.
    https://github.com/pallets/flask/blob/cc66213e579d6b35d9951c21b685d0078f373c44/src/flask/sessions.py#L350

Effect on pandas:
The following messages are now emitted:

  1. use-dict-literal:
    Consider using '{**_shared_docs}' instead of a call to 'dict'.
    https://github.com/pandas-dev/pandas/blob/25832bc479dd794c588938b5d650126f9d8d9bff/pandas/core/window/doc.py#L8
  2. use-dict-literal:
    Consider using '{"x": 'A', "y": 'B', "c": 'c', "colormap": cmap}' instead of a call to 'dict'.
    https://github.com/pandas-dev/pandas/blob/25832bc479dd794c588938b5d650126f9d8d9bff/pandas/tests/io/formats/style/test_matplotlib.py#L300

Effect on pytest:
The following messages are now emitted:

  1. use-dict-literal:
    Consider using '{"getfixture": self.fixture_request.getfixturevalue}' instead of a call to 'dict'.
    https://github.com/pytest-dev/pytest/blob/a092b3ab360b1aa56ea35d3303ed33b460144124/src/_pytest/doctest.py#L282
  2. use-dict-literal:
    Consider using '{"DONT_ACCEPT_TRUE_FOR_1": doctest.DONT_ACCEPT_TRUE_FOR_1, "DONT_ACCEPT_BLANKLINE": doctest.DONT_ACCEPT_BLANKLINE, ... }' instead of a call to 'dict'.
    https://github.com/pytest-dev/pytest/blob/a092b3ab360b1aa56ea35d3303ed33b460144124/src/_pytest/doctest.py#L385
  3. use-dict-literal:
    Consider using '{}' instead of a call to 'dict'.
    https://github.com/pytest-dev/pytest/blob/a092b3ab360b1aa56ea35d3303ed33b460144124/src/_pytest/doctest.py#L752
  4. use-dict-literal:
    Consider using '{"metafunc": metafunc}' instead of a call to 'dict'.
    https://github.com/pytest-dev/pytest/blob/a092b3ab360b1aa56ea35d3303ed33b460144124/src/_pytest/python.py#L499
  5. use-dict-literal:
    Consider using '{"warning_message": warning_message, "nodeid": nodeid, "when": when, ... }' instead of a call to 'dict'.
    https://github.com/pytest-dev/pytest/blob/a092b3ab360b1aa56ea35d3303ed33b460144124/src/_pytest/warnings.py#L65
  6. use-dict-literal:
    Consider using '{"plugin": plugin, "manager": self}' instead of a call to 'dict'.
    https://github.com/pytest-dev/pytest/blob/a092b3ab360b1aa56ea35d3303ed33b460144124/src/_pytest/config/__init__.py#L492
  7. use-dict-literal:
    Consider using '{"parser": self._parser, "pluginmanager": self.pluginmanager}' instead of a call to 'dict'.
    https://github.com/pytest-dev/pytest/blob/a092b3ab360b1aa56ea35d3303ed33b460144124/src/_pytest/config/__init__.py#L999
  8. use-dict-literal:
    Consider using '{"config": self}' instead of a call to 'dict'.
    https://github.com/pytest-dev/pytest/blob/a092b3ab360b1aa56ea35d3303ed33b460144124/src/_pytest/config/__init__.py#L1037
  9. use-dict-literal:
    Consider using '{"pluginmanager": self.pluginmanager}' instead of a call to 'dict'.
    https://github.com/pytest-dev/pytest/blob/a092b3ab360b1aa56ea35d3303ed33b460144124/src/_pytest/config/__init__.py#L1344
  10. use-dict-literal:
    Consider using '{"warning_message": records[0], "when": 'config', "nodeid": '', "location": location, ... }' instead of a call to 'dict'.
    https://github.com/pytest-dev/pytest/blob/a092b3ab360b1aa56ea35d3303ed33b460144124/src/_pytest/config/__init__.py#L1400
  11. use-dict-literal:
    Consider using '{"black": 30, "red": 31, "green": 32, "yellow": 33, "blue": 34, "purple": 35, ... }' instead of a call to 'dict'.
    https://github.com/pytest-dev/pytest/blob/a092b3ab360b1aa56ea35d3303ed33b460144124/src/_pytest/_io/terminalwriter.py#L42

The following messages are no longer emitted:

  1. use-dict-literal:
    Consider using {} instead of dict()
    https://github.com/pytest-dev/pytest/blob/a092b3ab360b1aa56ea35d3303ed33b460144124/src/_pytest/doctest.py#L752

Effect on sentry:
The following messages are now emitted:

  1. use-dict-literal:
    Consider using '{"geoip_lookup": rust_geoip, "max_secs_in_future": MAX_SECS_IN_FUTURE, ... }' instead of a call to 'dict'.
    https://github.com/getsentry/sentry/blob/8f53000b026f763fb849c40c7fb05277e22bb2c9/src/sentry/constants.py#L571
  2. use-dict-literal:
    Consider using '{"start": start, "end": end, "groupby": groupby, "conditions": conditions, ... }' instead of a call to 'dict'.
    https://github.com/getsentry/sentry/blob/8f53000b026f763fb849c40c7fb05277e22bb2c9/src/sentry/utils/snuba.py#L1187
  3. use-dict-literal:
    Consider using '{"partition_query": ' AND '.join(partition_query) + (' AND ' if partition_query else ''), ... }' instead of a call to 'dict'.
    https://github.com/getsentry/sentry/blob/8f53000b026f763fb849c40c7fb05277e22bb2c9/src/sentry/utils/query.py#L236
  4. use-dict-literal:
    Consider using '{}' instead of a call to 'dict'.
    https://github.com/getsentry/sentry/blob/8f53000b026f763fb849c40c7fb05277e22bb2c9/src/sentry/utils/jwt.py#L74
  5. use-dict-literal:
    Consider using '{"organization": organization}' instead of a call to 'dict'.
    https://github.com/getsentry/sentry/blob/8f53000b026f763fb849c40c7fb05277e22bb2c9/src/sentry/api/bases/organizationmember.py#L67
  6. use-dict-literal:
    Consider using '{"suggestions": list(get_suggested_updates(SdkSetupState(latest['sdkName'], latest['sdkVersion'], (), ()), index_state, ignore_patch_version=True)), ... }' instead of a call to 'dict'.
    https://github.com/getsentry/sentry/blob/8f53000b026f763fb849c40c7fb05277e22bb2c9/src/sentry/api/endpoints/organization_sdk_updates.py#L44
  7. use-dict-literal:
    Consider using '{"include_values_seen": True}' instead of a call to 'dict'.
    https://github.com/getsentry/sentry/blob/8f53000b026f763fb849c40c7fb05277e22bb2c9/src/sentry/api/endpoints/project_tags.py#L19
  8. use-dict-literal:
    Consider using '{}' instead of a call to 'dict'.
    https://github.com/getsentry/sentry/blob/8f53000b026f763fb849c40c7fb05277e22bb2c9/src/sentry/api/helpers/group_index/update.py#L691
  9. use-dict-literal:
    Consider using '{"url": f'/organizations/{org_slug}/integrations/{obj.key}/setup/', ... }' instead of a call to 'dict'.
    https://github.com/getsentry/sentry/blob/8f53000b026f763fb849c40c7fb05277e22bb2c9/src/sentry/api/serializers/models/integration.py#L170
  10. use-dict-literal:
    Consider using '{"constructor": NormalizedUserIpEvent}' instead of a call to 'dict'.
    https://github.com/getsentry/sentry/blob/8f53000b026f763fb849c40c7fb05277e22bb2c9/src/sentry/region_to_control/messages.py#L62
  11. use-dict-literal:
    Consider using '{"constructor": NormalizedAuditLogEvent}' instead of a call to 'dict'.
    https://github.com/getsentry/sentry/blob/8f53000b026f763fb849c40c7fb05277e22bb2c9/src/sentry/region_to_control/messages.py#L66
  12. use-dict-literal:
    Consider using '{"user_id": user_ip_event.user_id, "ip_address": user_ip_event.ip_address, ... }' instead of a call to 'dict'.
    https://github.com/getsentry/sentry/blob/8f53000b026f763fb849c40c7fb05277e22bb2c9/src/sentry/region_to_control/consumer.py#L109
  13. use-dict-literal:
    Consider using '{"key": redis_key, "limit": limit, "request_uid": request_uid}' instead of a call to 'dict'.
    https://github.com/getsentry/sentry/blob/8f53000b026f763fb849c40c7fb05277e22bb2c9/src/sentry/ratelimits/concurrent.py#L53
  14. use-dict-literal:
    Consider using '{"key": key, "request_uid": request_uid}' instead of a call to 'dict'.
    https://github.com/getsentry/sentry/blob/8f53000b026f763fb849c40c7fb05277e22bb2c9/src/sentry/ratelimits/concurrent.py#L79
  15. use-dict-literal:
    Consider using '{"value": original_data}' instead of a call to 'dict'.
    https://github.com/getsentry/sentry/blob/8f53000b026f763fb849c40c7fb05277e22bb2c9/src/sentry/db/mixin.py#L54
  16. use-dict-literal:
    Consider using '{"by": dict(((key, reverse_resolve_tag_value(self._use_case_id, self._organization_id, value, weak=True)) if groupby_alias_to_groupby_column.get(key) not in NON_RESOLVABLE_TAG_VALUES else (key, value) for (key, value) in tags)), ... }' instead of a call to 'dict'.
    https://github.com/getsentry/sentry/blob/8f53000b026f763fb849c40c7fb05277e22bb2c9/src/sentry/snuba/metrics/query_builder.py#L906
  17. use-dict-literal:
    Consider using '{}' instead of a call to 'dict'.
    https://github.com/getsentry/sentry/blob/8f53000b026f763fb849c40c7fb05277e22bb2c9/src/sentry/profiles/task.py#L167
  18. use-dict-literal:
    Consider using '{"data": data}' instead of a call to 'dict'.
    https://github.com/getsentry/sentry/blob/8f53000b026f763fb849c40c7fb05277e22bb2c9/src/sentry/models/processingissue.py#L89
  19. use-dict-literal:
    Consider using '{"group": group, "project_id": group.project_id, "linked_type": GroupLink.LinkedType.issue, ... }' instead of a call to 'dict'.
    https://github.com/getsentry/sentry/blob/8f53000b026f763fb849c40c7fb05277e22bb2c9/src/sentry/models/grouplink.py#L27
  20. use-dict-literal:
    Consider using '{"organization_id": self._release.organization_id, "release_id": self._release.id, ... }' instead of a call to 'dict'.
    https://github.com/getsentry/sentry/blob/8f53000b026f763fb849c40c7fb05277e22bb2c9/src/sentry/models/releasefile.py#L359
  21. use-dict-literal:
    Consider using '{"integration": integration, "organization__organizationintegration__integration": integration, ... }' instead of a call to 'dict'.
    https://github.com/getsentry/sentry/blob/8f53000b026f763fb849c40c7fb05277e22bb2c9/src/sentry/models/integrations/external_issue.py#L27
  22. use-dict-literal:
    Consider using '{"method": str(request.method), "view": view, "response": status_code, ... }' instead of a call to 'dict'.
    https://github.com/getsentry/sentry/blob/8f53000b026f763fb849c40c7fb05277e22bb2c9/src/sentry/middleware/access_log.py#L83
  23. use-dict-literal:
    Consider using '{"host": '%s:%d' % (host, port), "userid": dsn.username, "password": dsn.password, ... }' instead of a call to 'dict'.
    https://github.com/getsentry/sentry/blob/8f53000b026f763fb849c40c7fb05277e22bb2c9/src/sentry/monitoring/queues.py#L37
  24. use-dict-literal:
    Consider using '{}' instead of a call to 'dict'.
    https://github.com/getsentry/sentry/blob/8f53000b026f763fb849c40c7fb05277e22bb2c9/src/sentry/tagstore/snuba/backend.py#L599
  25. use-dict-literal:
    Consider using '{"user_id__isnull": False, "user__is_active": True}' instead of a call to 'dict'.
    https://github.com/getsentry/sentry/blob/8f53000b026f763fb849c40c7fb05277e22bb2c9/src/sentry/tasks/reports.py#L779
  26. use-dict-literal:
    Consider using '{}' instead of a call to 'dict'.
    https://github.com/getsentry/sentry/blob/8f53000b026f763fb849c40c7fb05277e22bb2c9/src/sentry/sentry_metrics/configuration.py#L51
  27. use-dict-literal:
    Consider using '{}' instead of a call to 'dict'.
    https://github.com/getsentry/sentry/blob/8f53000b026f763fb849c40c7fb05277e22bb2c9/src/sentry/integrations/utils/sync.py#L25
  28. use-dict-literal:
    Consider using '{"member_set__user": user, "organizationintegration__integration": integration, ... }' instead of a call to 'dict'.
    https://github.com/getsentry/sentry/blob/8f53000b026f763fb849c40c7fb05277e22bb2c9/src/sentry/integrations/utils/identities.py#L28
  29. use-dict-literal:
    Consider using '{"id": organization_id}' instead of a call to 'dict'.
    https://github.com/getsentry/sentry/blob/8f53000b026f763fb849c40c7fb05277e22bb2c9/src/sentry/integrations/utils/identities.py#L34
  30. use-dict-literal:
    Consider using '{"oauth_scopes": sorted(GitlabIdentityProvider.oauth_scopes), "redirect_url": absolute_uri('/extensions/gitlab/setup/'), ... }' instead of a call to 'dict'.
    https://github.com/getsentry/sentry/blob/8f53000b026f763fb849c40c7fb05277e22bb2c9/src/sentry/integrations/gitlab/integration.py#L335
  31. use-dict-literal:
    Consider using '{"oauth_scopes": (), "redirect_url": absolute_uri('/extensions/github-enterprise/setup/'), ... }' instead of a call to 'dict'.
    https://github.com/getsentry/sentry/blob/8f53000b026f763fb849c40c7fb05277e22bb2c9/src/sentry/integrations/github_enterprise/integration.py#L271
  32. use-dict-literal:
    Consider using '{"user": user, "key": 'issue:defaults', "project": project}' instead of a call to 'dict'.
    https://github.com/getsentry/sentry/blob/8f53000b026f763fb849c40c7fb05277e22bb2c9/src/sentry/integrations/mixins/issues.py#L168
  33. use-dict-literal:
    Consider using '{"user": user, "key": 'issue:defaults', "project": project}' instead of a call to 'dict'.
    https://github.com/getsentry/sentry/blob/8f53000b026f763fb849c40c7fb05277e22bb2c9/src/sentry/integrations/mixins/issues.py#L178
  34. use-dict-literal:
    *Consider using '{"jwt": encoded_jwt, *url_params or {}}' instead of a call to 'dict'.
    https://github.com/getsentry/sentry/blob/8f53000b026f763fb849c40c7fb05277e22bb2c9/src/sentry/integrations/jira/client.py#L71
  35. use-dict-literal:
    Consider using '{"method": method, "path": path, "data": data, "params": params}' instead of a call to 'dict'.
    https://github.com/getsentry/sentry/blob/8f53000b026f763fb849c40c7fb05277e22bb2c9/src/sentry/integrations/jira/client.py#L73
  36. use-dict-literal:
    Consider using '{"method": method, "path": path, "data": data, "params": params}' instead of a call to 'dict'.
    https://github.com/getsentry/sentry/blob/8f53000b026f763fb849c40c7fb05277e22bb2c9/src/sentry/integrations/jira_server/client.py#L73
  37. use-dict-literal:
    Consider using '{"external_name": channel_name, "external_id": channel_id}' instead of a call to 'dict'.
    https://github.com/getsentry/sentry/blob/8f53000b026f763fb849c40c7fb05277e22bb2c9/src/sentry/integrations/slack/views/link_team.py#L132
  38. use-dict-literal:
    *Consider using '{"query": query, *args}' instead of a call to 'dict'.
    https://github.com/getsentry/sentry/blob/8f53000b026f763fb849c40c7fb05277e22bb2c9/src/sentry/integrations/slack/unfurl/discover.py#L288
  39. use-dict-literal:
    Consider using '{}' instead of a call to 'dict'.
    https://github.com/getsentry/sentry/blob/8f53000b026f763fb849c40c7fb05277e22bb2c9/src/sentry/features/manager.py#L100
  40. use-dict-literal:
    Consider using '{"category": get_path(frame_data, 'data', 'category'), "family": get_behavior_family_for_platform(frame_data.get('platform') or platform), ... }' instead of a call to 'dict'.
    https://github.com/getsentry/sentry/blob/8f53000b026f763fb849c40c7fb05277e22bb2c9/src/sentry/grouping/enhancer/matchers.py#L63
  41. use-dict-literal:
    Consider using '{"ignore_unknown_options": True}' instead of a call to 'dict'.
    https://github.com/getsentry/sentry/blob/8f53000b026f763fb849c40c7fb05277e22bb2c9/src/sentry/runner/__init__.py#L91
  42. use-dict-literal:
    Consider using '{"ignore_unknown_options": True, "allow_extra_args": True}' instead of a call to 'dict'.
    https://github.com/getsentry/sentry/blob/8f53000b026f763fb849c40c7fb05277e22bb2c9/src/sentry/runner/commands/exec.py#L19
  43. use-dict-literal:
    Consider using '{"email": email, "username": email, "is_superuser": superuser, "is_staff": staff, ... }' instead of a call to 'dict'.
    https://github.com/getsentry/sentry/blob/8f53000b026f763fb849c40c7fb05277e22bb2c9/src/sentry/runner/commands/createuser.py#L109
  44. use-dict-literal:
    Consider using '{"ignore_unknown_options": True, "allow_extra_args": True}' instead of a call to 'dict'.
    https://github.com/getsentry/sentry/blob/8f53000b026f763fb849c40c7fb05277e22bb2c9/src/sentry/runner/commands/execfile.py#L8
  45. use-dict-literal:
    Consider using '{"ignore_unknown_options": True}' instead of a call to 'dict'.
    https://github.com/getsentry/sentry/blob/8f53000b026f763fb849c40c7fb05277e22bb2c9/src/sentry/runner/commands/django.py#L6
  46. use-dict-literal:
    Consider using '{"start": start, "end": end, "project_ids": [p.id for p in projects], ... }' instead of a call to 'dict'.
    https://github.com/getsentry/sentry/blob/8f53000b026f763fb849c40c7fb05277e22bb2c9/src/sentry/search/snuba/executors.py#L697
  47. use-dict-literal:
    Consider using '{}' instead of a call to 'dict'.
    https://github.com/getsentry/sentry/blob/8f53000b026f763fb849c40c7fb05277e22bb2c9/src/sentry/lang/javascript/errorlocale.py#L10
  48. use-dict-literal:
    Consider using '{"type": {'type': 'string', 'enum': ['http']}, "url": {'type': 'string'}, ... }' instead of a call to 'dict'.
    https://github.com/getsentry/sentry/blob/8f53000b026f763fb849c40c7fb05277e22bb2c9/src/sentry/lang/native/symbolicator.py#L81
  49. use-dict-literal:
    Consider using '{"type": {'type': 'string', 'enum': ['s3']}, "bucket": {'type': 'string'}, ... }' instead of a call to 'dict'.
    https://github.com/getsentry/sentry/blob/8f53000b026f763fb849c40c7fb05277e22bb2c9/src/sentry/lang/native/symbolicator.py#L94
  50. use-dict-literal:
    Consider using '{"type": {'type': 'string', 'enum': ['gcs']}, "bucket": {'type': 'string'}, ... }' instead of a call to 'dict'.
    https://github.com/getsentry/sentry/blob/8f53000b026f763fb849c40c7fb05277e22bb2c9/src/sentry/lang/native/symbolicator.py#L109
  51. use-dict-literal:
    Consider using '{}' instead of a call to 'dict'.
    https://github.com/getsentry/sentry/blob/8f53000b026f763fb849c40c7fb05277e22bb2c9/src/sentry/lang/native/symbolicator.py#L683
  52. use-dict-literal:
    Consider using '{}' instead of a call to 'dict'.
    https://github.com/getsentry/sentry/blob/8f53000b026f763fb849c40c7fb05277e22bb2c9/src/sentry/lang/native/appconnect.py#L162
  53. use-dict-literal:
    Consider using '{"task_name": self.name}' instead of a call to 'dict'.
    https://github.com/getsentry/sentry/blob/8f53000b026f763fb849c40c7fb05277e22bb2c9/src/sentry/bgtasks/api.py#L43
  54. use-dict-literal:
    Consider using '{"task_name": self.name}' instead of a call to 'dict'.
    https://github.com/getsentry/sentry/blob/8f53000b026f763fb849c40c7fb05277e22bb2c9/src/sentry/bgtasks/api.py#L56
  55. use-dict-literal:
    Consider using '{"task_name": self.name}' instead of a call to 'dict'.
    https://github.com/getsentry/sentry/blob/8f53000b026f763fb849c40c7fb05277e22bb2c9/src/sentry/bgtasks/api.py#L62
  56. use-dict-literal:
    Consider using '{}' instead of a call to 'dict'.
    https://github.com/getsentry/sentry/blob/8f53000b026f763fb849c40c7fb05277e22bb2c9/src/sentry/notifications/helpers.py#L230

The following messages are no longer emitted:

  1. use-dict-literal:
    Consider using {} instead of dict()
    https://github.com/getsentry/sentry/blob/8f53000b026f763fb849c40c7fb05277e22bb2c9/src/sentry/utils/jwt.py#L74
  2. use-dict-literal:
    Consider using {} instead of dict()
    https://github.com/getsentry/sentry/blob/8f53000b026f763fb849c40c7fb05277e22bb2c9/src/sentry/api/helpers/group_index/update.py#L691
  3. use-dict-literal:
    Consider using {} instead of dict()
    https://github.com/getsentry/sentry/blob/8f53000b026f763fb849c40c7fb05277e22bb2c9/src/sentry/profiles/task.py#L167
  4. use-dict-literal:
    Consider using {} instead of dict()
    https://github.com/getsentry/sentry/blob/8f53000b026f763fb849c40c7fb05277e22bb2c9/src/sentry/tagstore/snuba/backend.py#L599
  5. use-dict-literal:
    Consider using {} instead of dict()
    https://github.com/getsentry/sentry/blob/8f53000b026f763fb849c40c7fb05277e22bb2c9/src/sentry/sentry_metrics/configuration.py#L51
  6. use-dict-literal:
    Consider using {} instead of dict()
    https://github.com/getsentry/sentry/blob/8f53000b026f763fb849c40c7fb05277e22bb2c9/src/sentry/integrations/utils/sync.py#L25
  7. use-dict-literal:
    Consider using {} instead of dict()
    https://github.com/getsentry/sentry/blob/8f53000b026f763fb849c40c7fb05277e22bb2c9/src/sentry/features/manager.py#L100
  8. use-dict-literal:
    Consider using {} instead of dict()
    https://github.com/getsentry/sentry/blob/8f53000b026f763fb849c40c7fb05277e22bb2c9/src/sentry/lang/javascript/errorlocale.py#L10
  9. use-dict-literal:
    Consider using {} instead of dict()
    https://github.com/getsentry/sentry/blob/8f53000b026f763fb849c40c7fb05277e22bb2c9/src/sentry/lang/native/symbolicator.py#L683
  10. use-dict-literal:
    Consider using {} instead of dict()
    https://github.com/getsentry/sentry/blob/8f53000b026f763fb849c40c7fb05277e22bb2c9/src/sentry/lang/native/appconnect.py#L162
  11. use-dict-literal:
    Consider using {} instead of dict()
    https://github.com/getsentry/sentry/blob/8f53000b026f763fb849c40c7fb05277e22bb2c9/src/sentry/notifications/helpers.py#L230

Effect on coverage:
The following messages are now emitted:

  1. use-dict-literal:
    Consider using '{"Name": '{:{name_len}}', "Stmts": '{:>7}', "Miss": '{:>7}', "Branch": '{:>7}', ... }' instead of a call to 'dict'.
    https://github.com/nedbat/coveragepy/blob/bc630b58b5d1c58cc8108e584a480f3a1cd5ab70/coverage/summary.py#L52
  2. use-dict-literal:
    Consider using '{"Cover": '{:>{n}}%'}' instead of a call to 'dict'.
    https://github.com/nedbat/coveragepy/blob/bc630b58b5d1c58cc8108e584a480f3a1cd5ab70/coverage/summary.py#L72
  3. use-dict-literal:
    Consider using '{"Name": '| {:{name_len}}|', "Stmts": '{:>9} |', "Miss": '{:>9} |', ... }' instead of a call to 'dict'.
    https://github.com/nedbat/coveragepy/blob/bc630b58b5d1c58cc8108e584a480f3a1cd5ab70/coverage/summary.py#L106
  4. use-dict-literal:
    Consider using '{"Cover": '{:>{n}}% |'}' instead of a call to 'dict'.
    https://github.com/nedbat/coveragepy/blob/bc630b58b5d1c58cc8108e584a480f3a1cd5ab70/coverage/summary.py#L128
  5. use-dict-literal:
    Consider using '{"Name": '|{:>{name_len}} |', "Cover": '{:>{n}} |'}' instead of a call to 'dict'.
    https://github.com/nedbat/coveragepy/blob/bc630b58b5d1c58cc8108e584a480f3a1cd5ab70/coverage/summary.py#L136
  6. use-dict-literal:
    Consider using '{"name": 0, "stmts": 1, "miss": 2, "cover": -1}' instead of a call to 'dict'.
    https://github.com/nedbat/coveragepy/blob/bc630b58b5d1c58cc8108e584a480f3a1cd5ab70/coverage/summary.py#L182
  7. use-dict-literal:
    Consider using '{"branch": 3, "brpart": 4}' instead of a call to 'dict'.
    https://github.com/nedbat/coveragepy/blob/bc630b58b5d1c58cc8108e584a480f3a1cd5ab70/coverage/summary.py#L184
  8. use-dict-literal:
    Consider using '{"morfs": unglob_args(args), "ignore_errors": options.ignore_errors, ... }' instead of a call to 'dict'.
    https://github.com/nedbat/coveragepy/blob/bc630b58b5d1c58cc8108e584a480f3a1cd5ab70/coverage/cmdline.py#L676

This comment was generated for commit a552780

Copy link
Collaborator

@DanielNoord DanielNoord left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Love this change! Thanks very much!

@DanielNoord DanielNoord merged commit 0507ee3 into pylint-dev:main Nov 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement ✨ Improvement to a component
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Prefer dict literal over dict constructor
6 participants