Use is/is not for same-enum identity comparisons (3/3)#171597
Closed
justanotherariel wants to merge 1 commit into
Closed
Use is/is not for same-enum identity comparisons (3/3)#171597justanotherariel wants to merge 1 commit into
is/is not for same-enum identity comparisons (3/3)#171597justanotherariel wants to merge 1 commit into
Conversation
Part 3 of 3 of a mechanical codemod identified by the `mypy_plugins.enum_identity_compare` plugin from home-assistant#171551. Replaces `==` with `is` (and `!=` with `is not`) on every line where both operands statically resolve to the same `enum.Enum` subclass. This part covers files from `homeassistant/components/withings/sensor.py` through `tests/util/test_unit_system.py` alphabetically — 254 files. Land order with the other parts and the plugin (home-assistant#171551) does not matter for correctness, only for CI temporary noise.
21 tasks
Contributor
There was a problem hiding this comment.
Pull request overview
This PR is the third part of a repo-wide mechanical codemod replacing ==/!= with is/is not where both operands are intended to be the same enum type, preparing the codebase for the ha-enum-identity-compare mypy plugin.
Changes:
- Replaced enum equality/inequality comparisons with identity comparisons in core helpers/util code and multiple integrations.
- Updated a large set of tests to use enum identity comparisons in assertions and control flow.
- Applied the same replacements in various test utilities/fixtures and integration test suites.
Reviewed changes
Copilot reviewed 254 out of 254 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| homeassistant/util/unit_system.py | Switch enum comparisons in unit-system deprecation mapping to identity checks. |
| homeassistant/util/timeout.py | Switch internal _State enum comparison to identity check. |
| homeassistant/util/ssl.py | Switch SSLCipherList enum comparison to identity check. |
| homeassistant/helpers/trigger.py | Switch NumericThresholdType comparison to identity check. |
| homeassistant/helpers/service.py | Switch SupportsResponse comparison to identity check for response metadata. |
| homeassistant/helpers/selector.py | Switch NumericThresholdMode comparison in selector validation to identity check. |
| homeassistant/helpers/script.py | Switch SupportsResponse comparisons in script validation to identity checks. |
| homeassistant/helpers/intent.py | Switch IntentResponseType comparison to identity check in serialization. |
| homeassistant/helpers/entity_registry.py | Switch RegistryEntryDisabler comparisons to identity checks; adjust UNDEFINED sentinel check. |
| homeassistant/helpers/device_registry.py | Switch DeviceEntryDisabler comparison to identity check. |
| homeassistant/helpers/data_entry_flow.py | Switch FlowResultType comparison to identity check for JSON preparation. |
| homeassistant/data_entry_flow.py | Switch FlowResultType comparisons to identity checks in flow handling. |
| homeassistant/config_entries.py | Switch ConfigEntryState, FlowType, and FlowResultType comparisons to identity checks. |
| homeassistant/components/withings/sensor.py | Switch ConfigEntryState comparison to identity check in device listener. |
| homeassistant/components/zwave_js/triggers/trigger_helpers.py | Switch ConfigEntryState comparison to identity check. |
| homeassistant/components/zwave_js/migrate.py | Switch Platform comparison to identity check. |
| homeassistant/components/zwave_js/light.py | Switch ColorMode comparisons to identity checks. |
| homeassistant/components/zwave_js/helpers.py | Switch ConfigEntryState and ConfigurationValueType comparisons to identity checks. |
| homeassistant/components/zwave_js/discovery.py | Switch ConfigurationValueType comparisons to identity checks. |
| homeassistant/components/zwave_js/discovery_data_template.py | Switch MultilevelSensorType comparison to identity check. |
| homeassistant/components/zwave_js/device_automation_helpers.py | Switch ConfigEntryState comparison to identity check. |
| homeassistant/components/zwave_js/config_flow.py | Switch AddonState/ConfigEntryState comparisons to identity checks. |
| homeassistant/components/zwave_js/climate.py | Switch ThermostatSetpointType/HVACMode comparisons to identity checks. |
| homeassistant/components/zwave_js/api.py | Switch InclusionStrategy/NodeStatus comparisons to identity checks. |
| homeassistant/components/zwave_js/init.py | Switch RemoveNodeReason/AddonState comparisons to identity checks. |
| homeassistant/components/ziggo_mediabox_xl/media_player.py | Switch MediaPlayerState comparisons to identity checks. |
| homeassistant/components/zhong_hong/climate.py | Switch HVACMode comparison to identity check. |
| homeassistant/components/zha/repairs/wrong_silabs_firmware.py | Switch ApplicationType/HardwareType comparisons to identity checks. |
| homeassistant/components/zha/config_flow.py | Switch ProbeResult/ZigbeeFlowStrategy comparisons to identity checks. |
| homeassistant/components/yolink/services.py | Switch ConfigEntryState comparison to identity check. |
| homeassistant/components/yeelight/light.py | Switch ColorMode comparisons to identity checks. |
| homeassistant/components/yeelight/config_flow.py | Switch ConfigEntryState comparison to identity check. |
| homeassistant/components/yamaha_musiccast/media_player.py | Switch MediaPlayerState comparisons to identity checks. |
| homeassistant/components/yalexs_ble/binary_sensor.py | Switch DoorStatus comparison to identity check. |
| homeassistant/components/yale_smart_alarm/lock.py | Switch LockState comparisons to identity checks. |
| homeassistant/components/xiaomi_tv/media_player.py | Switch MediaPlayerState comparisons to identity checks. |
| homeassistant/components/xiaomi_miio/humidifier.py | Switch operation-mode enum comparisons to identity checks. |
| homeassistant/components/xiaomi_ble/config_flow.py | Switch EncryptionScheme comparisons to identity checks. |
| homeassistant/components/xiaomi_ble/init.py | Switch EncryptionScheme comparison to identity check. |
| homeassistant/components/xbox/remote.py | Switch PowerState comparison to identity check. |
| homeassistant/components/wyoming/devices.py | Switch VadSensitivity comparison to identity check. |
| homeassistant/components/wyoming/assist_satellite.py | Switch pipeline/timer enum comparisons to identity checks. |
| tests/util/test_unit_system.py | Update unit enum assertions to identity checks. |
| tests/test_core.py | Update core state/job type/release channel assertions to identity checks. |
| tests/syrupy.py | Update snapshot item status comparison to identity check. |
| tests/helpers/test_trigger_template_entity.py | Update device_class enum assertion to identity check. |
| tests/helpers/test_intent.py | Update intent enums assertions to identity checks. |
| tests/helpers/test_entity_registry.py | Update registry hider enum assertion to identity check. |
| tests/components/zwave_js/test_switch.py | Update EntityCategory assertion to identity check. |
| tests/components/zwave_js/test_sensor.py | Update EntityCategory assertion to identity check. |
| tests/components/zwave_js/test_select.py | Update EntityCategory assertion to identity check. |
| tests/components/zwave_js/test_number.py | Update EntityCategory assertion to identity check. |
| tests/components/zwave_js/test_discovery.py | Update EntityCategory assertions to identity checks. |
| tests/components/zwave_js/test_binary_sensor.py | Update EntityCategory assertions to identity checks. |
| tests/components/zha/test_select.py | Update EntityCategory assertion to identity check. |
| tests/components/zha/test_repairs.py | Update HardwareType assertions to identity checks. |
| tests/components/zha/test_radio_manager.py | Update ProbeResult assertions to identity checks. |
| tests/components/zha/test_helpers.py | Update ZCL enum assertions to identity checks. |
| tests/components/zha/test_config_flow.py | Update flow result type comparison to identity check. |
| tests/components/zha/test_button.py | Update EntityCategory assertion to identity check. |
| tests/components/zeroconf/test_repairs.py | Update issue severity enum assertions to identity checks. |
| tests/components/yandextts/test_tts.py | Update HTTPStatus assertions to identity checks. |
| tests/components/yale_smart_alarm/test_config_flow.py | Update ConfigEntryState assertion to identity check. |
| tests/components/wyoming/test_stt.py | Update STT result enum assertions to identity checks. |
| tests/components/wyoming/test_select.py | Update VadSensitivity assertions to identity checks. |
| tests/components/wyoming/test_satellite.py | Update intent response type assertions to identity checks. |
| tests/components/wyoming/test_conversation.py | Update intent response/error code assertions to identity checks. |
| tests/components/wled/test_init.py | Update ConfigEntryState assertions to identity checks. |
| tests/components/websocket_api/test_http.py | Update WSMsgType assertions to identity checks. |
| tests/components/websocket_api/test_auth.py | Update WSMsgType assertions to identity checks. |
| tests/components/weather/test_intent.py | Update intent response/match-reason assertions to identity checks. |
| tests/components/watergate/test_sensor.py | Update EntityCategory filtering to identity check. |
| tests/components/wake_word/test_init.py | Update EntityCategory assertion to identity check. |
| tests/components/voicerss/test_tts.py | Update HTTPStatus assertions to identity checks. |
| tests/components/vodafone_station/test_init.py | Update ConfigEntryState assertion to identity check. |
| tests/components/vicare/test_init.py | Update issue severity enum assertion to identity check. |
| tests/components/vera/common.py | Update ConfigSource comparisons to identity checks. |
| tests/components/valve/test_intent.py | Update intent response type assertions to identity checks. |
| tests/components/vacuum/test_init.py | Update issue severity enum assertion to identity check. |
| tests/components/unifiprotect/test_media_source.py | Update MediaClass assertions to identity checks. |
| tests/components/unifi/test_switch.py | Update registry disabler enum assertions to identity checks. |
| tests/components/unifi/test_sensor.py | Update registry disabler enum assertions to identity checks. |
| tests/components/unifi/test_image.py | Update registry disabler enum assertion to identity check. |
| tests/components/unifi/test_button.py | Update registry disabler enum assertion to identity check. |
| tests/components/uhoo/test_config_flow.py | Update flow result type assertion to identity check. |
| tests/components/tts/test_media_source.py | Update HTTPStatus assertions to identity checks. |
| tests/components/tts/test_init.py | Update HTTPStatus assertions to identity checks. |
| tests/components/tplink/test_init.py | Update EntityCategory assertion to identity check. |
| tests/components/tplink/test_config_flow.py | Update flow result type comparisons to identity checks. |
| tests/components/tplink_omada/test_init.py | Update config entry state assertions to identity checks. |
| tests/components/tplink_lte/test_init.py | Update issue severity enum assertion to identity check. |
| tests/components/todo/test_init.py | Update todo status enum assertions to identity checks. |
| tests/components/text/test_init.py | Update TextMode assertion to identity check. |
| tests/components/template/test_vacuum.py | Update issue severity enum assertion to identity check. |
| tests/components/template/test_config.py | Update issue severity enum assertion to identity check. |
| tests/components/template/conftest.py | Update ConfigurationStyle comparisons to identity checks. |
| tests/components/telegram_bot/test_telegram_bot.py | Update config entry state assertion to identity check. |
| tests/components/tami4/test_init.py | Update config entry state assertions to identity checks. |
| tests/components/tailscale/test_sensor.py | Update EntityCategory/DeviceEntryType assertions to identity checks. |
| tests/components/tailscale/test_binary_sensor.py | Update EntityCategory/DeviceEntryType assertions to identity checks. |
| tests/components/synology_dsm/test_media_source.py | Update MediaClass assertions to identity checks. |
| tests/components/switchbot_cloud/test_init.py | Update config entry state assertions to identity checks. |
| tests/components/switch_as_x/test_init.py | Update registry hider enum assertion to identity check. |
| tests/components/switch_as_x/test_config_flow.py | Update registry hider enum assertion to identity check. |
| tests/components/surepetcare/test_sensor.py | Update registry disabler enum assertion to identity check. |
| tests/components/stt/test_init.py | Update audio enum assertions to identity checks. |
| tests/components/stream/test_worker.py | Update error code enum assertion to identity check. |
| tests/components/steam_online/test_init.py | Update DeviceEntryType assertion to identity check. |
| tests/components/sonos/test_media_browser.py | Update MediaClass assertion to identity check. |
| tests/components/snooz/init.py | Update connection status enum comparison to identity check. |
| tests/components/smartthings/init.py | Update Platform comparison to identity check. |
| tests/components/sma/test_init.py | Update config entry state assertions to identity checks. |
| tests/components/shopping_list/test_intent.py | Update intent response type assertions to identity checks. |
| tests/components/shopping_list/test_init.py | Update intent response type assertion to identity check. |
| tests/components/shell_command/test_init.py | Update issue severity enum assertion to identity check. |
| tests/components/sftp_storage/test_backup.py | Update ConfigEntryState assertion to identity check. |
| tests/components/satel_integra/test_init.py | Update config entry state assertion to identity check. |
| tests/components/samsungtv/test_init.py | Update ConfigEntryState assertion to identity check. |
| tests/components/roku/test_sensor.py | Update EntityCategory assertions to identity checks. |
| tests/components/roku/test_binary_sensor.py | Update EntityCategory assertions to identity checks. |
| tests/components/roborock/test_vacuum.py | Update issue severity enum assertion to identity check. |
| tests/components/roborock/conftest.py | Update category enum comparison to identity check. |
| tests/components/rituals_perfume_genie/test_sensor.py | Update EntityCategory assertions to identity checks. |
| tests/components/rituals_perfume_genie/test_select.py | Update EntityCategory assertion to identity check. |
| tests/components/rituals_perfume_genie/test_binary_sensor.py | Update EntityCategory assertion to identity check. |
| tests/components/reolink/test_init.py | Update config entry state assertion to identity check. |
| tests/components/recorder/db_schema_51.py | Update dialect enum comparison to identity check. |
| tests/components/recorder/db_schema_50.py | Update dialect enum comparison to identity check. |
| tests/components/recorder/db_schema_48.py | Update dialect enum comparison to identity check. |
| tests/components/recorder/db_schema_43.py | Update dialect enum comparison to identity check. |
| tests/components/recorder/common.py | Update event origin enum assertion to identity check. |
| tests/components/radio_browser/test_media_source.py | Update ConfigEntryState assertions to identity checks. |
| tests/components/radio_browser/conftest.py | Update ConfigEntryState assertion to identity check. |
| tests/components/proxmoxve/test_init.py | Update config entry state assertions to identity checks. |
| tests/components/portainer/test_init.py | Update config entry state assertions to identity checks. |
| tests/components/picotts/test_tts.py | Update HTTPStatus assertion to identity check. |
| tests/components/paperless_ngx/test_init.py | Update config entry state assertion to identity check. |
| tests/components/overseerr/test_init.py | Update config entry state assertion to identity check. |
| tests/components/ourgroceries/test_init.py | Update config entry state assertion to identity check. |
| tests/components/otbr/test_config_flow.py | Update key format enum comparisons to identity checks. |
| tests/components/otbr/conftest.py | Update HTTPStatus selection to identity check. |
| tests/components/opower/test_coordinator.py | Update issue severity enum assertion to identity check. |
| tests/components/opentherm_gw/test_switch.py | Update registry disabler enum assertion to identity check. |
| tests/components/openai_conversation/test_tts.py | Update HTTPStatus assertions to identity checks. |
| tests/components/openai_conversation/test_conversation.py | Update intent response type assertions to identity checks. |
| tests/components/open_router/test_conversation.py | Update intent response type assertions to identity checks. |
| tests/components/ntfy/test_config_flow.py | Update flow type enum assertion to identity check. |
| tests/components/nextcloud/test_init.py | Update config entry state assertion to identity check. |
| tests/components/mqtt/common.py | Update EntityCategory assertion to identity check. |
| tests/components/mobile_app/test_webhook.py | Update registry disabler enum assertion to identity check. |
| tests/components/mobile_app/test_sensor.py | Update registry disabler enum assertion to identity check. |
| tests/components/microsoft/test_tts.py | Update HTTPStatus assertions to identity checks. |
| tests/components/maxcube/test_maxcube_binary_sensor.py | Update EntityCategory assertions to identity checks. |
| tests/components/matter/test_sensor.py | Update EntityCategory assertions to identity checks. |
| tests/components/marytts/test_tts.py | Update HTTPStatus assertions to identity checks. |
| tests/components/lovelace/test_dashboard.py | Update issue severity enum assertion to identity check. |
| tests/components/lovelace/test_cast.py | Update MediaClass assertion to identity check. |
| tests/components/lifx/test_binary_sensor.py | Update EntityCategory assertion to identity check. |
| tests/components/lcn/test_config_flow.py | Update flow result type assertions to identity checks. |
| tests/components/lawn_mower/test_intent.py | Update intent response type assertions to identity checks. |
| tests/components/lametric/test_button.py | Update EntityCategory assertions to identity checks. |
| tests/components/lamarzocco/conftest.py | Update model enum comparisons to identity checks. |
| tests/components/lamarzocco/init.py | Update model enum comparison to identity check. |
| tests/components/kitchen_sink/test_init.py | Update issue severity enum assertion to identity check. |
| tests/components/jewish_calendar/test_calendar.py | Update daily event type filtering to identity check. |
| tests/components/intent/test_init.py | Update intent response type assertions to identity checks. |
| tests/components/influxdb/test_init.py | Update ConfigEntryState assertions to identity checks. |
| tests/components/imap/test_config_flow.py | Update flow result type assertion to identity check. |
| tests/components/humidifier/test_intent.py | Update intent response/match reason assertions to identity checks. |
| tests/components/hue/test_sensor_v1.py | Update EntityCategory assertion to identity check. |
| tests/components/html5/test_config_flow.py | Update flow result type assertion to identity check. |
| tests/components/homeassistant/test_init.py | Update issue severity enum assertions to identity checks. |
| tests/components/homeassistant_sky_connect/test_util.py | Update hardware variant assertions to identity checks. |
| tests/components/homeassistant_sky_connect/test_const.py | Update hardware variant assertions to identity checks. |
| tests/components/homeassistant_hardware/test_switch.py | Update EntityCategory assertion to identity check. |
| tests/components/homeassistant_hardware/test_config_flow.py | Update flow result type comparison to identity check. |
| tests/components/home_connect/test_select.py | Update SettingKey comparison to identity check. |
| tests/components/home_connect/test_init.py | Update config entry state assertion to identity check. |
| tests/components/home_connect/test_button.py | Update CommandKey comparison to identity check. |
| tests/components/hikvision/test_binary_sensor.py | Update issue severity enum assertions to identity checks. |
| tests/components/hassio/test_issues.py | Update unsupported reason filtering to identity check. |
| tests/components/hassio/test_init.py | Update issue severity enum assertions to identity checks. |
| tests/components/gree/test_climate.py | Update temperature unit enum comparisons to identity checks. |
| tests/components/google/test_calendar.py | Update registry disabler enum assertion to identity check. |
| tests/components/google_translate/test_tts.py | Update HTTPStatus assertions to identity checks. |
| tests/components/google_generative_ai_conversation/test_tts.py | Update HTTPStatus assertions to identity checks. |
| tests/components/google_generative_ai_conversation/test_conversation.py | Update intent response type assertions to identity checks. |
| tests/components/google_assistant/test_trait.py | Update sensor device class comparisons to identity checks. |
| tests/components/go2rtc/test_init.py | Update config entry state assertions and issue severity assertions to identity checks. |
| tests/components/fully_kiosk/test_sensor.py | Update EntityCategory assertions to identity checks. |
| tests/components/fully_kiosk/test_binary_sensor.py | Update EntityCategory assertions to identity checks. |
| tests/components/fish_audio/test_tts.py | Update HTTPStatus assertions to identity checks. |
| tests/components/firefly_iii/test_init.py | Update config entry state assertion to identity check. |
| tests/components/fan/test_intent.py | Update intent response type assertion to identity check. |
| tests/components/evohome/conftest.py | Update HTTP method enum comparison to identity check. |
| tests/components/esphome/test_manager.py | Update log level/support response assertions to identity checks. |
| tests/components/esphome/test_enum_mapper.py | Update mapping enum assertions to identity checks. |
| tests/components/enphase_envoy/test_sensor.py | Update registry disabler filtering to identity check. |
| tests/components/energy/test_sensor.py | Update registry hider enum assertion to identity check. |
| tests/components/emulated_hue/test_hue_api.py | Update HTTPStatus comparison to identity check. |
| tests/components/elevenlabs/test_tts.py | Update HTTPStatus assertions to identity checks. |
| tests/components/elevenlabs/test_stt.py | Update STT result enum assertions to identity checks. |
| tests/components/ecovacs/test_config_flow.py | Update SSL verify mode comparison to identity check. |
| tests/components/duco/test_sensor.py | Update registry disabler assertions and node type comparison to identity checks. |
| tests/components/device_tracker/test_config_entry.py | Update registry disabler assertions to identity checks. |
| tests/components/cover/test_intent.py | Update intent response type assertions to identity checks. |
| tests/components/cookidoo/test_init.py | Update config entry state assertion to identity check. |
| tests/components/conversation/test_chat_log.py | Update chat log event type assertions to identity checks. |
| tests/components/config/test_entity_registry.py | Update registry disabler assertion to identity check. |
| tests/components/config/test_config_entries.py | Update flow result type assertions to identity checks. |
| tests/components/comelit/test_init.py | Update ConfigEntryState assertion to identity check. |
| tests/components/cloud/test_tts.py | Update issue severity enum assertions to identity checks. |
| tests/components/climate/test_init.py | Update HVACMode assertion to identity check. |
| tests/components/climate/test_condition.py | Update HVAC mode filtering to identity check. |
| tests/components/casper_glow/test_init.py | Update ConfigEntryState assertion to identity check. |
| tests/components/camera/test_prefs.py | Update orientation enum assertions to identity checks. |
| tests/components/bsblan/test_climate.py | Update HVAC action assertions to identity checks. |
| tests/components/bring/test_init.py | Update config entry state assertion to identity check. |
| tests/components/bluetooth/test_manager.py | Update issue severity enum assertions to identity checks. |
| tests/components/bayesian/test_config_flow.py | Update flow result type assertions to identity checks. |
| tests/components/backup/test_manager.py | Update backup manager state assertion to identity check. |
| tests/components/azure_data_explorer/test_config_flow.py | Update flow result type assertions to identity checks. |
| tests/components/axis/test_hub.py | Update config entry state assertions to identity checks. |
| tests/components/assist_pipeline/test_pipeline.py | Update pipeline event type comparisons to identity checks. |
| tests/components/assist_pipeline/test_init.py | Update pipeline event type assertions to identity checks. |
| tests/components/anthropic/test_coordinator.py | Update intent response type assertions to identity checks. |
| tests/components/anthropic/test_conversation.py | Update device entry type and intent response assertions to identity checks. |
| tests/components/alexa_devices/test_init.py | Update ConfigEntryState assertion to identity check. |
| tests/components/airos/test_init.py | Update config entry state assertion to identity check. |
| tests/components/airos/test_config_flow.py | Update flow result type assertions to identity checks. |
| tests/common.py | Update issue severity enum assertion to identity check. |
| tests/auth/providers/test_homeassistant.py | Update flow result type assertions to identity checks. |
| tests/auth/providers/test_command_line.py | Update flow result type assertions to identity checks. |
| tests/auth/mfa_modules/test_totp.py | Update flow result type assertions to identity checks. |
| tests/auth/mfa_modules/test_insecure_example.py | Update flow result type assertions to identity checks. |
Comment on lines
1625
to
1627
| mode = self.config["mode"] | ||
| if mode != NumericThresholdMode.CHANGED: | ||
| if mode is not NumericThresholdMode.CHANGED: | ||
| validators.append(_validate_numeric_threshold_not_any) |
Comment on lines
739
to
744
| return False | ||
|
|
||
| if self._threshold_type == NumericThresholdType.ANY: | ||
| if self._threshold_type is NumericThresholdType.ANY: | ||
| # If the threshold type is "any" we always trigger on valid state | ||
| # changes | ||
| return True |
Comment on lines
661
to
666
| if ( | ||
| response := hass.services.supports_response(domain, service) | ||
| ) != SupportsResponse.NONE: | ||
| ) is not SupportsResponse.NONE: | ||
| description["response"] = { | ||
| "optional": response == SupportsResponse.OPTIONAL, | ||
| } |
21 tasks
Member
|
OK for evohome, thanks. |
Member
Author
|
No longer needed - moved to #171591 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Proposed change
Mechanical codemod that replaces
==withis(and!=withis not)on every line where both operands statically resolve to the same
enum.Enumsubclass. This is a prerequisite to #171551 (themypy_plugins.enum_identity_compareplugin that identifies thesesites).
Part 3 of 3 — covers files alphabetically from
homeassistant/components/withings/sensor.pythroughtests/util/test_unit_system.py.Scope of this PR: ~1,150 sites across 254 files. (This part is the
test-heavy tail, where many lines have multiple swappable comparisons.)
Scope of the full codemod (all 3 parts): 2,159 sites across 762
files, touching 378 of 1,468 integrations (~26%) plus ~20
core/helper/util files.
What is NOT changed:
Flag/IntFlagpatterns (features & FEATURE_X == FEATURE_X) —bitwise
==is idiomatic there.str/int:state.state == HVACMode.HEAT(state-machine string),response.status_code == HTTPStatus.OK(HTTP-client integer), etc.The plugin correctly skips these and the codemod doesn't touch them.
Validation:
ha-enum-identity-compareviolation reported by the mypy plugin against
dev.plugin reports zero remaining violations.
removed-line == added-line modulo a single
==→is(or!=→is not) substitution, with the swap adjacent to anenum-class reference.
ast.parse).(informational delta check).
Type of change
Additional information
==/!=between same-enum operands #171551is/is notfor same-enum identity comparisons (source) #171591 (part 1,auth→manual_mqtt), Useis/is notfor same-enum identity comparisons (2/3) #171596 (part 2,matter→withings/coordinator).==/!=between same-enum operands #171551) does not matter for correctness, only for CI temporary noise.Checklist
ruff format homeassistant tests)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest.requirements_all.txt.Updated by running
python3 -m script.gen_requirements_all.To help with the load of incoming pull requests: