-
-
Notifications
You must be signed in to change notification settings - Fork 55
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
replace os.path.getsize with Path("file.txt").stat().st_size #189
Conversation
Hello is my first try to extend refurb. if i did something wrong let me know please. the ID is 154 bcz latest is 153 (according to `grep -r "code = " .| cut -d"=" -f 2|sort|uniq`)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @doomedraven for this PR! Everything looks good for the most part, minus the comments I left.
In addition, there are no tests for this code yet. I need to update the documentation for this, but in short, all you have to do is create a new file named test/data/err_xxx.py
(where xxx
is the error id), and add some code which will emit an error:
from os.path import getsize
_ = getsize("filename")
Then, run make update-tests
. This will create a file called test/data/err_xxx.txt
with content similar to:
test/data/err_xxx.py:3:5 [FURBxxx]: Replace `os.path.getsize(x)` with `Path(x).stat().st_size`
Note that make update-tests
only runs if the .py
test file was changed, not if the check itself was updated. If you update the check but not the test file, you will have to run this instead:
refurb test/data/err_xxx.py --quiet > test/data/err_xxx.txt
I appreciate you putting in the effort to make a PR for Refurb, and for the most part, this is ready to be merged once the other notes are addressed!
(And sorry for the delay on this review, I have been on vacation for the past week 🌴)
thank you for feedback. i got a question. Generated test shows |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting, when I run it on my machine I get 155
. I can't see why it would be doing that, but if it is still doing that let me know and I will look into it further.
Also, the newly added os.path.getatime
related functions are not showing up in the tests. When debugging, they are showing up as genericpath.getatime
, so we probably need to expand these out like you did for the first one (ie, adding genericpath
, posixpath
, and ntpath
). Doing that for each one might get tedious, so we might want to clean up/normalize the path name before we do the lookup.
about 146 was because I had added check size to my refurb to check my code. Thanks for feedback |
To fix the failing tests, add another line to the os.path.getsize(__file__) And run |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your contribution!
thanks for help to get this merged |
Hello is my first try to extend refurb. if i did something wrong let me know please.
The ID is 154 bcz latest is 153 (according to
grep -r "code = " .| cut -d"=" -f 2|sort|uniq
)