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

Emit possibly-used-before-assignment after if/else switches #8952

Merged
merged 20 commits into from
Apr 17, 2024

Conversation

jacobtylerwalls
Copy link
Member

Type of Changes

Type
✨ New feature

Description

Closes #1727

@jacobtylerwalls jacobtylerwalls added Enhancement ✨ Improvement to a component False Negative 🦋 No message is emitted but something is wrong with the code labels Aug 13, 2023
@jacobtylerwalls jacobtylerwalls added this to the 3.0.0b1 milestone Aug 13, 2023
@github-actions

This comment has been minimized.

@jacobtylerwalls
Copy link
Member Author

Many of the new messages in the primer look like reasonable reliances on repeating a variation of the same of the if condition (which we already test) but just not exactly. Probably worth a new possibly-used-before-assignment after all?

@Pierre-Sassoulas Pierre-Sassoulas added the Needs decision 🔒 Needs a decision before implemention or rejection label Aug 31, 2023
@jacobtylerwalls jacobtylerwalls removed this from the 3.0.0b1 milestone Sep 3, 2023
@jacobtylerwalls jacobtylerwalls added this to the 3.1.0 milestone Jan 20, 2024
@milosivanovic
Copy link

@jacobtylerwalls I see this PR is still a draft - is it completed and ready for review?

@jacobtylerwalls
Copy link
Member Author

jacobtylerwalls commented Jan 20, 2024

I'll add some tests and then open it for review 👍

EDIT: there's one test revealing an issue. I may not have time to debug it in the near term. Help appreciated!

This comment has been minimized.

@Pierre-Sassoulas
Copy link
Member

I looked at the three astroid new messages and they look like they could very well be actual error (or if that's not the case it would be for non obvious reasons related to how the ast is constructed or how the code is called). Generally we favor false negatives over false positives but the ratio seems good in this case. Although, there's more than a hundred such examples to review to have the real ratio, which I don't see myself doing anytime soon...

@jacobtylerwalls

This comment was marked as resolved.

This comment has been minimized.

@jacobtylerwalls jacobtylerwalls marked this pull request as ready for review February 23, 2024 23:58
Copy link

codecov bot commented Feb 24, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 95.81%. Comparing base (9dbf3df) to head (b362668).
Report is 26 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #8952      +/-   ##
==========================================
- Coverage   95.82%   95.81%   -0.01%     
==========================================
  Files         173      173              
  Lines       18797    18825      +28     
==========================================
+ Hits        18013    18038      +25     
- Misses        784      787       +3     
Files Coverage Δ
pylint/checkers/variables.py 97.35% <100.00%> (-0.05%) ⬇️

... and 5 files with indirect coverage changes

This comment has been minimized.

@Pierre-Sassoulas
Copy link
Member

I like a new message because it's easier to configure pylint for it for a user. It get raised you disable it (thus we can make it opt-out without too much pain), or you need to learn about it and then enable it. Options, you need to at least learn what the possible choices are and that it exists.

@milosivanovic
Copy link

I think a new message is ideal. There will be situations where it's not possible for the linter to know if it's truly used before assignment. The point of the linter is to help the user as much as possible, in the way that they would like to be helped. For users who don't disable the new message type, pylint can inform of potential-but-maybe-not-actual issues without bothering other users who prefer to take on more risk or just want less noise.

@Pierre-Sassoulas Pierre-Sassoulas removed the Needs decision 🔒 Needs a decision before implemention or rejection label Feb 26, 2024

This comment has been minimized.

Comment on lines -19 to 21
if x == a: # [used-before-assignment]
if x == a: # [possibly-used-before-assignment]
if x > 3:
x = 2 # [redefined-outer-name]
Copy link
Member Author

Choose a reason for hiding this comment

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

This is kind of a shame, but I can live with it.

This comment has been minimized.

This comment has been minimized.

This comment has been minimized.

@jacobtylerwalls jacobtylerwalls changed the title Emit used-before-assignment after if/else switches Emit possibly-used-before-assignment after if/else switches Apr 9, 2024

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.

Only some nitpicks from me :) I think the primer looks great. Testament to the code quality in pygame is the fact that we can immediately see that it's a false positive that we raise (but not unjustified of course), when some variable is only defined on windows because the function is named initsysfonts_win32 (https://github.com/pygame/pygame/blob/9cb30af95d9143dbbf52c13817753c54d5d2f5fe/src_py/sysfont.py#L67).

Great addition that will clarify both used-before-assignment and possibly-used-before-assignment !

tests/test_func.py Outdated Show resolved Hide resolved
pylint/checkers/variables.py Outdated Show resolved Hide resolved
doc/data/messages/p/possibly-used-before-assignment/bad.py Outdated Show resolved Hide resolved
Co-authored-by: Pierre Sassoulas <[email protected]>
Copy link
Contributor

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

Effect on astroid:
The following messages are now emitted:

  1. possibly-used-before-assignment:
    Possibly using variable 'default_offset' before assignment
    https://github.com/pylint-dev/astroid/blob/7a3b482b9673243d2ccc895672eb1e452f5daa82/astroid/nodes/node_classes.py#L1074

Effect on home-assistant:
The following messages are now emitted:

  1. possibly-used-before-assignment:
    Possibly using variable 'start' before assignment
    https://github.com/home-assistant/core/blob/11ff00f6377325f3ad5a1f7abcaa6ce701fc3c93/homeassistant/loader.py#L969
  2. possibly-used-before-assignment:
    Possibly using variable 'start' before assignment
    https://github.com/home-assistant/core/blob/11ff00f6377325f3ad5a1f7abcaa6ce701fc3c93/homeassistant/loader.py#L1159
  3. possibly-used-before-assignment:
    Possibly using variable 'data_schema' before assignment
    https://github.com/home-assistant/core/blob/11ff00f6377325f3ad5a1f7abcaa6ce701fc3c93/homeassistant/components/awair/config_flow.py#L187
  4. used-before-assignment:
    Using variable 'mower_id' before assignment
    https://github.com/home-assistant/core/blob/11ff00f6377325f3ad5a1f7abcaa6ce701fc3c93/homeassistant/components/husqvarna_automower/diagnostics.py#L47
  5. possibly-used-before-assignment:
    Possibly using variable 'descriptive_capacity_remaining' before assignment
    https://github.com/home-assistant/core/blob/11ff00f6377325f3ad5a1f7abcaa6ce701fc3c93/homeassistant/components/google_assistant/trait.py#L830
  6. possibly-used-before-assignment:
    Possibly using variable 'map_data' before assignment
    https://github.com/home-assistant/core/blob/11ff00f6377325f3ad5a1f7abcaa6ce701fc3c93/homeassistant/components/neato/camera.py#L92
  7. possibly-used-before-assignment:
    Possibly using variable 'service' before assignment
    https://github.com/home-assistant/core/blob/11ff00f6377325f3ad5a1f7abcaa6ce701fc3c93/homeassistant/components/climate/device_action.py#L99
  8. possibly-used-before-assignment:
    Possibly using variable 'translation_key' before assignment
    https://github.com/home-assistant/core/blob/11ff00f6377325f3ad5a1f7abcaa6ce701fc3c93/homeassistant/components/climate/__init__.py#L700
  9. possibly-used-before-assignment:
    Possibly using variable 'saved_queue_position' before assignment
    https://github.com/home-assistant/core/blob/11ff00f6377325f3ad5a1f7abcaa6ce701fc3c93/homeassistant/components/forked_daapd/media_player.py#L791
  10. undefined-variable:
    Undefined variable 'other_sources'
    https://github.com/home-assistant/core/blob/11ff00f6377325f3ad5a1f7abcaa6ce701fc3c93/homeassistant/components/forked_daapd/media_player.py#L863
  11. possibly-used-before-assignment:
    Possibly using variable 'name' before assignment
    https://github.com/home-assistant/core/blob/11ff00f6377325f3ad5a1f7abcaa6ce701fc3c93/homeassistant/components/steam_online/config_flow.py#L80
  12. used-before-assignment:
    Using variable 'hub_location' before assignment
    https://github.com/home-assistant/core/blob/11ff00f6377325f3ad5a1f7abcaa6ce701fc3c93/homeassistant/components/plex/media_browser.py#L169
  13. possibly-used-before-assignment:
    Possibly using variable 'year' before assignment
    https://github.com/home-assistant/core/blob/11ff00f6377325f3ad5a1f7abcaa6ce701fc3c93/homeassistant/components/homeassistant/triggers/time.py#L116
  14. possibly-used-before-assignment:
    Possibly using variable 'month' before assignment
    https://github.com/home-assistant/core/blob/11ff00f6377325f3ad5a1f7abcaa6ce701fc3c93/homeassistant/components/homeassistant/triggers/time.py#L117
  15. possibly-used-before-assignment:
    Possibly using variable 'day' before assignment
    https://github.com/home-assistant/core/blob/11ff00f6377325f3ad5a1f7abcaa6ce701fc3c93/homeassistant/components/homeassistant/triggers/time.py#L118
  16. possibly-used-before-assignment:
    Possibly using variable 'device' before assignment
    https://github.com/home-assistant/core/blob/11ff00f6377325f3ad5a1f7abcaa6ce701fc3c93/homeassistant/components/alarmdecoder/config_flow.py#L118
  17. possibly-used-before-assignment:
    Possibly using variable 'title' before assignment
    https://github.com/home-assistant/core/blob/11ff00f6377325f3ad5a1f7abcaa6ce701fc3c93/homeassistant/components/alarmdecoder/config_flow.py#L127
  18. possibly-used-before-assignment:
    Possibly using variable 'schema' before assignment
    https://github.com/home-assistant/core/blob/11ff00f6377325f3ad5a1f7abcaa6ce701fc3c93/homeassistant/components/alarmdecoder/config_flow.py#L152
  19. possibly-used-before-assignment:
    Possibly using variable 'controller' before assignment
    https://github.com/home-assistant/core/blob/11ff00f6377325f3ad5a1f7abcaa6ce701fc3c93/homeassistant/components/alarmdecoder/__init__.py#L61
  20. possibly-used-before-assignment:
    Possibly using variable 'blueprint_inputs' before assignment
    https://github.com/home-assistant/core/blob/11ff00f6377325f3ad5a1f7abcaa6ce701fc3c93/homeassistant/components/script/config.py#L134
  21. possibly-used-before-assignment:
    Possibly using variable 'pywemo_humidity' before assignment
    https://github.com/home-assistant/core/blob/11ff00f6377325f3ad5a1f7abcaa6ce701fc3c93/homeassistant/components/wemo/fan.py#L167
  22. possibly-used-before-assignment:
    Possibly using variable 'event_text' before assignment
    https://github.com/home-assistant/core/blob/11ff00f6377325f3ad5a1f7abcaa6ce701fc3c93/homeassistant/components/unifiprotect/media_source.py#L456
  23. possibly-used-before-assignment:
    Possibly using variable 'recording_start' before assignment
    https://github.com/home-assistant/core/blob/11ff00f6377325f3ad5a1f7abcaa6ce701fc3c93/homeassistant/components/unifiprotect/media_source.py#L606
  24. possibly-used-before-assignment:
    Possibly using variable 'state' before assignment
    https://github.com/home-assistant/core/blob/11ff00f6377325f3ad5a1f7abcaa6ce701fc3c93/homeassistant/components/omnilogic/sensor.py#L154
  25. possibly-used-before-assignment:
    Possibly using variable 'new_sleep_period' before assignment
    https://github.com/home-assistant/core/blob/11ff00f6377325f3ad5a1f7abcaa6ce701fc3c93/homeassistant/components/shelly/coordinator.py#L189
  26. possibly-used-before-assignment:
    Possibly using variable 'service' before assignment
    https://github.com/home-assistant/core/blob/11ff00f6377325f3ad5a1f7abcaa6ce701fc3c93/homeassistant/components/cover/device_action.py#L145
  27. possibly-used-before-assignment:
    Possibly using variable 'state' before assignment
    https://github.com/home-assistant/core/blob/11ff00f6377325f3ad5a1f7abcaa6ce701fc3c93/homeassistant/components/cover/device_condition.py#L141
  28. possibly-used-before-assignment:
    Possibly using variable 'position_attr' before assignment
    https://github.com/home-assistant/core/blob/11ff00f6377325f3ad5a1f7abcaa6ce701fc3c93/homeassistant/components/cover/device_condition.py#L158
  29. possibly-used-before-assignment:
    Possibly using variable 'service' before assignment
    https://github.com/home-assistant/core/blob/11ff00f6377325f3ad5a1f7abcaa6ce701fc3c93/homeassistant/components/cover/reproduce_state.py#L88
  30. possibly-used-before-assignment:
    Possibly using variable 'to_state' before assignment
    https://github.com/home-assistant/core/blob/11ff00f6377325f3ad5a1f7abcaa6ce701fc3c93/homeassistant/components/cover/device_trigger.py#L161
  31. possibly-used-before-assignment:
    Possibly using variable 'position' before assignment
    https://github.com/home-assistant/core/blob/11ff00f6377325f3ad5a1f7abcaa6ce701fc3c93/homeassistant/components/cover/device_trigger.py#L178
  32. possibly-used-before-assignment:
    Possibly using variable 'service' before assignment
    https://github.com/home-assistant/core/blob/11ff00f6377325f3ad5a1f7abcaa6ce701fc3c93/homeassistant/components/remote/reproduce_state.py#L56
  33. possibly-used-before-assignment:
    Possibly using variable 'service' before assignment
    https://github.com/home-assistant/core/blob/11ff00f6377325f3ad5a1f7abcaa6ce701fc3c93/homeassistant/components/alarm_control_panel/device_action.py#L120
  34. possibly-used-before-assignment:
    Possibly using variable 'state' before assignment
    https://github.com/home-assistant/core/blob/11ff00f6377325f3ad5a1f7abcaa6ce701fc3c93/homeassistant/components/alarm_control_panel/device_condition.py#L131
  35. possibly-used-before-assignment:
    Possibly using variable 'service' before assignment
    https://github.com/home-assistant/core/blob/11ff00f6377325f3ad5a1f7abcaa6ce701fc3c93/homeassistant/components/alarm_control_panel/reproduce_state.py#L84
  36. possibly-used-before-assignment:
    Possibly using variable 'to_state' before assignment
    https://github.com/home-assistant/core/blob/11ff00f6377325f3ad5a1f7abcaa6ce701fc3c93/homeassistant/components/alarm_control_panel/device_trigger.py#L149
  37. possibly-used-before-assignment:
    Possibly using variable 'max_bind_vars' before assignment
    https://github.com/home-assistant/core/blob/11ff00f6377325f3ad5a1f7abcaa6ce701fc3c93/homeassistant/components/recorder/util.py#L605
  38. possibly-used-before-assignment:
    Possibly using variable 'db_runs' before assignment
    https://github.com/home-assistant/core/blob/11ff00f6377325f3ad5a1f7abcaa6ce701fc3c93/homeassistant/components/recorder/system_health/__init__.py#L75
  39. possibly-used-before-assignment:
    Possibly using variable 'service' before assignment
    https://github.com/home-assistant/core/blob/11ff00f6377325f3ad5a1f7abcaa6ce701fc3c93/homeassistant/components/alert/reproduce_state.py#L54
  40. used-before-assignment:
    Using variable 'value_type' before assignment
    https://github.com/home-assistant/core/blob/11ff00f6377325f3ad5a1f7abcaa6ce701fc3c93/homeassistant/components/mysensors/climate.py#L178
  41. possibly-used-before-assignment:
    Possibly using variable 'dev_model' before assignment
    https://github.com/home-assistant/core/blob/11ff00f6377325f3ad5a1f7abcaa6ce701fc3c93/homeassistant/components/roon/media_player.py#L168
  42. possibly-used-before-assignment:
    Possibly using variable 'dev_model' before assignment
    https://github.com/home-assistant/core/blob/11ff00f6377325f3ad5a1f7abcaa6ce701fc3c93/homeassistant/components/roon/event.py#L71
  43. possibly-used-before-assignment:
    Possibly using variable 'unique_id' before assignment
    https://github.com/home-assistant/core/blob/11ff00f6377325f3ad5a1f7abcaa6ce701fc3c93/homeassistant/components/islamic_prayer_times/__init__.py#L67
  44. possibly-used-before-assignment:
    Possibly using variable 'cmd' before assignment
    https://github.com/home-assistant/core/blob/11ff00f6377325f3ad5a1f7abcaa6ce701fc3c93/homeassistant/components/rflink/__init__.py#L548
  45. possibly-used-before-assignment:
    Possibly using variable 'parameters' before assignment
    https://github.com/home-assistant/core/blob/11ff00f6377325f3ad5a1f7abcaa6ce701fc3c93/homeassistant/components/dialogflow/__init__.py#L92
  46. possibly-used-before-assignment:
    Possibly using variable 'valid_units' before assignment
    https://github.com/home-assistant/core/blob/11ff00f6377325f3ad5a1f7abcaa6ce701fc3c93/homeassistant/components/energy/sensor.py#L342
  47. possibly-used-before-assignment:
    Possibly using variable 'default_price_unit' before assignment
    https://github.com/home-assistant/core/blob/11ff00f6377325f3ad5a1f7abcaa6ce701fc3c93/homeassistant/components/energy/sensor.py#L343
  48. possibly-used-before-assignment:
    Possibly using variable 'service' before assignment
    https://github.com/home-assistant/core/blob/11ff00f6377325f3ad5a1f7abcaa6ce701fc3c93/homeassistant/components/automation/reproduce_state.py#L56
  49. possibly-used-before-assignment:
    Possibly using variable 'blueprint_inputs' before assignment
    https://github.com/home-assistant/core/blob/11ff00f6377325f3ad5a1f7abcaa6ce701fc3c93/homeassistant/components/automation/config.py#L102
  50. possibly-used-before-assignment:
    Possibly using variable 'tado_sensor_data' before assignment
    https://github.com/home-assistant/core/blob/11ff00f6377325f3ad5a1f7abcaa6ce701fc3c93/homeassistant/components/tado/sensor.py#L280
  51. possibly-used-before-assignment:
    Possibly using variable 'alarm_state' before assignment
    https://github.com/home-assistant/core/blob/11ff00f6377325f3ad5a1f7abcaa6ce701fc3c93/homeassistant/components/yale_smart_alarm/alarm_control_panel.py#L94
  52. possibly-used-before-assignment:
    Possibly using variable 'lock_state' before assignment
    https://github.com/home-assistant/core/blob/11ff00f6377325f3ad5a1f7abcaa6ce701fc3c93/homeassistant/components/yale_smart_alarm/lock.py#L91
  53. possibly-used-before-assignment:
    Possibly using variable 'bridge_attr' before assignment
    https://github.com/home-assistant/core/blob/11ff00f6377325f3ad5a1f7abcaa6ce701fc3c93/homeassistant/components/dynalite/__init__.py#L79
  54. possibly-used-before-assignment:
    Possibly using variable 'time' before assignment
    https://github.com/home-assistant/core/blob/11ff00f6377325f3ad5a1f7abcaa6ce701fc3c93/homeassistant/components/nws/weather.py#L235
  55. possibly-used-before-assignment:
    Possibly using variable 'service' before assignment
    https://github.com/home-assistant/core/blob/11ff00f6377325f3ad5a1f7abcaa6ce701fc3c93/homeassistant/components/switch/reproduce_state.py#L56
  56. possibly-used-before-assignment:
    Possibly using variable 'service' before assignment
    https://github.com/home-assistant/core/blob/11ff00f6377325f3ad5a1f7abcaa6ce701fc3c93/homeassistant/components/timer/reproduce_state.py#L65
  57. possibly-used-before-assignment:
    Possibly using variable 'service' before assignment
    https://github.com/home-assistant/core/blob/11ff00f6377325f3ad5a1f7abcaa6ce701fc3c93/homeassistant/components/water_heater/device_action.py#L79
  58. possibly-used-before-assignment:
    Possibly using variable 'offset_value' before assignment
    https://github.com/home-assistant/core/blob/11ff00f6377325f3ad5a1f7abcaa6ce701fc3c93/homeassistant/components/google/calendar.py#L483
  59. possibly-used-before-assignment:
    Possibly using variable 'blackbird' before assignment
    https://github.com/home-assistant/core/blob/11ff00f6377325f3ad5a1f7abcaa6ce701fc3c93/homeassistant/components/blackbird/media_player.py#L108
  60. possibly-used-before-assignment:
    Possibly using variable 'service' before assignment
    https://github.com/home-assistant/core/blob/11ff00f6377325f3ad5a1f7abcaa6ce701fc3c93/homeassistant/components/lock/device_action.py#L90
  61. possibly-used-before-assignment:
    Possibly using variable 'service' before assignment
    https://github.com/home-assistant/core/blob/11ff00f6377325f3ad5a1f7abcaa6ce701fc3c93/homeassistant/components/lock/reproduce_state.py#L58
  62. possibly-used-before-assignment:
    Possibly using variable 'service' before assignment
    https://github.com/home-assistant/core/blob/11ff00f6377325f3ad5a1f7abcaa6ce701fc3c93/homeassistant/components/vacuum/device_action.py#L78
  63. possibly-used-before-assignment:
    Possibly using variable 'service' before assignment
    https://github.com/home-assistant/core/blob/11ff00f6377325f3ad5a1f7abcaa6ce701fc3c93/homeassistant/components/vacuum/reproduce_state.py#L88
  64. possibly-used-before-assignment:
    Possibly using variable 'thread_dataset_channel' before assignment
    https://github.com/home-assistant/core/blob/11ff00f6377325f3ad5a1f7abcaa6ce701fc3c93/homeassistant/components/otbr/websocket_api.py#L172
  65. possibly-used-before-assignment:
    Possibly using variable 'power' before assignment
    https://github.com/home-assistant/core/blob/11ff00f6377325f3ad5a1f7abcaa6ce701fc3c93/homeassistant/components/emulated_kasa/__init__.py#L142
  66. possibly-used-before-assignment:
    Possibly using variable 'image_type' before assignment
    https://github.com/home-assistant/core/blob/11ff00f6377325f3ad5a1f7abcaa6ce701fc3c93/homeassistant/components/color_extractor/__init__.py#L86
  67. possibly-used-before-assignment:
    Possibly using variable 'color' before assignment
    https://github.com/home-assistant/core/blob/11ff00f6377325f3ad5a1f7abcaa6ce701fc3c93/homeassistant/components/color_extractor/__init__.py#L92
  68. possibly-used-before-assignment:
    Possibly using variable 'pull_gpio_up' before assignment
    https://github.com/home-assistant/core/blob/11ff00f6377325f3ad5a1f7abcaa6ce701fc3c93/homeassistant/components/remote_rpi_gpio/__init__.py#L39
  69. possibly-used-before-assignment:
    Possibly using variable 'auth_type' before assignment
    https://github.com/home-assistant/core/blob/11ff00f6377325f3ad5a1f7abcaa6ce701fc3c93/homeassistant/components/http/auth.py#L279
  70. possibly-used-before-assignment:
    Possibly using variable 'response' before assignment
    https://github.com/home-assistant/core/blob/11ff00f6377325f3ad5a1f7abcaa6ce701fc3c93/homeassistant/components/itunes/media_player.py#L74
  71. possibly-used-before-assignment:
    Possibly using variable 'duration' before assignment
    https://github.com/home-assistant/core/blob/11ff00f6377325f3ad5a1f7abcaa6ce701fc3c93/homeassistant/components/yeelight/light.py#L734
  72. possibly-used-before-assignment:
    Possibly using variable 'count' before assignment
    https://github.com/home-assistant/core/blob/11ff00f6377325f3ad5a1f7abcaa6ce701fc3c93/homeassistant/components/yeelight/light.py#L742
  73. possibly-used-before-assignment:
    Possibly using variable 'breaks_in_ha_version' before assignment
    https://github.com/home-assistant/core/blob/11ff00f6377325f3ad5a1f7abcaa6ce701fc3c93/homeassistant/helpers/deprecation.py#L303
  74. possibly-used-before-assignment:
    Possibly using variable 'start' before assignment
    https://github.com/home-assistant/core/blob/11ff00f6377325f3ad5a1f7abcaa6ce701fc3c93/homeassistant/helpers/update_coordinator.py#L398

The following messages are no longer emitted:

  1. used-before-assignment:
    Using variable 'image_type' before assignment
    https://github.com/home-assistant/core/blob/11ff00f6377325f3ad5a1f7abcaa6ce701fc3c93/homeassistant/components/color_extractor/__init__.py#L86

Effect on pygame:
The following messages are now emitted:

  1. used-before-assignment:
    Using variable '_winreg' before assignment
    https://github.com/pygame/pygame/blob/c85b24c5ef8903b0b7c989c9351db9ceda4e2fa1/src_py/sysfont.py#L67
  2. possibly-used-before-assignment:
    Possibly using variable 'subprocess' before assignment
    https://github.com/pygame/pygame/blob/c85b24c5ef8903b0b7c989c9351db9ceda4e2fa1/src_py/sysfont.py#L214

Effect on black:
The following messages are now emitted:

  1. possibly-used-before-assignment:
    Possibly using variable '_prefix' before assignment
    https://github.com/psf/black/blob/735733b20516f2ea849d20f585555bf41a40311f/src/blib2to3/pgen2/driver.py#L168

Effect on music21:
The following messages are now emitted:

  1. possibly-used-before-assignment:
    Possibly using variable 'intervals' before assignment
    https://github.com/cuthbertLab/music21/blob/d33ca3c73ad3206b0fe4e239406217baab8fcf4e/music21/pitch.py#L584
  2. possibly-used-before-assignment:
    Possibly using variable 'bass' before assignment
    https://github.com/cuthbertLab/music21/blob/d33ca3c73ad3206b0fe4e239406217baab8fcf4e/music21/figuredBass/resolution.py#L105
  3. possibly-used-before-assignment:
    Possibly using variable 'root' before assignment
    https://github.com/cuthbertLab/music21/blob/d33ca3c73ad3206b0fe4e239406217baab8fcf4e/music21/figuredBass/resolution.py#L106
  4. possibly-used-before-assignment:
    Possibly using variable 'fifth' before assignment
    https://github.com/cuthbertLab/music21/blob/d33ca3c73ad3206b0fe4e239406217baab8fcf4e/music21/figuredBass/resolution.py#L107
  5. possibly-used-before-assignment:
    Possibly using variable 'other' before assignment
    https://github.com/cuthbertLab/music21/blob/d33ca3c73ad3206b0fe4e239406217baab8fcf4e/music21/figuredBass/resolution.py#L108
  6. possibly-used-before-assignment:
    Possibly using variable 'bass' before assignment
    https://github.com/cuthbertLab/music21/blob/d33ca3c73ad3206b0fe4e239406217baab8fcf4e/music21/figuredBass/resolution.py#L175
  7. possibly-used-before-assignment:
    Possibly using variable 'root' before assignment
    https://github.com/cuthbertLab/music21/blob/d33ca3c73ad3206b0fe4e239406217baab8fcf4e/music21/figuredBass/resolution.py#L176
  8. possibly-used-before-assignment:
    Possibly using variable 'fifth' before assignment
    https://github.com/cuthbertLab/music21/blob/d33ca3c73ad3206b0fe4e239406217baab8fcf4e/music21/figuredBass/resolution.py#L177
  9. possibly-used-before-assignment:
    Possibly using variable 'other' before assignment
    https://github.com/cuthbertLab/music21/blob/d33ca3c73ad3206b0fe4e239406217baab8fcf4e/music21/figuredBass/resolution.py#L178
  10. possibly-used-before-assignment:
    Possibly using variable 'bass' before assignment
    https://github.com/cuthbertLab/music21/blob/d33ca3c73ad3206b0fe4e239406217baab8fcf4e/music21/figuredBass/resolution.py#L246
  11. possibly-used-before-assignment:
    Possibly using variable 'root' before assignment
    https://github.com/cuthbertLab/music21/blob/d33ca3c73ad3206b0fe4e239406217baab8fcf4e/music21/figuredBass/resolution.py#L247
  12. possibly-used-before-assignment:
    Possibly using variable 'fifth' before assignment
    https://github.com/cuthbertLab/music21/blob/d33ca3c73ad3206b0fe4e239406217baab8fcf4e/music21/figuredBass/resolution.py#L248
  13. possibly-used-before-assignment:
    Possibly using variable 'other' before assignment
    https://github.com/cuthbertLab/music21/blob/d33ca3c73ad3206b0fe4e239406217baab8fcf4e/music21/figuredBass/resolution.py#L249

Effect on pytest:
The following messages are now emitted:

  1. possibly-used-before-assignment:
    Possibly using variable 'scoped_item_path' before assignment
    https://github.com/pytest-dev/pytest/blob/b56b294f54268b45f611917e6d1fd577a2f848be/src/_pytest/fixtures.py#L198
  2. possibly-used-before-assignment:
    Possibly using variable 'reprentry' before assignment
    https://github.com/pytest-dev/pytest/blob/b56b294f54268b45f611917e6d1fd577a2f848be/src/_pytest/reports.py#L573
  3. possibly-used-before-assignment:
    Possibly using variable 'cond' before assignment
    https://github.com/pytest-dev/pytest/blob/b56b294f54268b45f611917e6d1fd577a2f848be/src/_pytest/assertion/rewrite.py#L1007
  4. possibly-used-before-assignment:
    Possibly using variable 'source' before assignment
    https://github.com/pytest-dev/pytest/blob/b56b294f54268b45f611917e6d1fd577a2f848be/src/_pytest/config/__init__.py#L1355

Effect on django:
The following messages are now emitted:

  1. used-before-assignment:
    Using variable 'silent' before assignment
    https://github.com/django/django/blob/47c608202a58c8120d049c98d5d27c4609551d33/django/template/defaulttags.py#L662
  2. possibly-used-before-assignment:
    Possibly using variable 'content' before assignment
    https://github.com/django/django/blob/47c608202a58c8120d049c98d5d27c4609551d33/django/core/management/commands/makemessages.py#L126
  3. possibly-used-before-assignment:
    Possibly using variable 'sid' before assignment
    https://github.com/django/django/blob/47c608202a58c8120d049c98d5d27c4609551d33/django/db/transaction.py#L245
  4. possibly-used-before-assignment:
    Possibly using variable 'confirm' before assignment
    https://github.com/django/django/blob/47c608202a58c8120d049c98d5d27c4609551d33/django/db/backends/sqlite3/creation.py#L43
  5. possibly-used-before-assignment:
    Possibly using variable 'confirm' before assignment
    https://github.com/django/django/blob/47c608202a58c8120d049c98d5d27c4609551d33/django/db/backends/oracle/creation.py#L48
  6. possibly-used-before-assignment:
    Possibly using variable 'confirm' before assignment
    https://github.com/django/django/blob/47c608202a58c8120d049c98d5d27c4609551d33/django/db/backends/oracle/creation.py#L174
  7. possibly-used-before-assignment:
    Possibly using variable 'confirm' before assignment
    https://github.com/django/django/blob/47c608202a58c8120d049c98d5d27c4609551d33/django/db/backends/base/creation.py#L217
  8. possibly-used-before-assignment:
    Possibly using variable 'collected_sql_before' before assignment
    https://github.com/django/django/blob/47c608202a58c8120d049c98d5d27c4609551d33/django/db/migrations/migration.py#L135
  9. possibly-used-before-assignment:
    Possibly using variable 'collected_sql_before' before assignment
    https://github.com/django/django/blob/47c608202a58c8120d049c98d5d27c4609551d33/django/db/migrations/migration.py#L196
  10. used-before-assignment:
    Using variable 'rel_obj' before assignment
    https://github.com/django/django/blob/47c608202a58c8120d049c98d5d27c4609551d33/django/db/models/base.py#L542
  11. possibly-used-before-assignment:
    Possibly using variable 'progress_interval' before assignment
    https://github.com/django/django/blob/47c608202a58c8120d049c98d5d27c4609551d33/django/contrib/gis/utils/layermapping.py#L686

Effect on pandas:
The following messages are now emitted:

  1. possibly-used-before-assignment:
    Possibly using variable 'new_index' before assignment
    https://github.com/pandas-dev/pandas/blob/888b6bc1bb3fdf203dda64e50336db4eb9b1e778/pandas/core/generic.py#L4107
  2. possibly-used-before-assignment:
    Possibly using variable 'arr_mask' before assignment
    https://github.com/pandas-dev/pandas/blob/888b6bc1bb3fdf203dda64e50336db4eb9b1e778/pandas/core/missing.py#L125
  3. possibly-used-before-assignment:
    Possibly using variable 'idxpos' before assignment
    https://github.com/pandas-dev/pandas/blob/888b6bc1bb3fdf203dda64e50336db4eb9b1e778/pandas/core/missing.py#L252
  4. possibly-used-before-assignment:
    Possibly using variable 'pa' before assignment
    https://github.com/pandas-dev/pandas/blob/888b6bc1bb3fdf203dda64e50336db4eb9b1e778/pandas/core/arrays/string_arrow.py#L135
  5. possibly-used-before-assignment:
    Possibly using variable 'pc' before assignment
    https://github.com/pandas-dev/pandas/blob/888b6bc1bb3fdf203dda64e50336db4eb9b1e778/pandas/core/arrays/string_arrow.py#L138
  6. possibly-used-before-assignment:
    Possibly using variable 'fallback_performancewarning' before assignment
    https://github.com/pandas-dev/pandas/blob/888b6bc1bb3fdf203dda64e50336db4eb9b1e778/pandas/core/arrays/string_arrow.py#L349
  7. possibly-used-before-assignment:
    Possibly using variable 'pc' before assignment
    https://github.com/pandas-dev/pandas/blob/888b6bc1bb3fdf203dda64e50336db4eb9b1e778/pandas/core/arrays/_arrow_string_mixins.py#L33
  8. possibly-used-before-assignment:
    Possibly using variable 'pa' before assignment
    https://github.com/pandas-dev/pandas/blob/888b6bc1bb3fdf203dda64e50336db4eb9b1e778/pandas/core/arrays/_arrow_string_mixins.py#L60
  9. possibly-used-before-assignment:
    Possibly using variable 'ARROW_CMP_FUNCS' before assignment
    https://github.com/pandas-dev/pandas/blob/888b6bc1bb3fdf203dda64e50336db4eb9b1e778/pandas/core/arrays/arrow/array.py#L704
  10. used-before-assignment:
    Using variable 'result' before assignment
    https://github.com/pandas-dev/pandas/blob/888b6bc1bb3fdf203dda64e50336db4eb9b1e778/pandas/core/arrays/arrow/array.py#L744
  11. possibly-used-before-assignment:
    Possibly using variable 'ARROW_LOGICAL_FUNCS' before assignment
    https://github.com/pandas-dev/pandas/blob/888b6bc1bb3fdf203dda64e50336db4eb9b1e778/pandas/core/arrays/arrow/array.py#L768
  12. possibly-used-before-assignment:
    Possibly using variable 'ARROW_BIT_WISE_FUNCS' before assignment
    https://github.com/pandas-dev/pandas/blob/888b6bc1bb3fdf203dda64e50336db4eb9b1e778/pandas/core/arrays/arrow/array.py#L784
  13. possibly-used-before-assignment:
    Possibly using variable 'ARROW_ARITHMETIC_FUNCS' before assignment
    https://github.com/pandas-dev/pandas/blob/888b6bc1bb3fdf203dda64e50336db4eb9b1e778/pandas/core/arrays/arrow/array.py#L789
  14. possibly-used-before-assignment:
    Possibly using variable 'ArrowDtype' before assignment
    https://github.com/pandas-dev/pandas/blob/888b6bc1bb3fdf203dda64e50336db4eb9b1e778/pandas/core/arrays/arrow/accessors.py#L49
  15. possibly-used-before-assignment:
    Possibly using variable 'pa' before assignment
    https://github.com/pandas-dev/pandas/blob/888b6bc1bb3fdf203dda64e50336db4eb9b1e778/pandas/core/arrays/arrow/accessors.py#L81
  16. possibly-used-before-assignment:
    Possibly using variable 'pc' before assignment
    https://github.com/pandas-dev/pandas/blob/888b6bc1bb3fdf203dda64e50336db4eb9b1e778/pandas/core/arrays/arrow/accessors.py#L112
  17. possibly-used-before-assignment:
    Possibly using variable 'join_index' before assignment
    https://github.com/pandas-dev/pandas/blob/888b6bc1bb3fdf203dda64e50336db4eb9b1e778/pandas/core/indexes/base.py#L4630
  18. possibly-used-before-assignment:
    Possibly using variable 'freq' before assignment
    https://github.com/pandas-dev/pandas/blob/888b6bc1bb3fdf203dda64e50336db4eb9b1e778/pandas/core/indexes/datetimelike.py#L275
  19. used-before-assignment:
    Using variable 'func' before assignment
    https://github.com/pandas-dev/pandas/blob/888b6bc1bb3fdf203dda64e50336db4eb9b1e778/pandas/core/array_algos/take.py#L244
  20. possibly-used-before-assignment:
    Possibly using variable 'lidx' before assignment
    https://github.com/pandas-dev/pandas/blob/888b6bc1bb3fdf203dda64e50336db4eb9b1e778/pandas/core/reshape/merge.py#L1797
  21. possibly-used-before-assignment:
    Possibly using variable 'ridx' before assignment
    https://github.com/pandas-dev/pandas/blob/888b6bc1bb3fdf203dda64e50336db4eb9b1e778/pandas/core/reshape/merge.py#L1797
  22. possibly-used-before-assignment:
    Possibly using variable 'values_multi' before assignment
    https://github.com/pandas-dev/pandas/blob/888b6bc1bb3fdf203dda64e50336db4eb9b1e778/pandas/core/reshape/pivot.py#L231
  23. possibly-used-before-assignment:
    Possibly using variable 'msg' before assignment
    https://github.com/pandas-dev/pandas/blob/888b6bc1bb3fdf203dda64e50336db4eb9b1e778/pandas/core/computation/eval.py#L171
  24. possibly-used-before-assignment:
    Possibly using variable 'res' before assignment
    https://github.com/pandas-dev/pandas/blob/888b6bc1bb3fdf203dda64e50336db4eb9b1e778/pandas/core/computation/pytables.py#L165
  25. possibly-used-before-assignment:
    Possibly using variable 'ne' before assignment
    https://github.com/pandas-dev/pandas/blob/888b6bc1bb3fdf203dda64e50336db4eb9b1e778/pandas/core/computation/expressions.py#L64
  26. possibly-used-before-assignment:
    Possibly using variable 'concat' before assignment
    https://github.com/pandas-dev/pandas/blob/888b6bc1bb3fdf203dda64e50336db4eb9b1e778/pandas/core/groupby/groupby.py#L5052
  27. possibly-used-before-assignment:
    Possibly using variable 'weights_arr' before assignment
    https://github.com/pandas-dev/pandas/blob/888b6bc1bb3fdf203dda64e50336db4eb9b1e778/pandas/core/groupby/groupby.py#L5460

Effect on sentry:
The following messages are now emitted:

  1. possibly-used-before-assignment:
    Possibly using variable 'freq_delta' before assignment
    https://github.com/getsentry/sentry/blob/530d898b7851806d90cbf13362bb053bc1d89ff9/src/sentry/api/helpers/span_analysis.py#L86
  2. possibly-used-before-assignment:
    Possibly using variable 'duration_delta' before assignment
    https://github.com/getsentry/sentry/blob/530d898b7851806d90cbf13362bb053bc1d89ff9/src/sentry/api/helpers/span_analysis.py#L87
  3. possibly-used-before-assignment:
    Possibly using variable 'state' before assignment
    https://github.com/getsentry/sentry/blob/530d898b7851806d90cbf13362bb053bc1d89ff9/src/sentry/integrations/slack/webhooks/action.py#L540
  4. possibly-used-before-assignment:
    Possibly using variable 'values' before assignment
    https://github.com/getsentry/sentry/blob/530d898b7851806d90cbf13362bb053bc1d89ff9/src/sentry/integrations/slack/webhooks/action.py#L542
  5. possibly-used-before-assignment:
    Possibly using variable 'mappings' before assignment
    https://github.com/getsentry/sentry/blob/530d898b7851806d90cbf13362bb053bc1d89ff9/src/sentry/snuba/metrics_layer/query.py#L297
  6. possibly-used-before-assignment:
    Possibly using variable 'sentry_app_map' before assignment
    https://github.com/getsentry/sentry/blob/530d898b7851806d90cbf13362bb053bc1d89ff9/src/sentry/incidents/endpoints/organization_alert_rule_details.py#L76
  7. possibly-used-before-assignment:
    Possibly using variable 'organization' before assignment
    https://github.com/getsentry/sentry/blob/530d898b7851806d90cbf13362bb053bc1d89ff9/src/sentry/tasks/integrations/slack/link_slack_user_identities.py#L32
  8. possibly-used-before-assignment:
    Possibly using variable 'integration' before assignment
    https://github.com/getsentry/sentry/blob/530d898b7851806d90cbf13362bb053bc1d89ff9/src/sentry/tasks/integrations/slack/link_slack_user_identities.py#L32
  9. possibly-used-before-assignment:
    Possibly using variable 'subscriptions_by_team_id' before assignment
    https://github.com/getsentry/sentry/blob/530d898b7851806d90cbf13362bb053bc1d89ff9/src/sentry/models/groupsubscription.py#L206

Effect on psycopg:
The following messages are now emitted:

  1. possibly-used-before-assignment:
    Possibly using variable 'wait_c' before assignment
    https://github.com/psycopg/psycopg/blob/ae0a8bd351a53d5e5934e65a9c073c4ddc033cf9/psycopg/psycopg/waiting.py#L414
  2. possibly-used-before-assignment:
    Possibly using variable 'enc' before assignment
    https://github.com/psycopg/psycopg/blob/ae0a8bd351a53d5e5934e65a9c073c4ddc033cf9/psycopg/psycopg/connection_async.py#L366
  3. possibly-used-before-assignment:
    Possibly using variable 'enc' before assignment
    https://github.com/psycopg/psycopg/blob/ae0a8bd351a53d5e5934e65a9c073c4ddc033cf9/psycopg/psycopg/connection.py#L343

Effect on coverage:
The following messages are now emitted:

  1. possibly-used-before-assignment:
    Possibly using variable 'soft_key_lines' before assignment
    https://github.com/nedbat/coveragepy/blob/d9156677a9450e1d613ffa25c87d6b063c28e62e/coverage/phystokens.py#L162
  2. possibly-used-before-assignment:
    Possibly using variable 'PYPYVERSION' before assignment
    https://github.com/nedbat/coveragepy/blob/d9156677a9450e1d613ffa25c87d6b063c28e62e/coverage/env.py#L76
  3. possibly-used-before-assignment:
    Possibly using variable 'YIELD_VALUE' before assignment
    https://github.com/nedbat/coveragepy/blob/d9156677a9450e1d613ffa25c87d6b063c28e62e/coverage/pytracer.py#L263
  4. possibly-used-before-assignment:
    Possibly using variable 'YIELD_FROM_OFFSET' before assignment
    https://github.com/nedbat/coveragepy/blob/d9156677a9450e1d613ffa25c87d6b063c28e62e/coverage/pytracer.py#L265
  5. possibly-used-before-assignment:
    Possibly using variable 'YIELD_FROM' before assignment
    https://github.com/nedbat/coveragepy/blob/d9156677a9450e1d613ffa25c87d6b063c28e62e/coverage/pytracer.py#L267
  6. possibly-used-before-assignment:
    Possibly using variable 'missing_branch_arcs' before assignment
    https://github.com/nedbat/coveragepy/blob/d9156677a9450e1d613ffa25c87d6b063c28e62e/coverage/html.py#L143
  7. possibly-used-before-assignment:
    Possibly using variable 'arcs_executed' before assignment
    https://github.com/nedbat/coveragepy/blob/d9156677a9450e1d613ffa25c87d6b063c28e62e/coverage/html.py#L150

This comment was generated for commit b362668

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.

Great !

@jacobtylerwalls
Copy link
Member Author

Should this be enabled by default?

@DanielNoord
Copy link
Collaborator

Perhaps first as an extension and then after 1 or 2 minor version by default?

@Pierre-Sassoulas
Copy link
Member

I think making this an extension would involve moving the code around (and we have a lot of optimization if the code is mixed with used-before-assignement, right ?), so I would say:

  • opt-in in 3.0 (with enable), opt-out in 4.0 (As part of Disable certain messages by default #3512 ?)
  • or opt-out (with disable)
    option 1 is "safer", but then again the check is pretty useful (even if noisy) so maybe option 2... (knowing it's easy to disable a message)

@DanielNoord
Copy link
Collaborator

Let's go with option 2 then!

@jacobtylerwalls jacobtylerwalls merged commit 67bfab4 into main Apr 17, 2024
44 checks passed
@jacobtylerwalls jacobtylerwalls deleted the 1727-uba-false-negative branch April 17, 2024 11:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement ✨ Improvement to a component False Negative 🦋 No message is emitted but something is wrong with the code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

used-before-assignment false negative after conditionals
4 participants