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

feat(rules): Add rule to check for mutations of loop iterator #446

Merged

Conversation

mimre25
Copy link
Contributor

@mimre25 mimre25 commented Jan 12, 2024

This implements a POC for #445.

I opted to go the route of alerting for any mutations of a loop iterator.

Note:
I picked B999 temporarily, not sure how the numbers are picked.
Also, I'm very much open to change the error message.

Would be happy if you could give this a review @cooperlees 🙂

@mimre25 mimre25 force-pushed the add-rule-to-check-for-mutation-of-loop-iterator branch from 46c0de7 to fd4e612 Compare January 12, 2024 18:51
Copy link
Collaborator

@cooperlees cooperlees left a comment

Choose a reason for hiding this comment

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

Many thanks for this. Looks good. I like this starting point.

Can you please:

  • Lets go with b038
  • Add more detailed few lines explanation into READNE.rst

bugbear.py Outdated Show resolved Hide resolved
bugbear.py Outdated Show resolved Hide resolved
bugbear.py Outdated Show resolved Hide resolved
Copy link
Collaborator

@cooperlees cooperlees left a comment

Choose a reason for hiding this comment

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

Many thanks for your contribution!

Will get a release our next week.

@cooperlees cooperlees merged commit 7c823af into PyCQA:main Jan 14, 2024
6 checks passed
@sahuagin
Copy link

I have an example for a false positive (I hope), if it's desired.
Setup. A CSV file as input with the first item in each row being an index number.

        id_pos = 0
        # lf is LogFile not LazyFrame
        lf = self._logger
        with self.rlock:
            lf.seek(0, 0)
            cpos = lf.tell()
            for line in lf:
                if len(line.strip()) == 0:
                    continue
                sl = line.split(b",", 1)
                self._mapper[sl[id_pos]] = cpos
                cpos = lf.tell()

Desired behavior is to find all indexes and record the file position where they start.
This just started getting flagged, which led me here. There are 4 more flags in the same file,
tell()
seek() x2
write()

@JelleZijlstra
Copy link
Collaborator

@sahuagin thanks for the report, #453 should fix this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants