Skip to content

Commit d7e8971

Browse files
committed
Use != instead of is not for values.
This uses the `==`/`!=` operators instead of `is`/`is not` when checking the return value of RPC calls. In Python, `is not` tests if the two operands are the same object whereas `!=` test that they have the same value. `is not` just happens to work for small integers due to an implementation detail in CPython (e.g. see [StackOverflow][1]). [1]: https://stackoverflow.com/a/133024/1976323
1 parent ded17f0 commit d7e8971

File tree

4 files changed

+4
-4
lines changed

4 files changed

+4
-4
lines changed

examples/telemetry_takeoff_and_land.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ async def print_flight_mode(drone):
7575
previous_flight_mode = None
7676

7777
async for flight_mode in drone.telemetry.flight_mode():
78-
if flight_mode is not previous_flight_mode:
78+
if flight_mode != previous_flight_mode:
7979
previous_flight_mode = flight_mode
8080
print(f"Flight mode: {flight_mode}")
8181

other/templates/py/call.j2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,6 @@ async def {{ name.lower_snake_case }}(self{% for param in params %}, {{ param.na
4848
{% if has_result %}
4949
result = self._extract_result(response)
5050

51-
if result.result is not {{ plugin_name.upper_camel_case }}Result.Result.SUCCESS:
51+
if result.result != {{ plugin_name.upper_camel_case }}Result.Result.SUCCESS:
5252
raise {{ plugin_name.upper_camel_case }}Error(result, "{{ name.lower_snake_case }}()"{% for param in params %}, {{ param.name.lower_snake_case }}{% endfor %})
5353
{% endif %}

other/templates/py/request.j2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ async def {{ name.lower_snake_case }}(self{% for param in params %}, {{ param.na
5252
{% if has_result %}
5353
result = self._extract_result(response)
5454

55-
if result.result is not {{ plugin_name.upper_camel_case }}Result.Result.SUCCESS:
55+
if result.result != {{ plugin_name.upper_camel_case }}Result.Result.SUCCESS:
5656
raise {{ plugin_name.upper_camel_case }}Error(result, "{{ name.lower_snake_case }}()"{% for param in params %}, {{ param.name.lower_snake_case }}{% endfor %})
5757
{% endif %}
5858

other/templates/py/stream.j2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ async def {{ name.lower_snake_case }}(self{% for param in params %}, {{ param.na
6161
if result.result not in success_codes:
6262
raise {{ plugin_name.upper_camel_case }}Error(result, "{{ name.lower_snake_case }}()"{% for param in params %}, {{ param.name.lower_snake_case }}{% endfor %})
6363

64-
if result.result is {{ plugin_name.upper_camel_case }}Result.Result.SUCCESS:
64+
if result.result == {{ plugin_name.upper_camel_case }}Result.Result.SUCCESS:
6565
{{ name.lower_snake_case }}_stream.cancel();
6666
return
6767
{% endif %}

0 commit comments

Comments
 (0)