-
Notifications
You must be signed in to change notification settings - Fork 242
Ruff fixes #786
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
Ruff fixes #786
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
5a05cc3
examples: async fixes
julianoes 6dc989f
examples: fix RUF006
julianoes f1be084
CI: add ruff checks
julianoes 5874239
Update .github/workflows/main.yml
julianoes bcbc92c
Use pipx
julianoes 7c7ac36
Various improvements
julianoes b6f80ff
examples: fix unnecessary f-strings
julianoes 8bb56d8
examples: more ruff fixes
julianoes fce9984
CI: enable all ruff checks
julianoes e84d87f
CI: add standard set for ruff, examples only
julianoes 0259a11
CI: add codespell check
julianoes f71029c
CI: check directory, not all files
julianoes faa08d2
CI: switch from pycodestyle to ruff format
julianoes c428076
examples: ran ruff format
julianoes 96e1c38
CI: fixup line length
julianoes File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -24,20 +24,22 @@ async def run(): | |||||||||||||||||||||||||
drone = System() | ||||||||||||||||||||||||||
await drone.connect(system_address="udpin://0.0.0.0:14540") | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
asyncio.ensure_future(observe_current_settings(drone)) | ||||||||||||||||||||||||||
asyncio.ensure_future(observe_camera_mode(drone)) | ||||||||||||||||||||||||||
asyncio.ensure_future(observe_possible_setting_options(drone)) | ||||||||||||||||||||||||||
_tasks = [ | ||||||||||||||||||||||||||
asyncio.create_task(observe_current_settings(drone)), | ||||||||||||||||||||||||||
asyncio.create_task(observe_camera_mode(drone)), | ||||||||||||||||||||||||||
asyncio.create_task(observe_possible_setting_options(drone)), | ||||||||||||||||||||||||||
] | ||||||||||||||||||||||||||
Comment on lines
+27
to
+31
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This syntax would delete tasks as they are completed, as discussed in
Suggested change
|
||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
while True: | ||||||||||||||||||||||||||
entered_input = await ainput(usage_str) | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
if entered_input == "p": | ||||||||||||||||||||||||||
print(f"\n=== Current settings ===\n") | ||||||||||||||||||||||||||
print("\n=== Current settings ===\n") | ||||||||||||||||||||||||||
print_current_settings() | ||||||||||||||||||||||||||
elif entered_input == "m": | ||||||||||||||||||||||||||
print(f"\n=== Possible modes ===\n") | ||||||||||||||||||||||||||
print(f"1. PHOTO") | ||||||||||||||||||||||||||
print(f"2. VIDEO") | ||||||||||||||||||||||||||
print("\n=== Possible modes ===\n") | ||||||||||||||||||||||||||
print("1. PHOTO") | ||||||||||||||||||||||||||
print("2. VIDEO") | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
try: | ||||||||||||||||||||||||||
index_mode = await make_user_choose_camera_mode() | ||||||||||||||||||||||||||
|
@@ -54,11 +56,11 @@ async def run(): | |||||||||||||||||||||||||
|
||||||||||||||||||||||||||
try: | ||||||||||||||||||||||||||
await drone.camera.set_mode(chosen_mode) | ||||||||||||||||||||||||||
print(f" --> Succeeded") | ||||||||||||||||||||||||||
print(" --> Succeeded") | ||||||||||||||||||||||||||
except CameraError as error: | ||||||||||||||||||||||||||
print(f" --> Failed with code: {error._result.result_str}") | ||||||||||||||||||||||||||
elif entered_input == "s": | ||||||||||||||||||||||||||
print(f"\n=== Possible settings ===\n") | ||||||||||||||||||||||||||
print("\n=== Possible settings ===\n") | ||||||||||||||||||||||||||
print_possible_settings(possible_setting_options) | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
try: | ||||||||||||||||||||||||||
|
@@ -70,10 +72,10 @@ async def run(): | |||||||||||||||||||||||||
selected_setting = possible_setting_options[index_setting - 1] | ||||||||||||||||||||||||||
possible_options = selected_setting.options | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
print(f"\n=== Available options ===") | ||||||||||||||||||||||||||
print("\n=== Available options ===") | ||||||||||||||||||||||||||
print(f"Setting: {selected_setting.setting_id}") | ||||||||||||||||||||||||||
if not selected_setting.is_range: | ||||||||||||||||||||||||||
print(f"Options:") | ||||||||||||||||||||||||||
print("Options:") | ||||||||||||||||||||||||||
try: | ||||||||||||||||||||||||||
print_possible_options(possible_options) | ||||||||||||||||||||||||||
index_option = await make_user_choose_option(possible_options) | ||||||||||||||||||||||||||
|
@@ -94,9 +96,7 @@ async def run(): | |||||||||||||||||||||||||
continue | ||||||||||||||||||||||||||
else: | ||||||||||||||||||||||||||
try: | ||||||||||||||||||||||||||
selected_value = await make_user_choose_option_range( | ||||||||||||||||||||||||||
possible_options | ||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||
selected_value = await make_user_choose_option_range(possible_options) | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
print(f"Setting {selected_setting.setting_id} to {selected_value}!") | ||||||||||||||||||||||||||
setting = Setting( | ||||||||||||||||||||||||||
|
@@ -111,7 +111,7 @@ async def run(): | |||||||||||||||||||||||||
|
||||||||||||||||||||||||||
try: | ||||||||||||||||||||||||||
await drone.camera.set_setting(setting) | ||||||||||||||||||||||||||
print(f" --> Succeeded") | ||||||||||||||||||||||||||
print(" --> Succeeded") | ||||||||||||||||||||||||||
except CameraError as error: | ||||||||||||||||||||||||||
print(f" --> Failed with code: {error._result.result_str}") | ||||||||||||||||||||||||||
else: | ||||||||||||||||||||||||||
|
@@ -148,7 +148,7 @@ def print_current_settings(): | |||||||||||||||||||||||||
|
||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
async def make_user_choose_camera_mode(): | ||||||||||||||||||||||||||
index_mode_str = await ainput(f"\nWhich mode do you want? [1..2] >>> ") | ||||||||||||||||||||||||||
index_mode_str = await ainput("\nWhich mode do you want? [1..2] >>> ") | ||||||||||||||||||||||||||
index_mode = int(index_mode_str) | ||||||||||||||||||||||||||
if index_mode < 1 or index_mode > 2: | ||||||||||||||||||||||||||
raise ValueError() | ||||||||||||||||||||||||||
|
@@ -185,9 +185,7 @@ def print_possible_options(possible_options): | |||||||||||||||||||||||||
|
||||||||||||||||||||||||||
async def make_user_choose_option(possible_options): | ||||||||||||||||||||||||||
n_options = len(possible_options) | ||||||||||||||||||||||||||
index_option_str = await ainput( | ||||||||||||||||||||||||||
f"\nWhich option do you want? [1..{n_options}] >>> " | ||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||
index_option_str = await ainput(f"\nWhich option do you want? [1..{n_options}] >>> ") | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
index_option = int(index_option_str) | ||||||||||||||||||||||||||
if index_option < 1 or index_option > n_options: | ||||||||||||||||||||||||||
|
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is unusual to assemble these tasks but not await them. Are we certain that they will be run at some point?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, so this code was working fine but ruff complained that the tasks were dangling: https://docs.astral.sh/ruff/rules/asyncio-dangling-task/.
So, the advice was to create a strong reference to the tasks. However, now ruff complains that tasks are assigned but never used. It feels like you can't win.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cclauss ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cclauss you need to actually do a read&write conversation, not just write only please.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was wrong... This usage is correct.