leandrotoledo/python-telegram-bot

View on GitHub
telegram/ext/_applicationbuilder.py

Summary

Maintainability
F
4 days
Test Coverage

File _applicationbuilder.py has 1093 lines of code (exceeds 250 allowed). Consider refactoring.
Open

#!/usr/bin/env python
#
# A library that provides a Python interface to the Telegram Bot API
# Copyright (C) 2015-2024
# Leandro Toledo de Souza <devs@python-telegram-bot.org>
Severity: Major
Found in telegram/ext/_applicationbuilder.py - About 2 days to fix

    ApplicationBuilder has 48 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class ApplicationBuilder(Generic[BT, CCT, UD, CD, BD, JQ]):
        """This class serves as initializer for :class:`telegram.ext.Application` via the so called
        `builder pattern`_. To build a :class:`telegram.ext.Application`, one first initializes an
        instance of this class. Arguments for the :class:`telegram.ext.Application` to build are then
        added by subsequently calling the methods of the builder. Finally, the
    Severity: Minor
    Found in telegram/ext/_applicationbuilder.py - About 6 hrs to fix

      Function __init__ has 40 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          def __init__(self: "InitApplicationBuilder"):
              self._token: DVType[str] = DefaultValue("")
              self._base_url: DVType[str] = DefaultValue("https://api.telegram.org/bot")
              self._base_file_url: DVType[str] = DefaultValue("https://api.telegram.org/file/bot")
              self._connection_pool_size: DVInput[int] = DEFAULT_NONE
      Severity: Minor
      Found in telegram/ext/_applicationbuilder.py - About 1 hr to fix

        Function _request_check has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
        Open

            def _request_check(self, get_updates: bool) -> None:
                prefix = "get_updates_" if get_updates else ""
                name = prefix + "request"
        
                timeouts = ["connect_timeout", "read_timeout", "write_timeout", "pool_timeout"]
        Severity: Minor
        Found in telegram/ext/_applicationbuilder.py - About 1 hr to fix

        Cognitive Complexity

        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

        A method's cognitive complexity is based on a few simple rules:

        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
        • Code is considered more complex for each "break in the linear flow of the code"
        • Code is considered more complex when "flow breaking structures are nested"

        Further reading

        Function build has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
        Open

            def build(
                self: "ApplicationBuilder[BT, CCT, UD, CD, BD, JQ]",
            ) -> Application[BT, CCT, UD, CD, BD, JQ]:
                """Builds a :class:`telegram.ext.Application` with the provided arguments.
        
        
        Severity: Minor
        Found in telegram/ext/_applicationbuilder.py - About 1 hr to fix

        Cognitive Complexity

        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

        A method's cognitive complexity is based on a few simple rules:

        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
        • Code is considered more complex for each "break in the linear flow of the code"
        • Code is considered more complex when "flow breaking structures are nested"

        Further reading

        Function _request_param_check has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
        Open

            def _request_param_check(self, name: str, get_updates: bool) -> None:
                if get_updates and self._get_updates_request is not DEFAULT_NONE:
                    raise RuntimeError(  # disallow request args for get_updates if Request for that is set
                        _TWO_ARGS_REQ.format(f"get_updates_{name}", "get_updates_request instance")
                    )
        Severity: Minor
        Found in telegram/ext/_applicationbuilder.py - About 55 mins to fix

        Cognitive Complexity

        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

        A method's cognitive complexity is based on a few simple rules:

        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
        • Code is considered more complex for each "break in the linear flow of the code"
        • Code is considered more complex when "flow breaking structures are nested"

        Further reading

        Function updater has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

            def updater(self: BuilderType, updater: Optional[Updater]) -> BuilderType:
                """Sets a :class:`telegram.ext.Updater` instance for
                :attr:`telegram.ext.Application.updater`. The :attr:`telegram.ext.Updater.bot` and
                :attr:`telegram.ext.Updater.update_queue` will be used for
                :attr:`telegram.ext.Application.bot` and :attr:`telegram.ext.Application.update_queue`,
        Severity: Minor
        Found in telegram/ext/_applicationbuilder.py - About 35 mins to fix

        Cognitive Complexity

        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

        A method's cognitive complexity is based on a few simple rules:

        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
        • Code is considered more complex for each "break in the linear flow of the code"
        • Code is considered more complex when "flow breaking structures are nested"

        Further reading

        Function _build_request has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

            def _build_request(self, get_updates: bool) -> BaseRequest:
                prefix = "_get_updates_" if get_updates else "_"
                if not isinstance(getattr(self, f"{prefix}request"), DefaultValue):
                    return getattr(self, f"{prefix}request")
        
        
        Severity: Minor
        Found in telegram/ext/_applicationbuilder.py - About 35 mins to fix

        Cognitive Complexity

        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

        A method's cognitive complexity is based on a few simple rules:

        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
        • Code is considered more complex for each "break in the linear flow of the code"
        • Code is considered more complex when "flow breaking structures are nested"

        Further reading

        Function private_key has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

            def private_key(
                self: BuilderType,
                private_key: Union[bytes, FilePathInput],
                password: Optional[Union[bytes, FilePathInput]] = None,
            ) -> BuilderType:
        Severity: Minor
        Found in telegram/ext/_applicationbuilder.py - About 25 mins to fix

        Cognitive Complexity

        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

        A method's cognitive complexity is based on a few simple rules:

        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
        • Code is considered more complex for each "break in the linear flow of the code"
        • Code is considered more complex when "flow breaking structures are nested"

        Further reading

        There are no issues that match your filters.

        Category
        Status