diff --git a/docs/source/codedoc.rst b/docs/source/codedoc.rst index 4204505cc..c6384d432 100644 --- a/docs/source/codedoc.rst +++ b/docs/source/codedoc.rst @@ -338,41 +338,48 @@ Branch priorities ----------------- When pydoctor deals with try/except/else or if/else block, it makes sure that the names defined in -the "principal" flow do not get overridden by names defined in the except handlers or ifs' else block. -New names defined in these block will be processed normally. +the main flow has precedence over the definitions in ``except`` handlers or ``else`` blocks. Meaning that in the context of the code below, ``ssl`` would resolve to ``twisted.internet.ssl``: .. code:: python try: + # main flow from twisted.internet import ssl as _ssl except ImportError: - ssl = None + # exceptional flow + ssl = None # ignored since 'ssl' is defined in the main flow below. + var = True # not ignored since 'var' is not defined anywhere else. else: + # main flow ssl = _ssl -Similarly, in the context of the code below, the first ``CapSys`` class will be -documented and the second one will be ignored. +Similarly, in the context of the code below, the ``CapSys`` protocol under the ``TYPE_CHECKING`` block will be +documented and the runtime version will be ignored. .. code:: python from typing import TYPE_CHECKING if TYPE_CHECKING: + # main flow from typing import Protocol class CapSys(Protocol): def readouterr() -> Any: ... else: - class CapSys(object): # ignored + # secondary flow + class CapSys(object): # ignored since 'CapSys' is defined in the main flow above. ... -.. But sometimes pydoctor can be better off analysing the ``TYPE_CHECKING`` blocks and should -.. stick to the runtime version of the code instead. - -.. You can instruct pydoctor do to such things with a custom system class. - -.. .. code:: python - -.. class MySystem(model.System): -.. eval_if = {'my_mod':{'TYPE_CHECKING':False}} +But sometimes pydoctor can be better off analysing the ``TYPE_CHECKING`` blocks and should +stick to the runtime version of the code instead. +For these case, you might want to inverse the condition of if statement: + + .. code:: python + if not TYPE_CHECKING: + # main flow + from ._implementation import Thing + else: + # secondary flow + from ._typing import Thing # ignored since 'Thing' is defined in the main flow above.