Skip to content
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

Enable Ruff SIM #13309

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
8 changes: 8 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ select = [
"N", # pep8-naming
"PGH", # pygrep-hooks
"RUF", # Ruff-specific and unused-noqa
"SIM", # flake8-simplify
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still think I'd rather explicitly list the rules we think are useful here, rather than enabling the whole category and disabling specific rules. This category is just too hit-and-miss for me: some of the rules are pretty clear wins, but quite a few make some very opinionated suggestions that have high false-positive rates. Even if some of those rules don't have any false positives on typeshed today, there's a chance we might add code in the future that they'd emit false positives on, or there's a chance that Ruff might stabilise new SIM rules that have false positives on typeshed code.

If lint rules end up irritating us (or confusing contributors) more than they actually help us write better code, then it defeats the purpose of a linter, in my opinion :-)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated to be more specific about rules selection
I listed the rules I didn't select in the PR's description

"UP", # pyupgrade
"YTT", # flake8-2020
# Flake8 base rules
Expand Down Expand Up @@ -116,6 +117,13 @@ ignore = [
# Used for direct, non-subclass type comparison, for example: `type(val) is str`
# see https://github.com/astral-sh/ruff/issues/6465
"E721", # Do not compare types, use `isinstance()`
# Long single-line ternaries tend to be less readable with our 130 line-length
"SIM102", # Use a single if statement instead of nested if statements
"SIM108", # Use ternary operator {contents} instead of if-else-block
# Explicit short-circuiting loops can be more readable and any/all on a single line
"SIM110",
# contextlib.suppress is roughly 3x slower than try/except
"SIM105", # Use contextlib.suppress() instead of try-except-pass
# Slower and more verbose https://github.com/astral-sh/ruff/issues/7871
"UP038", # Use `X | Y` in `isinstance` call instead of `(X, Y)`
###
Expand Down
4 changes: 1 addition & 3 deletions stdlib/_ssl.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -240,9 +240,7 @@ OP_SINGLE_ECDH_USE: int
OP_NO_COMPRESSION: int
OP_ENABLE_MIDDLEBOX_COMPAT: int
OP_NO_RENEGOTIATION: int
if sys.version_info >= (3, 11):
OP_IGNORE_UNEXPECTED_EOF: int
elif sys.version_info >= (3, 8) and sys.platform == "linux":
if sys.version_info >= (3, 11) or sys.platform == "linux":
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OP_IGNORE_UNEXPECTED_EOF: int
if sys.version_info >= (3, 12):
OP_LEGACY_SERVER_CONNECT: int
Expand Down
182 changes: 2 additions & 180 deletions stdlib/asyncio/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -410,94 +410,7 @@ if sys.platform == "win32":
"WindowsSelectorEventLoopPolicy", # from windows_events
"WindowsProactorEventLoopPolicy", # from windows_events
)
elif sys.version_info >= (3, 10):
Copy link
Collaborator Author

@Avasam Avasam Jan 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apparently the 3.9 and 3.10 branches were duplicate (manual fix)

__all__ = (
"BaseEventLoop", # from base_events
"Server", # from base_events
"coroutine", # from coroutines
"iscoroutinefunction", # from coroutines
"iscoroutine", # from coroutines
"AbstractEventLoopPolicy", # from events
"AbstractEventLoop", # from events
"AbstractServer", # from events
"Handle", # from events
"TimerHandle", # from events
"get_event_loop_policy", # from events
"set_event_loop_policy", # from events
"get_event_loop", # from events
"set_event_loop", # from events
"new_event_loop", # from events
"get_child_watcher", # from events
"set_child_watcher", # from events
"_set_running_loop", # from events
"get_running_loop", # from events
"_get_running_loop", # from events
"CancelledError", # from exceptions
"InvalidStateError", # from exceptions
"TimeoutError", # from exceptions
"IncompleteReadError", # from exceptions
"LimitOverrunError", # from exceptions
"SendfileNotAvailableError", # from exceptions
"Future", # from futures
"wrap_future", # from futures
"isfuture", # from futures
"Lock", # from locks
"Event", # from locks
"Condition", # from locks
"Semaphore", # from locks
"BoundedSemaphore", # from locks
"BaseProtocol", # from protocols
"Protocol", # from protocols
"DatagramProtocol", # from protocols
"SubprocessProtocol", # from protocols
"BufferedProtocol", # from protocols
"run", # from runners
"Queue", # from queues
"PriorityQueue", # from queues
"LifoQueue", # from queues
"QueueFull", # from queues
"QueueEmpty", # from queues
"StreamReader", # from streams
"StreamWriter", # from streams
"StreamReaderProtocol", # from streams
"open_connection", # from streams
"start_server", # from streams
"create_subprocess_exec", # from subprocess
"create_subprocess_shell", # from subprocess
"Task", # from tasks
"create_task", # from tasks
"FIRST_COMPLETED", # from tasks
"FIRST_EXCEPTION", # from tasks
"ALL_COMPLETED", # from tasks
"wait", # from tasks
"wait_for", # from tasks
"as_completed", # from tasks
"sleep", # from tasks
"gather", # from tasks
"shield", # from tasks
"ensure_future", # from tasks
"run_coroutine_threadsafe", # from tasks
"current_task", # from tasks
"all_tasks", # from tasks
"_register_task", # from tasks
"_unregister_task", # from tasks
"_enter_task", # from tasks
"_leave_task", # from tasks
"to_thread", # from threads
"BaseTransport", # from transports
"ReadTransport", # from transports
"WriteTransport", # from transports
"Transport", # from transports
"DatagramTransport", # from transports
"SubprocessTransport", # from transports
"SelectorEventLoop", # from windows_events
"ProactorEventLoop", # from windows_events
"IocpProactor", # from windows_events
"DefaultEventLoopPolicy", # from windows_events
"WindowsSelectorEventLoopPolicy", # from windows_events
"WindowsProactorEventLoopPolicy", # from windows_events
)
elif sys.version_info >= (3, 9):
elif sys.version_info >= (3, 10) or sys.version_info >= (3, 9):
Avasam marked this conversation as resolved.
Show resolved Hide resolved
__all__ = (
"BaseEventLoop", # from base_events
"Server", # from base_events
Expand Down Expand Up @@ -1059,98 +972,7 @@ else:
"ThreadedChildWatcher", # from unix_events
"DefaultEventLoopPolicy", # from unix_events
)
elif sys.version_info >= (3, 10):
__all__ = (
"BaseEventLoop", # from base_events
"Server", # from base_events
"coroutine", # from coroutines
"iscoroutinefunction", # from coroutines
"iscoroutine", # from coroutines
"AbstractEventLoopPolicy", # from events
"AbstractEventLoop", # from events
"AbstractServer", # from events
"Handle", # from events
"TimerHandle", # from events
"get_event_loop_policy", # from events
"set_event_loop_policy", # from events
"get_event_loop", # from events
"set_event_loop", # from events
"new_event_loop", # from events
"get_child_watcher", # from events
"set_child_watcher", # from events
"_set_running_loop", # from events
"get_running_loop", # from events
"_get_running_loop", # from events
"CancelledError", # from exceptions
"InvalidStateError", # from exceptions
"TimeoutError", # from exceptions
"IncompleteReadError", # from exceptions
"LimitOverrunError", # from exceptions
"SendfileNotAvailableError", # from exceptions
"Future", # from futures
"wrap_future", # from futures
"isfuture", # from futures
"Lock", # from locks
"Event", # from locks
"Condition", # from locks
"Semaphore", # from locks
"BoundedSemaphore", # from locks
"BaseProtocol", # from protocols
"Protocol", # from protocols
"DatagramProtocol", # from protocols
"SubprocessProtocol", # from protocols
"BufferedProtocol", # from protocols
"run", # from runners
"Queue", # from queues
"PriorityQueue", # from queues
"LifoQueue", # from queues
"QueueFull", # from queues
"QueueEmpty", # from queues
"StreamReader", # from streams
"StreamWriter", # from streams
"StreamReaderProtocol", # from streams
"open_connection", # from streams
"start_server", # from streams
"open_unix_connection", # from streams
"start_unix_server", # from streams
"create_subprocess_exec", # from subprocess
"create_subprocess_shell", # from subprocess
"Task", # from tasks
"create_task", # from tasks
"FIRST_COMPLETED", # from tasks
"FIRST_EXCEPTION", # from tasks
"ALL_COMPLETED", # from tasks
"wait", # from tasks
"wait_for", # from tasks
"as_completed", # from tasks
"sleep", # from tasks
"gather", # from tasks
"shield", # from tasks
"ensure_future", # from tasks
"run_coroutine_threadsafe", # from tasks
"current_task", # from tasks
"all_tasks", # from tasks
"_register_task", # from tasks
"_unregister_task", # from tasks
"_enter_task", # from tasks
"_leave_task", # from tasks
"to_thread", # from threads
"BaseTransport", # from transports
"ReadTransport", # from transports
"WriteTransport", # from transports
"Transport", # from transports
"DatagramTransport", # from transports
"SubprocessTransport", # from transports
"SelectorEventLoop", # from unix_events
"AbstractChildWatcher", # from unix_events
"SafeChildWatcher", # from unix_events
"FastChildWatcher", # from unix_events
"PidfdChildWatcher", # from unix_events
"MultiLoopChildWatcher", # from unix_events
"ThreadedChildWatcher", # from unix_events
"DefaultEventLoopPolicy", # from unix_events
)
elif sys.version_info >= (3, 9):
elif sys.version_info >= (3, 10) or sys.version_info >= (3, 9):
Avasam marked this conversation as resolved.
Show resolved Hide resolved
__all__ = (
"BaseEventLoop", # from base_events
"Server", # from base_events
Expand Down
Loading