2020-09-02 00:36:52 +02:00
[ tool . black ]
line-length = 100
2022-04-27 02:00:45 +02:00
target-version = [ "py38" ]
2021-03-04 23:33:41 +01:00
[ tool . isort ]
2022-12-04 10:59:47 +01:00
src_paths = [ "." , "tools" ]
2021-03-04 23:33:41 +01:00
known_third_party = "zulip"
profile = "black"
line_length = 100
2021-07-05 23:36:46 +02:00
[ tool . mypy ]
# Logistics of what code to check and how to handle the data.
scripts_are_modules = true
show_traceback = true
# See https://zulip.readthedocs.io/en/latest/testing/mypy.html#mypy-stubs-for-third-party-modules
# for notes on how we manage mypy stubs.
mypy_path = "$MYPY_CONFIG_FILE_DIR/stubs"
cache_dir = "$MYPY_CONFIG_FILE_DIR/var/mypy-cache"
2022-05-31 23:57:19 +02:00
# Enable strict mode, with some exceptions.
strict = true
2021-07-05 23:36:46 +02:00
disallow_subclassing_any = false
disallow_untyped_calls = false
disallow_untyped_decorators = false
warn_return_any = false
2022-06-01 00:09:19 +02:00
# Enable optional errors.
enable_error_code = [
"redundant-expr" ,
2022-06-01 01:31:28 +02:00
"truthy-bool" ,
2022-06-01 01:32:31 +02:00
"ignore-without-code" ,
2022-06-01 01:35:23 +02:00
"unused-awaitable" ,
2022-06-01 00:09:19 +02:00
]
2021-07-05 23:36:46 +02:00
# Display the codes needed for # type: ignore[code] annotations.
show_error_codes = true
# Warn of unreachable or redundant code.
warn_unreachable = true
2021-07-10 02:10:01 +02:00
2022-06-30 21:23:36 +02:00
# dmypy enables local_partial_types implicitly. We need mypy to align
# with this behavior.
local_partial_types = true
2022-10-27 20:41:08 +02:00
plugins = [ "mypy_django_plugin.main" , "pydantic.mypy" ]
2021-07-17 12:25:08 +02:00
2021-07-16 22:11:10 +02:00
[ [ tool . mypy . overrides ] ]
2021-07-17 12:25:08 +02:00
module = [ "zproject.configured_settings" , "zproject.settings" , "zproject.default_settings" ]
2021-07-16 22:11:10 +02:00
no_implicit_reexport = false
2021-07-10 02:10:01 +02:00
[ [ tool . mypy . overrides ] ]
module = [
"ahocorasick.*" ,
2022-12-04 11:24:46 +01:00
"aioapns.*" , # https://github.com/Fatal1ty/aioapns/issues/33
2021-07-10 02:10:01 +02:00
"bitfield.*" ,
"bmemcached.*" ,
2023-01-03 06:55:07 +01:00
"cairosvg.*" , # https://github.com/Kozea/CairoSVG/issues/373
rate_limit: Add a flag to lump all TOR exit node IPs together.
TOR users are legitimate users of the system; however, that system can
also be used for abuse -- specifically, by evading IP-based
rate-limiting.
For the purposes of IP-based rate-limiting, add a
RATE_LIMIT_TOR_TOGETHER flag, defaulting to false, which lumps all
requests from TOR exit nodes into the same bucket. This may allow a
TOR user to deny other TOR users access to the find-my-account and
new-realm endpoints, but this is a low cost for cutting off a
significant potential abuse vector.
If enabled, the list of TOR exit nodes is fetched from their public
endpoint once per hour, via a cron job, and cached on disk. Django
processes load this data from disk, and cache it in memcached.
Requests are spared from the burden of checking disk on failure via a
circuitbreaker, which trips of there are two failures in a row, and
only begins trying again after 10 minutes.
2021-11-03 21:43:02 +01:00
"circuitbreaker.*" ,
2022-05-03 06:18:10 +02:00
"defusedxml.*" , # https://github.com/tiran/defusedxml/issues/46
2021-07-10 02:10:01 +02:00
"digitalocean.*" ,
"django_auth_ldap.*" ,
2022-04-05 03:27:33 +02:00
"django_bmemcached.*" ,
2021-10-09 19:40:25 +02:00
"django_cte.*" ,
2021-07-10 02:10:01 +02:00
"django_otp.*" ,
2021-09-10 18:36:56 +02:00
"django_scim.*" ,
2021-07-10 02:10:01 +02:00
"DNS.*" ,
"fakeldap.*" ,
"gcm.*" ,
"gitlint.*" ,
"jsonref.*" ,
2023-01-03 06:55:07 +01:00
"ldap.*" , # https://github.com/python-ldap/python-ldap/issues/368
2022-05-03 06:18:10 +02:00
"moto.*" , # https://github.com/spulec/moto/issues/4944
2021-07-10 02:10:01 +02:00
"onelogin.*" ,
"pyinotify.*" ,
"pyoembed.*" ,
"pyuca.*" ,
2021-09-15 02:01:23 +02:00
"re2.*" ,
2022-05-03 06:18:10 +02:00
"requests_oauthlib.*" , # https://github.com/requests/requests-oauthlib/issues/428
2021-09-10 18:36:56 +02:00
"scim2_filter_parser.attr_paths" ,
2022-05-03 06:18:10 +02:00
"scrapy.*" , # https://github.com/scrapy/scrapy/issues/4041
2021-07-10 02:10:01 +02:00
"social_core.*" ,
"social_django.*" ,
"talon_core.*" ,
"tlds.*" ,
"twitter.*" ,
"two_factor.*" ,
]
ignore_missing_imports = true
2021-07-17 12:25:08 +02:00
[ tool . django-stubs ]
django_settings_module = "zproject.settings"
2022-10-30 00:07:03 +02:00
2022-10-27 20:41:08 +02:00
[ tool . pydantic-mypy ]
# See https://docs.pydantic.dev/latest/integrations/mypy/#mypy-plugin-capabilities for the effects of these options.
init_forbid_extra = true
init_typed = true
warn_required_dynamic_aliases = true
2022-10-30 00:07:03 +02:00
[ tool . ruff ]
# See https://github.com/charliermarsh/ruff#rules for error code definitions.
2022-11-08 06:45:10 +01:00
select = [
2022-11-16 06:32:34 +01:00
"ANN" , # annotations
2022-10-30 02:33:27 +02:00
"B" , # bugbear
2022-12-04 08:33:30 +01:00
"C4" , # comprehensions
2023-07-31 21:59:55 +02:00
"COM" , # trailing comma
2023-04-12 22:41:59 +02:00
"DJ" , # Django
2023-01-03 02:18:00 +01:00
"DTZ" , # naive datetime
2022-11-08 06:45:10 +01:00
"E" , # style errors
2023-02-02 03:40:54 +01:00
"EXE" , # shebang
2022-11-08 06:45:10 +01:00
"F" , # flakes
2023-07-31 22:04:41 +02:00
"FLY" , # string formatting
2023-02-04 01:44:12 +01:00
"G" , # logging format
2022-11-16 06:45:45 +01:00
"I" , # import sorting
2023-04-13 01:15:55 +02:00
"INT" , # gettext
2023-01-03 02:18:00 +01:00
"ISC" , # string concatenation
2022-11-16 06:32:50 +01:00
"N" , # naming
2023-08-01 00:23:52 +02:00
"PERF" , # performance
2022-12-04 10:36:40 +01:00
"PGH" , # pygrep-hooks
2023-01-03 02:18:00 +01:00
"PIE" , # miscellaneous
2023-02-02 03:40:54 +01:00
"PL" , # pylint
2023-04-13 01:15:55 +02:00
"PYI" , # typing stubs
2023-01-03 02:18:00 +01:00
"Q" , # quotes
2023-02-04 02:07:45 +01:00
"RSE" , # raise
2022-12-04 08:33:30 +01:00
"RUF" , # Ruff
2023-01-03 02:18:00 +01:00
"S" , # security
"SIM" , # simplify
2022-12-04 10:36:40 +01:00
"T10" , # debugger
2022-12-04 08:33:30 +01:00
"UP" , # upgrade
2022-10-30 02:33:27 +02:00
"W" , # style warnings
2022-11-16 06:54:18 +01:00
"YTT" , # sys.version
2022-10-30 02:33:27 +02:00
]
2022-10-30 00:07:03 +02:00
ignore = [
2022-11-16 06:32:34 +01:00
"ANN101" , # Missing type annotation for `self` in method
"ANN102" , # Missing type annotation for `cls` in classmethod
"ANN401" , # Dynamically typed expressions (typing.Any) are disallowed
2022-10-30 02:33:27 +02:00
"B007" , # Loop control variable not used within the loop body
2022-12-04 10:36:40 +01:00
"B008" , # Do not perform function calls in argument defaults
2022-12-04 08:33:30 +01:00
"B023" , # Function definition does not bind loop variable
"B904" , # Within an except clause, raise exceptions with raise ... from err or raise ... from None to distinguish them from errors in exception handling
2022-10-30 02:33:27 +02:00
"C408" , # Unnecessary `dict` call (rewrite as a literal)
2023-07-31 21:59:55 +02:00
"COM812" , # Trailing comma missing
2023-04-12 22:41:59 +02:00
"DJ001" , # Avoid using `null=True` on string-based fields
"DJ008" , # Model does not define `__str__` method
2022-10-30 00:07:03 +02:00
"E402" , # Module level import not at top of file
"E501" , # Line too long
"E731" , # Do not assign a lambda expression, use a def
2022-11-16 06:32:50 +01:00
"N802" , # Function name should be lowercase
"N806" , # Variable in function should be lowercase
2023-08-01 00:23:52 +02:00
"PERF203" , # `try`-`except` within a loop incurs performance overhead
2023-04-04 01:42:32 +02:00
"PLC1901" , # `s == ""` can be simplified to `not s` as an empty string is falsey
2023-03-04 01:24:14 +01:00
"PLR0911" , # Too many return statements
"PLR0912" , # Too many branches
2023-02-02 03:40:54 +01:00
"PLR0913" , # Too many arguments to function call
"PLR0915" , # Too many statements
"PLR2004" , # Magic value used in comparison
2023-03-04 01:24:14 +01:00
"PLR5501" , # Consider using `elif` instead of `else` then `if` to remove one indentation level
"PLW0603" , # Using the global statement is discouraged
"PLW2901" , # Outer for loop variable overwritten by inner for loop target
2022-12-04 08:33:30 +01:00
"RUF001" , # String contains ambiguous unicode character
2023-01-05 07:35:37 +01:00
"RUF002" , # Docstring contains ambiguous unicode character
2022-12-04 08:33:30 +01:00
"RUF003" , # Comment contains ambiguous unicode character
2023-07-19 22:57:31 +02:00
"RUF012" , # Mutable class attributes should be annotated with `typing.ClassVar`
2023-01-03 02:18:00 +01:00
"S101" , # Use of `assert` detected
"S105" , # Possible hardcoded password
"S106" , # Possible hardcoded password
"S107" , # Possible hardcoded password
2023-02-02 03:40:54 +01:00
"S110" , # `try`-`except`-`pass` detected, consider logging the exception
"S113" , # Probable use of requests call without timeout
2023-04-04 01:42:32 +02:00
"S310" , # Audit URL open for permitted schemes. Allowing use of `file:` or custom schemes is often unexpected.
"S311" , # Standard pseudo-random generators are not suitable for cryptographic purposes
2023-02-02 03:40:54 +01:00
"S324" , # Probable use of insecure hash functions in `hashlib`
2023-04-26 02:52:20 +02:00
"S603" , # `subprocess` call: check for execution of untrusted input
"S606" , # Starting a process without a shell
"S607" , # Starting a process with a partial executable path
2023-02-02 03:40:54 +01:00
"SIM103" , # Return the condition directly
"SIM108" , # Use ternary operator `action = "[commented]" if action == "created" else f"{action} a [comment]"` instead of if-else-block
2023-03-04 01:24:14 +01:00
"SIM114" , # Combine `if` branches using logical `or` operator
2023-02-02 03:40:54 +01:00
"SIM117" , # Use a single `with` statement with multiple contexts instead of nested `with` statements
"SIM401" , # Use `d.get(key, default)` instead of an `if` block
2022-10-30 00:07:03 +02:00
]
line-length = 100
2022-12-04 10:59:47 +01:00
src = [ "." , "tools" ]
2022-11-08 06:42:06 +01:00
target-version = "py38"
2022-11-16 06:45:45 +01:00
2023-04-13 01:15:55 +02:00
[ tool . ruff . flake8-gettext ]
extend-function-names = [ "gettext_lazy" ]
2022-11-16 06:45:45 +01:00
[ tool . ruff . isort ]
known-third-party = [ "zulip" ]
2023-08-03 02:09:35 +02:00
split-on-trailing-comma = false