Merged
Conversation
747ef02 to
567fa92
Compare
eliben
reviewed
Mar 14, 2025
elftools/construct/core.py
Outdated
| raise RangeError("expected %d to %d, found %d" % | ||
| (self.mincount, self.maxcout, c), ex) | ||
| stream.seek(pos) | ||
| ctx = context.__copy__ if self.subcon.conflags & self.FLAG_COPY_CONTEXT else (lambda: context) |
Owner
There was a problem hiding this comment.
If at all possible, I would prefer to minimize changes inside elftools/construct
Is there a simpler way to make the type checker happy? Just predeclaring pos?
Contributor
Author
There was a problem hiding this comment.
Minimum would be an additional pos = -1 before the try, e.g.
--- a/elftools/construct/core.py
+++ b/elftools/construct/core.py
@@ -496,1 +496,1 @@ class Range(Subconstruct):
- c = 0
+ c = pos = -1`ruff check --select UP028 --fix --unsafe-fixes` - [UP028](https://docs.astral.sh/ruff/rules/yield-in-for-loop/) Signed-off-by: Philipp Hahn <[email protected]>
`ruff check --select PERF401` - [PERF401](https://docs.astral.sh/ruff/rules/manual-list-comprehension/) Signed-off-by: Philipp Hahn <[email protected]>
Signed-off-by: Philipp Hahn <[email protected]>
`ruff check --select RUF005 --unsafe-fixes --fix` - [RUF005](https://docs.astral.sh/ruff/rules/collection-literal-concatenation/) Signed-off-by: Philipp Hahn <[email protected]>
`len(…) ==/!=/> 0` is O(n), while `not …` is O(1) as long as … is not a generator. - PLC1802](https://docs.astral.sh/ruff/rules/len-test/) Signed-off-by: Philipp Hahn <[email protected]>
eliben
approved these changes
Mar 15, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
While working on #514 I took the opportunity to modernize some old code:
Use named arguments instead ofkwargsto allow typing themSimplifypyelftools.construct.core.Range:mypycomplained aboutposnot being declared in all cases; rewrite the logic.const, except while declaring them.Build _printable with a dict-comprehension: Basically this isrufffindingsℹ️ There is a small change in the output of
elftools.dwarf.lineprogram.LineState.__repr__(), where I removed the trailing\n. If you want it back append another""to the end of the tuple.