Enable flake8-bugbear, but disable most checks. (#9499)

* Adds B00 to ignored checks.
* Fixes remaining issues.
This commit is contained in:
Jonathan de Jong 2021-03-16 19:19:27 +01:00 committed by GitHub
parent dd5e5dc1d6
commit 27d2820c33
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 29 additions and 10 deletions

1
changelog.d/9499.misc Normal file
View file

@ -0,0 +1 @@
Introduce bugbear to the test suite and fix some of it's lint violations.

View file

@ -18,7 +18,8 @@ ignore =
# E203: whitespace before ':' (which is contrary to pep8?) # E203: whitespace before ':' (which is contrary to pep8?)
# E731: do not assign a lambda expression, use a def # E731: do not assign a lambda expression, use a def
# E501: Line too long (black enforces this for us) # E501: Line too long (black enforces this for us)
ignore=W503,W504,E203,E731,E501 # B00: Subsection of the bugbear suite (TODO: add in remaining fixes)
ignore=W503,W504,E203,E731,E501,B00
[isort] [isort]
line_length = 88 line_length = 88

View file

@ -99,6 +99,7 @@ CONDITIONAL_REQUIREMENTS["lint"] = [
"isort==5.7.0", "isort==5.7.0",
"black==20.8b1", "black==20.8b1",
"flake8-comprehensions", "flake8-comprehensions",
"flake8-bugbear",
"flake8", "flake8",
] ]

View file

@ -22,7 +22,9 @@ logger = logging.getLogger(__name__)
try: try:
python_dependencies.check_requirements() python_dependencies.check_requirements()
except python_dependencies.DependencyException as e: except python_dependencies.DependencyException as e:
sys.stderr.writelines(e.message) sys.stderr.writelines(
e.message # noqa: B306, DependencyException.message is a property
)
sys.exit(1) sys.exit(1)

View file

@ -404,7 +404,11 @@ def _parse_key_servers(key_servers, federation_verify_certificates):
try: try:
jsonschema.validate(key_servers, TRUSTED_KEY_SERVERS_SCHEMA) jsonschema.validate(key_servers, TRUSTED_KEY_SERVERS_SCHEMA)
except jsonschema.ValidationError as e: except jsonschema.ValidationError as e:
raise ConfigError("Unable to parse 'trusted_key_servers': " + e.message) raise ConfigError(
"Unable to parse 'trusted_key_servers': {}".format(
e.message # noqa: B306, jsonschema.ValidationError.message is a valid attribute
)
)
for server in key_servers: for server in key_servers:
server_name = server["server_name"] server_name = server["server_name"]

View file

@ -56,7 +56,9 @@ class MetricsConfig(Config):
try: try:
check_requirements("sentry") check_requirements("sentry")
except DependencyException as e: except DependencyException as e:
raise ConfigError(e.message) raise ConfigError(
e.message # noqa: B306, DependencyException.message is a property
)
self.sentry_dsn = config["sentry"].get("dsn") self.sentry_dsn = config["sentry"].get("dsn")
if not self.sentry_dsn: if not self.sentry_dsn:

View file

@ -42,7 +42,9 @@ class OIDCConfig(Config):
try: try:
check_requirements("oidc") check_requirements("oidc")
except DependencyException as e: except DependencyException as e:
raise ConfigError(e.message) from e raise ConfigError(
e.message # noqa: B306, DependencyException.message is a property
) from e
# check we don't have any duplicate idp_ids now. (The SSO handler will also # check we don't have any duplicate idp_ids now. (The SSO handler will also
# check for duplicates when the REST listeners get registered, but that happens # check for duplicates when the REST listeners get registered, but that happens

View file

@ -176,7 +176,9 @@ class ContentRepositoryConfig(Config):
check_requirements("url_preview") check_requirements("url_preview")
except DependencyException as e: except DependencyException as e:
raise ConfigError(e.message) raise ConfigError(
e.message # noqa: B306, DependencyException.message is a property
)
if "url_preview_ip_range_blacklist" not in config: if "url_preview_ip_range_blacklist" not in config:
raise ConfigError( raise ConfigError(

View file

@ -76,7 +76,9 @@ class SAML2Config(Config):
try: try:
check_requirements("saml2") check_requirements("saml2")
except DependencyException as e: except DependencyException as e:
raise ConfigError(e.message) raise ConfigError(
e.message # noqa: B306, DependencyException.message is a property
)
self.saml2_enabled = True self.saml2_enabled = True

View file

@ -39,7 +39,9 @@ class TracerConfig(Config):
try: try:
check_requirements("opentracing") check_requirements("opentracing")
except DependencyException as e: except DependencyException as e:
raise ConfigError(e.message) raise ConfigError(
e.message # noqa: B306, DependencyException.message is a property
)
# The tracer is enabled so sanitize the config # The tracer is enabled so sanitize the config

View file

@ -219,7 +219,7 @@ class SSLClientConnectionCreator:
# ... and we also gut-wrench a '_synapse_tls_verifier' attribute into the # ... and we also gut-wrench a '_synapse_tls_verifier' attribute into the
# tls_protocol so that the SSL context's info callback has something to # tls_protocol so that the SSL context's info callback has something to
# call to do the cert verification. # call to do the cert verification.
setattr(tls_protocol, "_synapse_tls_verifier", self._verifier) tls_protocol._synapse_tls_verifier = self._verifier
return connection return connection

View file

@ -140,7 +140,7 @@ class TestCase(unittest.TestCase):
try: try:
self.assertEquals(attrs[key], getattr(obj, key)) self.assertEquals(attrs[key], getattr(obj, key))
except AssertionError as e: except AssertionError as e:
raise (type(e))(e.message + " for '.%s'" % key) raise (type(e))("Assert error for '.{}':".format(key)) from e
def assert_dict(self, required, actual): def assert_dict(self, required, actual):
"""Does a partial assert of a dict. """Does a partial assert of a dict.