Repository navigation
perflint: Add ruff rules for performance #21
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -46,34 +46,31 @@ | |
|
|
||
|
|
||
| def find_cameras(raise_when_empty=False, max_index_search_range=MAX_OPENCV_INDEX, mock=False) -> list[dict]: | ||
| cameras = [] | ||
| if platform.system() == "Linux": | ||
| print("Linux detected. Finding available camera indices through scanning '/dev/video*' ports") | ||
| possible_ports = [str(port) for port in Path("/dev").glob("video*")] | ||
| ports = _find_cameras(possible_ports, mock=mock) | ||
|
||
| for port in ports: | ||
| cameras.append( | ||
| { | ||
| "port": port, | ||
| "index": int(port.removeprefix("/dev/video")), | ||
| } | ||
| ) | ||
| else: | ||
| print( | ||
| "Mac or Windows detected. Finding available camera indices through " | ||
| f"scanning all indices from 0 to {MAX_OPENCV_INDEX}" | ||
| ) | ||
| possible_indices = range(max_index_search_range) | ||
| indices = _find_cameras(possible_indices, mock=mock) | ||
| for index in indices: | ||
| cameras.append( | ||
| { | ||
| "port": None, | ||
| "index": index, | ||
| } | ||
| ) | ||
|
|
||
| return cameras | ||
| return [ | ||
| { | ||
| "port": port, | ||
| "index": int(port.removeprefix("/dev/video")), | ||
| } | ||
| for port in ports | ||
| ] | ||
|
|
||
| print( | ||
| "Mac or Windows detected. Finding available camera indices through " | ||
| f"scanning all indices from 0 to {MAX_OPENCV_INDEX}" | ||
| ) | ||
| possible_indices = range(max_index_search_range) | ||
| indices = _find_cameras(possible_indices, mock=mock) | ||
|
||
| return [ | ||
| { | ||
| "port": None, | ||
| "index": index, | ||
| } | ||
| for index in indices | ||
| ] | ||
|
Comment on lines
+61
to
+73
|
||
|
|
||
|
|
||
| def _find_cameras( | ||
|
|
||
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.
The function signature indicates it returns
list[dict]but the implementation has two different return paths that may not execute. After the Linux block, there's noelseclause, so the Mac/Windows code will always execute regardless of platform, potentially causing the Linux case to return twice or fall through incorrectly.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.
Both possible paths return a
list[dict]. The fall through is correct because Mac/Windows code will never execute in the Linux case and the Linux code will never execute in the Mac/Windows case. Returning twice is not possible in Python code because the first return leaves the function.