-
Notifications
You must be signed in to change notification settings - Fork 5
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
Feedback #4
Comments
Another thing, on many Needs try:
do_stuff()
except SomeException:
pass Doesn't need try:
do_stuff()
except SomeException:
print("workn't") Also, if using an empty from contextlib import suppress
with suppress(SomeException):
do_stuff()
|
https://github.com/Pathos315/pdfcurate/blob/63f41324d71a6e8425dfd8693bad3638237da80f/altscraper/program_v008.py#L71 # Use Optional[] for values that could be None
x: Optional[str] = some_function()
|
https://github.com/Pathos315/pdfcurate/blob/63f41324d71a6e8425dfd8693bad3638237da80f/altscraper/program_v008.py#L20 |
https://github.com/Pathos315/pdfcurate/blob/63f41324d71a6e8425dfd8693bad3638237da80f/altscraper/program_v008.py#L61-L69 except (json.decoder.JSONDecodeError, KeyError) as err:
print(f"{search_text} failed to serialize to Python object, moving to next available object. Reason Given:", err)
logging.error(err)
|
https://github.com/Pathos315/pdfcurate/blob/63f41324d71a6e8425dfd8693bad3638237da80f/altscraper/program_v008.py#L80-L81 |
Agreed on all points, will work these into the next release/patch |
https://github.com/Pathos315/pdfcurate/blob/63f41324d71a6e8425dfd8693bad3638237da80f/altscraper/program_v008.py#L38-L51 If it did fail, one of the So subsequent parts of code that rely on It could be a good idea to re-raise the exception on those One way of doing that is simply adding try:
r = requests.request("GET", URL_DMNSNS, params=querystring)
r.raise_for_status()
logging.info(r.status_code)
except requests.exceptions.HTTPError as errh:
print("HTTP Error Encountered, moving to next available object. Reason Given:", errh)
logging.error(r.status_code, errh)
raise
except requests.exceptions.RequestException as e:
print("Unexcepted error encountered, moving to next available object. Reason Given:", e)
logging.error(r.status_code, e)
raise
The problem of doing it this way is that this function will then raise exceptions, that will need to be handled elsewhere. Another option would be to explicitly And technically, this is the current behavior of this function, because if So by explicitly returning |
Here's some feedback after a quick look over the code.
Some of the feedback here is mostly related to style and formatting. Although that's usually not going to keep the code from working, that can impact readability.
I've linked some sections of the PEP8 and other sources that I usually follow.
One thing I would suggest, but this is mostly personal preference, is to use a code formatter and linter, such as Black and Flake8. Those, among other tools, will greatly help with keeping a consistent style and making the code easier to read.
If you're interested, here's a nice list of the tools I personally use:
https://github.com/MicaelJarniac/BuildURL/blob/main/CONTRIBUTING.md (expand the "Quick Reference" section)
https://github.com/Pathos315/pdfcurate/blob/63f41324d71a6e8425dfd8693bad3638237da80f/altscraper/program_v008.py#L55-L59
I think that this
for
loop will iterate over the first element only, and immediately return, without iterating through the other elements.One way of working around that would be to create an empty list before the
for
, and instead of returning inside the loop, appending to that list, and then returning that list outside thefor
loop, after it's done.Another option would be to use
yield
instead ofreturn
, thus turning that function into a generator.https://github.com/Pathos315/pdfcurate/blob/63f41324d71a6e8425dfd8693bad3638237da80f/altscraper/program_v008.py#L1
https://github.com/Pathos315/pdfcurate/blob/63f41324d71a6e8425dfd8693bad3638237da80f/altscraper/program_v008.py#L16
https://github.com/Pathos315/pdfcurate/blob/63f41324d71a6e8425dfd8693bad3638237da80f/altscraper/program_v008.py#L17
https://github.com/Pathos315/pdfcurate/blob/63f41324d71a6e8425dfd8693bad3638237da80f/altscraper/program_v008.py#L26
https://github.com/Pathos315/pdfcurate/blob/63f41324d71a6e8425dfd8693bad3638237da80f/altscraper/program_v008.py#L34
https://github.com/Pathos315/pdfcurate/blob/63f41324d71a6e8425dfd8693bad3638237da80f/altscraper/program_v008.py#L33
The text was updated successfully, but these errors were encountered: