Skip to content

Commit 62feb28

Browse files
authored
Enable Ruff SIM (#13309)
1 parent 915a348 commit 62feb28

File tree

2 files changed

+29
-183
lines changed

2 files changed

+29
-183
lines changed

pyproject.toml

+29-5
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,6 @@ select = [
5555
"W", # pycodestyle Warning
5656
# Only include flake8-annotations rules that are autofixable. Otherwise leave this to mypy+pyright
5757
"ANN2",
58-
# Don't include TC rules that create a TYPE_CHECKING block or stringifies annotations
59-
"TC004", # Move import `{qualified_name}` out of type-checking block. Import is used for more than type hinting.
60-
"TC005", # Found empty type-checking block
61-
# "TC008", # TODO: Enable when out of preview
62-
"TC010", # Invalid string member in `X | Y`-style union type
6358
# Most refurb rules are in preview and can be opinionated,
6459
# consider them individually as they come out of preview (last check: 0.8.4)
6560
"FURB105", # Unnecessary empty string passed to `print`
@@ -94,6 +89,35 @@ select = [
9489
# "PYI061", # TODO: Enable when out of preview
9590
"PYI062", # Duplicate literal member `{}`
9691
"PYI064", # `Final[Literal[{literal}]]` can be replaced with a bare Final
92+
# flake8-simplify, excluding rules that can reduce performance or readability due to long line formatting
93+
"SIM101", # Multiple `isinstance` calls for `{name}`, merge into a single call
94+
"SIM103", # Return the condition `{condition}` directly
95+
"SIM107", # Don't use return in `try-except` and `finally`
96+
"SIM109", # Use `{replacement}` instead of multiple equality comparisons
97+
"SIM112", # Use capitalized environment variable `{expected}` instead of `{actual}`
98+
"SIM113", # Use `enumerate()` for index variable `{index}` in `for` loop
99+
"SIM114", # Combine `if` branches using logical `or` operator
100+
"SIM115", # Use a context manager for opening files
101+
"SIM118", # Use key `{operator}` dict instead of key `{operator} dict.keys()`
102+
"SIM201", # Use `{left} != {right}` instead of not `{left} == {right}`
103+
"SIM202", # Use `{left} == {right}` instead of not `{left} != {right}`
104+
"SIM208", # Use `{expr}` instead of `not (not {expr})`
105+
"SIM210", # Remove unnecessary `True if ... else False`
106+
"SIM211", # Use `not ...` instead of `False if ... else True`
107+
"SIM212", # Use `{expr_else} if {expr_else} else {expr_body}` instead of `{expr_body} if not {expr_else} else {expr_else}`
108+
"SIM220", # Use `False` instead of `{name} and not {name}`
109+
"SIM221", # Use `True` instead of `{name} or not {name}`
110+
"SIM222", # Use `{expr}` instead of `{replaced}`
111+
"SIM223", # Use `{expr}` instead of `{replaced}`
112+
"SIM300", # Yoda condition detected
113+
"SIM401", # Use `{contents}` instead of an if block
114+
"SIM910", # Use `{expected}` instead of `{actual}` (dict-get-with-none-default)
115+
"SIM911", # Use `{expected}` instead of `{actual}` (zip-dict-keys-and-values)
116+
# Don't include TC rules that create a TYPE_CHECKING block or stringifies annotations
117+
"TC004", # Move import `{qualified_name}` out of type-checking block. Import is used for more than type hinting.
118+
"TC005", # Found empty type-checking block
119+
# "TC008", # TODO: Enable when out of preview
120+
"TC010", # Invalid string member in `X | Y`-style union type
97121
]
98122
extend-safe-fixes = [
99123
"UP036", # Remove unnecessary `sys.version_info` blocks

stdlib/asyncio/__init__.pyi

-178
Original file line numberDiff line numberDiff line change
@@ -410,93 +410,6 @@ if sys.platform == "win32":
410410
"WindowsSelectorEventLoopPolicy", # from windows_events
411411
"WindowsProactorEventLoopPolicy", # from windows_events
412412
)
413-
elif sys.version_info >= (3, 10):
414-
__all__ = (
415-
"BaseEventLoop", # from base_events
416-
"Server", # from base_events
417-
"coroutine", # from coroutines
418-
"iscoroutinefunction", # from coroutines
419-
"iscoroutine", # from coroutines
420-
"AbstractEventLoopPolicy", # from events
421-
"AbstractEventLoop", # from events
422-
"AbstractServer", # from events
423-
"Handle", # from events
424-
"TimerHandle", # from events
425-
"get_event_loop_policy", # from events
426-
"set_event_loop_policy", # from events
427-
"get_event_loop", # from events
428-
"set_event_loop", # from events
429-
"new_event_loop", # from events
430-
"get_child_watcher", # from events
431-
"set_child_watcher", # from events
432-
"_set_running_loop", # from events
433-
"get_running_loop", # from events
434-
"_get_running_loop", # from events
435-
"CancelledError", # from exceptions
436-
"InvalidStateError", # from exceptions
437-
"TimeoutError", # from exceptions
438-
"IncompleteReadError", # from exceptions
439-
"LimitOverrunError", # from exceptions
440-
"SendfileNotAvailableError", # from exceptions
441-
"Future", # from futures
442-
"wrap_future", # from futures
443-
"isfuture", # from futures
444-
"Lock", # from locks
445-
"Event", # from locks
446-
"Condition", # from locks
447-
"Semaphore", # from locks
448-
"BoundedSemaphore", # from locks
449-
"BaseProtocol", # from protocols
450-
"Protocol", # from protocols
451-
"DatagramProtocol", # from protocols
452-
"SubprocessProtocol", # from protocols
453-
"BufferedProtocol", # from protocols
454-
"run", # from runners
455-
"Queue", # from queues
456-
"PriorityQueue", # from queues
457-
"LifoQueue", # from queues
458-
"QueueFull", # from queues
459-
"QueueEmpty", # from queues
460-
"StreamReader", # from streams
461-
"StreamWriter", # from streams
462-
"StreamReaderProtocol", # from streams
463-
"open_connection", # from streams
464-
"start_server", # from streams
465-
"create_subprocess_exec", # from subprocess
466-
"create_subprocess_shell", # from subprocess
467-
"Task", # from tasks
468-
"create_task", # from tasks
469-
"FIRST_COMPLETED", # from tasks
470-
"FIRST_EXCEPTION", # from tasks
471-
"ALL_COMPLETED", # from tasks
472-
"wait", # from tasks
473-
"wait_for", # from tasks
474-
"as_completed", # from tasks
475-
"sleep", # from tasks
476-
"gather", # from tasks
477-
"shield", # from tasks
478-
"ensure_future", # from tasks
479-
"run_coroutine_threadsafe", # from tasks
480-
"current_task", # from tasks
481-
"all_tasks", # from tasks
482-
"_register_task", # from tasks
483-
"_unregister_task", # from tasks
484-
"_enter_task", # from tasks
485-
"_leave_task", # from tasks
486-
"to_thread", # from threads
487-
"BaseTransport", # from transports
488-
"ReadTransport", # from transports
489-
"WriteTransport", # from transports
490-
"Transport", # from transports
491-
"DatagramTransport", # from transports
492-
"SubprocessTransport", # from transports
493-
"SelectorEventLoop", # from windows_events
494-
"ProactorEventLoop", # from windows_events
495-
"IocpProactor", # from windows_events
496-
"DefaultEventLoopPolicy", # from windows_events
497-
"WindowsSelectorEventLoopPolicy", # from windows_events
498-
"WindowsProactorEventLoopPolicy", # from windows_events
499-
)
500413
elif sys.version_info >= (3, 9):
501414
__all__ = (
502415
"BaseEventLoop", # from base_events
@@ -1059,97 +972,6 @@ else:
1059972
"ThreadedChildWatcher", # from unix_events
1060973
"DefaultEventLoopPolicy", # from unix_events
1061974
)
1062-
elif sys.version_info >= (3, 10):
1063-
__all__ = (
1064-
"BaseEventLoop", # from base_events
1065-
"Server", # from base_events
1066-
"coroutine", # from coroutines
1067-
"iscoroutinefunction", # from coroutines
1068-
"iscoroutine", # from coroutines
1069-
"AbstractEventLoopPolicy", # from events
1070-
"AbstractEventLoop", # from events
1071-
"AbstractServer", # from events
1072-
"Handle", # from events
1073-
"TimerHandle", # from events
1074-
"get_event_loop_policy", # from events
1075-
"set_event_loop_policy", # from events
1076-
"get_event_loop", # from events
1077-
"set_event_loop", # from events
1078-
"new_event_loop", # from events
1079-
"get_child_watcher", # from events
1080-
"set_child_watcher", # from events
1081-
"_set_running_loop", # from events
1082-
"get_running_loop", # from events
1083-
"_get_running_loop", # from events
1084-
"CancelledError", # from exceptions
1085-
"InvalidStateError", # from exceptions
1086-
"TimeoutError", # from exceptions
1087-
"IncompleteReadError", # from exceptions
1088-
"LimitOverrunError", # from exceptions
1089-
"SendfileNotAvailableError", # from exceptions
1090-
"Future", # from futures
1091-
"wrap_future", # from futures
1092-
"isfuture", # from futures
1093-
"Lock", # from locks
1094-
"Event", # from locks
1095-
"Condition", # from locks
1096-
"Semaphore", # from locks
1097-
"BoundedSemaphore", # from locks
1098-
"BaseProtocol", # from protocols
1099-
"Protocol", # from protocols
1100-
"DatagramProtocol", # from protocols
1101-
"SubprocessProtocol", # from protocols
1102-
"BufferedProtocol", # from protocols
1103-
"run", # from runners
1104-
"Queue", # from queues
1105-
"PriorityQueue", # from queues
1106-
"LifoQueue", # from queues
1107-
"QueueFull", # from queues
1108-
"QueueEmpty", # from queues
1109-
"StreamReader", # from streams
1110-
"StreamWriter", # from streams
1111-
"StreamReaderProtocol", # from streams
1112-
"open_connection", # from streams
1113-
"start_server", # from streams
1114-
"open_unix_connection", # from streams
1115-
"start_unix_server", # from streams
1116-
"create_subprocess_exec", # from subprocess
1117-
"create_subprocess_shell", # from subprocess
1118-
"Task", # from tasks
1119-
"create_task", # from tasks
1120-
"FIRST_COMPLETED", # from tasks
1121-
"FIRST_EXCEPTION", # from tasks
1122-
"ALL_COMPLETED", # from tasks
1123-
"wait", # from tasks
1124-
"wait_for", # from tasks
1125-
"as_completed", # from tasks
1126-
"sleep", # from tasks
1127-
"gather", # from tasks
1128-
"shield", # from tasks
1129-
"ensure_future", # from tasks
1130-
"run_coroutine_threadsafe", # from tasks
1131-
"current_task", # from tasks
1132-
"all_tasks", # from tasks
1133-
"_register_task", # from tasks
1134-
"_unregister_task", # from tasks
1135-
"_enter_task", # from tasks
1136-
"_leave_task", # from tasks
1137-
"to_thread", # from threads
1138-
"BaseTransport", # from transports
1139-
"ReadTransport", # from transports
1140-
"WriteTransport", # from transports
1141-
"Transport", # from transports
1142-
"DatagramTransport", # from transports
1143-
"SubprocessTransport", # from transports
1144-
"SelectorEventLoop", # from unix_events
1145-
"AbstractChildWatcher", # from unix_events
1146-
"SafeChildWatcher", # from unix_events
1147-
"FastChildWatcher", # from unix_events
1148-
"PidfdChildWatcher", # from unix_events
1149-
"MultiLoopChildWatcher", # from unix_events
1150-
"ThreadedChildWatcher", # from unix_events
1151-
"DefaultEventLoopPolicy", # from unix_events
1152-
)
1153975
elif sys.version_info >= (3, 9):
1154976
__all__ = (
1155977
"BaseEventLoop", # from base_events

0 commit comments

Comments
 (0)