Skip to content
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

Extend dict-get-with-none-default (SIM910) to non-literals #8762

Merged
merged 1 commit into from
Nov 19, 2023

Conversation

charliermarsh
Copy link
Member

Summary

Ensures that we can catch cases like:

ages = {"Tom": 23, "Maria": 23, "Dog": 11}
age = ages.get("Cat", None)

Previously, the rule was somewhat useless, as it only checked for literal accesses.

Closes #8760.

@charliermarsh charliermarsh added the bug Something isn't working label Nov 18, 2023
Copy link
Contributor

github-actions bot commented Nov 19, 2023

ruff-ecosystem results

Linter (stable)

ℹ️ ecosystem check detected linter changes. (+12 -0 violations, +0 -0 fixes in 41 projects)

rotki/rotki (+12 -0 violations, +0 -0 fixes)

+ rotkehlchen/api/v1/schemas.py:1582:17: SIM910 [*] Use `data.get('label')` instead of `data.get('label', None)`
+ rotkehlchen/chain/balances.py:174:27: SIM910 [*] Use `xpub_mappings.get(account)` instead of `xpub_mappings.get(account, None)`
+ rotkehlchen/chain/bitcoin/hdkey.py:125:14: SIM910 [*] Use `VERSION_BYTES.get(prefix)` instead of `VERSION_BYTES.get(prefix, None)`
+ rotkehlchen/chain/ethereum/modules/aave/aave.py:127:32: SIM910 [*] Use `reserve_cache.get(reserve_address)` instead of `reserve_cache.get(reserve_address, None)`
+ rotkehlchen/chain/ethereum/modules/yearn/vaultsv2.py:122:27: SIM910 [*] Use `roi_cache.get(vault_address)` instead of `roi_cache.get(vault_address, None)`
+ rotkehlchen/chain/ethereum/modules/yearn/vaultsv2.py:123:27: SIM910 [*] Use `pps_cache.get(vault_address)` instead of `pps_cache.get(vault_address, None)`
+ rotkehlchen/exchanges/coinbase.py:619:27: SIM910 [*] Use `raw_data.get('payout_at')` instead of `raw_data.get('payout_at', None)`
+ rotkehlchen/exchanges/coinbase.py:768:27: SIM910 [*] Use `raw_data.get('payout_at')` instead of `raw_data.get('payout_at', None)`
+ rotkehlchen/exchanges/independentreserve.py:136:13: SIM910 [*] Use `IR_TO_WORLD.get(symbol)` instead of `IR_TO_WORLD.get(symbol, None)`
+ rotkehlchen/exchanges/utils.py:32:11: SIM910 [*] Use `mapping.get(key)` instead of `mapping.get(key, None)`
+ rotkehlchen/rotkehlchen.py:636:25: SIM910 [*] Use `xpub_mappings.get(xpub_entry)` instead of `xpub_mappings.get(xpub_entry, None)`
+ rotkehlchen/serialization/schemas.py:216:35: SIM910 [*] Use `data.get('underlying_tokens')` instead of `data.get('underlying_tokens', None)`

Changes by rule (1 rules affected)

code total + violation - violation + fix - fix
SIM910 12 12 0 0 0

Linter (preview)

ℹ️ ecosystem check detected linter changes. (+842 -0 violations, +0 -0 fixes in 41 projects)

apache/airflow (+7 -0 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --select ALL --preview

+ airflow/io/store/__init__.py:134:21: SIM910 [*] Use `_STORE_CACHE.get(alias)` instead of `_STORE_CACHE.get(alias, None)`
+ airflow/providers/amazon/aws/hooks/glue_crawler.py:126:32: SIM910 [*] Use `crawler_tags.get(key)` instead of `crawler_tags.get(key, None)`
+ airflow/providers/apache/livy/operators/livy.py:214:12: SIM910 [*] Use `event.get("log_lines")` instead of `event.get("log_lines", None)`
+ tests/hooks/test_package_index.py:70:24: SIM910 [*] Use `testdata.get("host")` instead of `testdata.get("host", None)`
+ tests/hooks/test_package_index.py:71:25: SIM910 [*] Use `testdata.get("login")` instead of `testdata.get("login", None)`
+ tests/hooks/test_package_index.py:72:28: SIM910 [*] Use `testdata.get("password")` instead of `testdata.get("password", None)`
+ tests/hooks/test_package_index.py:73:35: SIM910 [*] Use `testdata.get("expected_result")` instead of `testdata.get("expected_result", None)`

bokeh/bokeh (+4 -0 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --select ALL --preview

+ src/bokeh/application/handlers/code_runner.py:108:25: SIM910 [*] Use `d.get('__doc__')` instead of `d.get('__doc__', None)`
+ src/bokeh/server/views/multi_root_static_handler.py:62:25: SIM910 [*] Use `root.get(name)` instead of `root.get(name, None)`
+ src/bokeh/sphinxext/bokeh_palette.py:113:9: SIM910 [*] Use `_globals.get("palette")` instead of `_globals.get("palette", None)`
+ src/bokeh/util/compiler.py:306:14: SIM910 [*] Use `_bundle_cache.get(key)` instead of `_bundle_cache.get(key, None)`

demisto/content (+803 -0 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --preview

+ Documentation/common_server_docs.py:178:32: SIM910 [*] Use `PY_IRREGULAR_FUNCS.get(a)` instead of `PY_IRREGULAR_FUNCS.get(a, None)`
+ Documentation/common_server_docs.py:185:32: SIM910 [*] Use `PY_IRREGULAR_FUNCS.get(a)` instead of `PY_IRREGULAR_FUNCS.get(a, None)`
+ Packs/AWS-Enrichment-Remediation/Scripts/AWSRecreateSG/AWSRecreateSG.py:304:19: SIM910 [*] Use `args.get('instance_id')` instead of `args.get('instance_id', None)`
+ Packs/AWS-Enrichment-Remediation/Scripts/AWSRecreateSG/AWSRecreateSG.py:305:16: SIM910 [*] Use `args.get('port')` instead of `args.get('port', None)`
+ Packs/AWS-Enrichment-Remediation/Scripts/AWSRecreateSG/AWSRecreateSG.py:306:16: SIM910 [*] Use `args.get('protocol')` instead of `args.get('protocol', None)`
+ Packs/AWS-Enrichment-Remediation/Scripts/AWSRecreateSG/AWSRecreateSG.py:307:17: SIM910 [*] Use `args.get('public_ip')` instead of `args.get('public_ip', None)`
+ Packs/AWS-Enrichment-Remediation/Scripts/AWSRecreateSG/AWSRecreateSG.py:308:19: SIM910 [*] Use `args.get('assume_role')` instead of `args.get('assume_role', None)`
+ Packs/AWS-Enrichment-Remediation/Scripts/AWSRecreateSG/AWSRecreateSG.py:309:14: SIM910 [*] Use `args.get('region')` instead of `args.get('region', None)`
+ Packs/AWS-SecurityHub/Integrations/AWS_SecurityHub/AWS_SecurityHub.py:100:26: SIM910 [*] Use `args.get('first_observed_at_start')` instead of `args.get('first_observed_at_start', None)`
+ Packs/AWS-SecurityHub/Integrations/AWS_SecurityHub/AWS_SecurityHub.py:101:24: SIM910 [*] Use `args.get('first_observed_at_end')` instead of `args.get('first_observed_at_end', None)`
+ Packs/AWS-SecurityHub/Integrations/AWS_SecurityHub/AWS_SecurityHub.py:103:29: SIM910 [*] Use `args.get('date_range_unit')` instead of `args.get('date_range_unit', None)`
+ Packs/AWS-SecurityHub/Integrations/AWS_SecurityHub/AWS_SecurityHub.py:109:26: SIM910 [*] Use `args.get('last_observed_at_start')` instead of `args.get('last_observed_at_start', None)`
+ Packs/AWS-SecurityHub/Integrations/AWS_SecurityHub/AWS_SecurityHub.py:110:24: SIM910 [*] Use `args.get('last_observed_at_end')` instead of `args.get('last_observed_at_end', None)`
+ Packs/AWS-SecurityHub/Integrations/AWS_SecurityHub/AWS_SecurityHub.py:112:29: SIM910 [*] Use `args.get('date_range_unit')` instead of `args.get('date_range_unit', None)`
+ Packs/AWS-SecurityHub/Integrations/AWS_SecurityHub/AWS_SecurityHub.py:116:26: SIM910 [*] Use `args.get('created_at_start')` instead of `args.get('created_at_start', None)`
+ Packs/AWS-SecurityHub/Integrations/AWS_SecurityHub/AWS_SecurityHub.py:117:24: SIM910 [*] Use `args.get('created_at_end')` instead of `args.get('created_at_end', None)`
+ Packs/AWS-SecurityHub/Integrations/AWS_SecurityHub/AWS_SecurityHub.py:119:29: SIM910 [*] Use `args.get('date_range_unit')` instead of `args.get('date_range_unit', None)`
+ Packs/AWS-SecurityHub/Integrations/AWS_SecurityHub/AWS_SecurityHub.py:123:26: SIM910 [*] Use `args.get('updated_at_start')` instead of `args.get('updated_at_start', None)`
+ Packs/AWS-SecurityHub/Integrations/AWS_SecurityHub/AWS_SecurityHub.py:124:24: SIM910 [*] Use `args.get('updated_at_end')` instead of `args.get('updated_at_end', None)`
+ Packs/AWS-SecurityHub/Integrations/AWS_SecurityHub/AWS_SecurityHub.py:126:29: SIM910 [*] Use `args.get('date_range_unit')` instead of `args.get('date_range_unit', None)`
+ Packs/AWS-SecurityHub/Integrations/AWS_SecurityHub/AWS_SecurityHub.py:130:26: SIM910 [*] Use `args.get('severity_label_value')` instead of `args.get('severity_label_value', None)`
+ Packs/AWS-SecurityHub/Integrations/AWS_SecurityHub/AWS_SecurityHub.py:131:31: SIM910 [*] Use `args.get('severity_label_comparison')` instead of `args.get('severity_label_comparison', None)`
+ Packs/AWS-SecurityHub/Integrations/AWS_SecurityHub/AWS_SecurityHub.py:135:26: SIM910 [*] Use `args.get('title_value')` instead of `args.get('title_value', None)`
+ Packs/AWS-SecurityHub/Integrations/AWS_SecurityHub/AWS_SecurityHub.py:136:31: SIM910 [*] Use `args.get('title_comparison')` instead of `args.get('title_comparison', None)`
+ Packs/AWS-SecurityHub/Integrations/AWS_SecurityHub/AWS_SecurityHub.py:140:26: SIM910 [*] Use `args.get('description_value')` instead of `args.get('description_value', None)`
+ Packs/AWS-SecurityHub/Integrations/AWS_SecurityHub/AWS_SecurityHub.py:141:31: SIM910 [*] Use `args.get('description_comparison')` instead of `args.get('description_comparison', None)`
+ Packs/AWS-SecurityHub/Integrations/AWS_SecurityHub/AWS_SecurityHub.py:145:26: SIM910 [*] Use `args.get('recommendation_text_value')` instead of `args.get('recommendation_text_value', None)`
+ Packs/AWS-SecurityHub/Integrations/AWS_SecurityHub/AWS_SecurityHub.py:146:31: SIM910 [*] Use `args.get('recommendation_text_comparison')` instead of `args.get('recommendation_text_comparison', None)`
+ Packs/AWS-SecurityHub/Integrations/AWS_SecurityHub/AWS_SecurityHub.py:150:26: SIM910 [*] Use `args.get('source_url_value')` instead of `args.get('source_url_value', None)`
+ Packs/AWS-SecurityHub/Integrations/AWS_SecurityHub/AWS_SecurityHub.py:151:31: SIM910 [*] Use `args.get('source_url_comparison')` instead of `args.get('source_url_comparison', None)`
+ Packs/AWS-SecurityHub/Integrations/AWS_SecurityHub/AWS_SecurityHub.py:155:24: SIM910 [*] Use `args.get('product_fields_key')` instead of `args.get('product_fields_key', None)`
+ Packs/AWS-SecurityHub/Integrations/AWS_SecurityHub/AWS_SecurityHub.py:156:26: SIM910 [*] Use `args.get('product_fields_value')` instead of `args.get('product_fields_value', None)`
+ Packs/AWS-SecurityHub/Integrations/AWS_SecurityHub/AWS_SecurityHub.py:157:31: SIM910 [*] Use `args.get('product_fields_comparison')` instead of `args.get('product_fields_comparison', None)`
+ Packs/AWS-SecurityHub/Integrations/AWS_SecurityHub/AWS_SecurityHub.py:161:26: SIM910 [*] Use `args.get('product_name_value')` instead of `args.get('product_name_value', None)`
+ Packs/AWS-SecurityHub/Integrations/AWS_SecurityHub/AWS_SecurityHub.py:162:31: SIM910 [*] Use `args.get('product_name_comparison')` instead of `args.get('product_name_comparison', None)`
+ Packs/AWS-SecurityHub/Integrations/AWS_SecurityHub/AWS_SecurityHub.py:166:26: SIM910 [*] Use `args.get('company_name_value')` instead of `args.get('company_name_value', None)`
+ Packs/AWS-SecurityHub/Integrations/AWS_SecurityHub/AWS_SecurityHub.py:167:31: SIM910 [*] Use `args.get('company_name_comparison')` instead of `args.get('company_name_comparison', None)`
+ Packs/AWS-SecurityHub/Integrations/AWS_SecurityHub/AWS_SecurityHub.py:171:24: SIM910 [*] Use `args.get('user_defined_fields_key')` instead of `args.get('user_defined_fields_key', None)`
+ Packs/AWS-SecurityHub/Integrations/AWS_SecurityHub/AWS_SecurityHub.py:172:26: SIM910 [*] Use `args.get('user_defined_fields_value')` instead of `args.get('user_defined_fields_value', None)`
+ Packs/AWS-SecurityHub/Integrations/AWS_SecurityHub/AWS_SecurityHub.py:173:31: SIM910 [*] Use `args.get('user_defined_fields_comparison')` instead of `args.get('user_defined_fields_comparison', None)`
+ Packs/AWS-SecurityHub/Integrations/AWS_SecurityHub/AWS_SecurityHub.py:177:26: SIM910 [*] Use `args.get('malware_name_value')` instead of `args.get('malware_name_value', None)`
+ Packs/AWS-SecurityHub/Integrations/AWS_SecurityHub/AWS_SecurityHub.py:178:31: SIM910 [*] Use `args.get('malware_name_comparison')` instead of `args.get('malware_name_comparison', None)`
+ Packs/AWS-SecurityHub/Integrations/AWS_SecurityHub/AWS_SecurityHub.py:182:26: SIM910 [*] Use `args.get('malware_type_value')` instead of `args.get('malware_type_value', None)`
+ Packs/AWS-SecurityHub/Integrations/AWS_SecurityHub/AWS_SecurityHub.py:183:31: SIM910 [*] Use `args.get('malware_type_comparison')` instead of `args.get('malware_type_comparison', None)`
+ Packs/AWS-SecurityHub/Integrations/AWS_SecurityHub/AWS_SecurityHub.py:187:26: SIM910 [*] Use `args.get('malware_path_value')` instead of `args.get('malware_path_value', None)`
+ Packs/AWS-SecurityHub/Integrations/AWS_SecurityHub/AWS_SecurityHub.py:188:31: SIM910 [*] Use `args.get('malware_path_comparison')` instead of `args.get('malware_path_comparison', None)`
+ Packs/AWS-SecurityHub/Integrations/AWS_SecurityHub/AWS_SecurityHub.py:192:26: SIM910 [*] Use `args.get('malware_state_value')` instead of `args.get('malware_state_value', None)`
... 756 additional changes omitted for project

ibis-project/ibis (+6 -0 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --preview

+ ibis/backends/pandas/execution/temporal.py:123:11: SIM910 [*] Use `OFFSET_CLASS.get(unit)` instead of `OFFSET_CLASS.get(unit, None)`
+ ibis/backends/pandas/execution/temporal.py:135:11: SIM910 [*] Use `OFFSET_CLASS.get(unit)` instead of `OFFSET_CLASS.get(unit, None)`
+ ibis/backends/pandas/execution/temporal.py:147:11: SIM910 [*] Use `OFFSET_CLASS.get(unit)` instead of `OFFSET_CLASS.get(unit, None)`
+ ibis/backends/pandas/execution/temporal.py:159:11: SIM910 [*] Use `OFFSET_CLASS.get(unit)` instead of `OFFSET_CLASS.get(unit, None)`
+ ibis/backends/postgres/datatypes.py:76:25: SIM910 [*] Use `_postgres_interval_fields.get(field)` instead of `_postgres_interval_fields.get(field, None)`
+ ibis/backends/tests/test_map.py:194:46: SIM910 [*] Use `value.get(x)` instead of `value.get(x, None)`

... Truncated remaining completed projected reports due to GitHub comment length restrictions

Changes by rule (1 rules affected)

code total + violation - violation + fix - fix
SIM910 842 842 0 0 0

@charliermarsh
Copy link
Member Author

This needs to be gated behind preview.

@charliermarsh charliermarsh added rule Implementing or modifying a lint rule preview Related to preview mode features and removed bug Something isn't working labels Nov 19, 2023
@charliermarsh charliermarsh enabled auto-merge (squash) November 19, 2023 00:17
@charliermarsh charliermarsh merged commit 8b86e80 into main Nov 19, 2023
16 checks passed
@charliermarsh charliermarsh deleted the charlie/SIM9 branch November 19, 2023 00:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
preview Related to preview mode features rule Implementing or modifying a lint rule
Projects
None yet
Development

Successfully merging this pull request may close these issues.

SIM910 only applies to dictionary literals
1 participant