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

Configure Flake8 and resolve errors #347

Merged
merged 3 commits into from
Jun 1, 2021
Merged

Conversation

callahad
Copy link
Contributor

@callahad callahad commented May 28, 2021

Pull Request Checklist

  • Pull request includes a changelog file. The entry should:
    • Be a short description of your change which makes sense to users. "Fix a bug that prevented receiving messages from other servers." instead of "Move X method from EventStore to EventWorkerStore.".
    • Use markdown where necessary, mostly for code blocks.
    • End with either a period (.) or an exclamation mark (!).
    • Start with a capital letter.
  • Pull request includes a sign off

callahad added 2 commits May 28, 2021 22:47
Signed-off-by: Dan Callahan <danc@element.io>
Signed-off-by: Dan Callahan <danc@element.io>
Signed-off-by: Dan Callahan <danc@element.io>
@callahad
Copy link
Contributor Author

This supersedes #345


[flake8]
max-line-length = 88
extend-ignore = E203,E501,F821 # TODO: Fix E501 and F821
Copy link
Contributor Author

Choose a reason for hiding this comment

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

E501 is line length; we can deal with that separately.

F821 is undefined name... this occurs on two lines in sydent/http/federation_tls_options.py, and frankly I just need more time to understand context here, since that code cannot work as it is, but has been in place for a few years.

Copy link
Contributor

Choose a reason for hiding this comment

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

Re: F821- so if a piece of code is broken but it's been there awhile the prudent thing to do is investigate it thoroughly rather than just fix/remove?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep! See Chesterton's fence -- I don't know why that code is like that, and until I do, it's hard to know how it should be fixed. What I do know is that Sydent has been running with that code present for literally two years, so it can't be too problematic. So why?

Maybe its enclosing function is dead code? (Nope; I just checked and several paths eventually lead to it).

It's in an exception handler, so maybe the code it's wrapping never actually raises an exception, so control never passes into the except block? (Unlikely...)

Or maybe when it execution does flow into the except block it just... blows up with a NameError instead of properly handling things. (Likely!) Looking at the upstream Twisted code that this borrows from, it looks like its purpose is to just do a better job of logging an error, and then drop a connection... so quite possibly benign if it fails.

Copy link
Contributor

@H-Shay H-Shay left a comment

Choose a reason for hiding this comment

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

Seems very similar to mine!


[flake8]
max-line-length = 88
extend-ignore = E203,E501,F821 # TODO: Fix E501 and F821
Copy link
Contributor

Choose a reason for hiding this comment

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

Re: F821- so if a piece of code is broken but it's been there awhile the prudent thing to do is investigate it thoroughly rather than just fix/remove?

@@ -54,7 +54,7 @@ def _createSchema(self):
try:
logger.info("Importing %s", scriptPath)
c.executescript(fp.read())
except:
except Exception:
Copy link
Contributor

Choose a reason for hiding this comment

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

Exception here is the base class of exceptions and so should just function to catch any-typed exceptions?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep! See Flake8 Rules for a really good explanation, and the Python 3 Exception Hierarchy

@@ -60,7 +60,7 @@ def get_json(self, uri, max_size=None):
try:
# json.loads doesn't allow bytes in Python 3.5
json_body = json_decoder.decode(body.decode("UTF-8"))
except Exception as e:
Copy link
Contributor

Choose a reason for hiding this comment

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

I left this-I wasn't quite sure how the e was functioning (other than storing an exception if thrown?)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The e is just there to create a variable which points to the actual instance of the Exception you caught. Useful if you want to actually do something with the specific exception (programmatically inspecting it, etc.)

@callahad callahad merged commit cc72969 into matrix-org:main Jun 1, 2021
@callahad callahad deleted the flake8 branch June 1, 2021 15:52
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.

2 participants