# Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
# For details: https://github.com/PyCQA/pylint/blob/main/LICENSE
# Copyright (c) https://github.com/PyCQA/pylint/blob/main/CONTRIBUTORS.txt
"""Looks for try/except statements with too much code in the try clause."""
from __future__ import annotations
from typing import TYPE_CHECKING
from astroid import nodes
from pylint import checkers
if TYPE_CHECKING:
from pylint.lint import PyLinter
class BroadTryClauseChecker(checkers.BaseChecker):
"""Checks for try clauses with too many lines.
According to PEP 8, ``try`` clauses shall contain the absolute minimum
amount of code. This checker enforces a maximum number of statements within
``try`` clauses.
"""
# configuration section name
name = "broad_try_clause"
msgs = {
"W0717": (
"%s",
"too-many-try-statements",
"Try clause contains too many statements.",
)
}
options = (
(
"max-try-statements",
{
"default": 1,
"type": "int",
"metavar": "