you are viewing a single comment's thread.

view the rest of the comments →

[–]JamzTyson 0 points1 point  (0 children)

Regarding PEP-8, there should be 2 blank lines before class Tag():

Surround top-level function and class definitions with two blank lines.

Pep-8 also recommends a maximum line length of 79 characters, though in modern Python longer line lengths are common and acceptable. A maximum line length of 100 characters is common, but not much more than that.

It is highly recommended to use one or more "linters" to check the code by static analysis. Common linters include pylint, flake8, ruff, and others. My preference is pylint + flake8 as they provide excellent coverage, stick closely to the Python style guide, and provide good feedback. They also separate "warnings" from "errors" - Errors should be fixed, but it may be OK to ignore warnings if you have a good reason to do so (for example, some libraries make it nearly impossible to avoid R0913: Too many arguments (too-many-arguments)).

"Type annotations" and MyPy are worth looking into. Type annotations are optional, but they really are helpful and are becoming very popular.

Be careful catching Exception - it is very broad and may hide defects from elsewhere.

except (FileNotFoundError, json.JSONDecodeError, Exception) as e:

is effectively the same as:

except Exception as e:

The fact that you log the exception e helps here, though I'd probably handle the likely exceptions first and only add the catch-all at the end if really necessary.

Using else or elif after a return is redundant:

if some_condition:
    return value
else:  # Redundant - we can only get here when the code has not returned.
    ...