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

Check sequence type before triggering unnecessary-enumerate (FURB148) len suggestion #7781

Merged
merged 6 commits into from
Oct 3, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Document behaviour in known problems
  • Loading branch information
tjkuson committed Oct 3, 2023
commit 57b2e752822496b6b881e64c02f4dcadffa0d252
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ use crate::registry::AsRule;
/// `range(len(...))` or the sequence itself, respectively, instead. This is
/// more efficient and communicates the intent of the code more clearly.
///
/// ## Known problems
/// This rule is prone to false negatives due to type inference limitations;
/// namely, it will only suggest a fix using the `len` builtin function if the
/// sequence passed to `enumerate` is an instantiated as a list, set, dict, or
/// tuple literal, or annotated as such with a type annotation. This is because
/// the `len` builtin function is not defined for all object types (such as
/// generators).
///
/// ## Example
/// ```python
/// for index, _ in enumerate(sequence):
Expand Down
Loading