Skip to content

Commit

Permalink
Merge branch 'master' into 743-fix-noise
Browse files Browse the repository at this point in the history
  • Loading branch information
tristanlatr authored Nov 5, 2023
2 parents 8463f13 + 14185de commit 09243b3
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 10 deletions.
5 changes: 5 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ This is the last major release to support Python 3.7.
Highest priority callables will be called first during post-processing.
* Fix too noisy ``--verbose`` mode (suppres some ambiguous annotations warnings).

pydoctor 23.9.1
^^^^^^^^^^^^^^^

* Fix regression in link not found warnings' line numbers.

pydoctor 23.9.0
^^^^^^^^^^^^^^^

Expand Down
20 changes: 10 additions & 10 deletions pydoctor/linker.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,6 @@ def __init__(self, obj:'model.Documentable') -> None:
self._scope = obj.parent or obj
self._module_linker = self._module.docstring_linker
self._scope_linker = self._scope.docstring_linker

self.switch_context(obj).__enter__()

@property
def obj(self) -> 'model.Documentable':
Expand All @@ -271,16 +269,18 @@ def warn_ambiguous_annotation(self, target:str) -> None:
)

def link_to(self, target: str, label: "Flattenable") -> Tag:
if self._module.isNameDefined(target):
self.warn_ambiguous_annotation(target)
return self._module_linker.link_to(target, label)
elif self._scope.isNameDefined(target):
return self._scope_linker.link_to(target, label)
else:
return self._module_linker.link_to(target, label)
with self.switch_context(self._obj):
if self._module.isNameDefined(target):
self.warn_ambiguous_annotation(target)
return self._module_linker.link_to(target, label)
elif self._scope.isNameDefined(target):
return self._scope_linker.link_to(target, label)
else:
return self._module_linker.link_to(target, label)

def link_xref(self, target: str, label: "Flattenable", lineno: int) -> Tag:
return self.obj.docstring_linker.link_xref(target, label, lineno)
with self.switch_context(self._obj):
return self.obj.docstring_linker.link_xref(target, label, lineno)

@contextlib.contextmanager
def switch_context(self, ob:Optional['model.Documentable']) -> Iterator[None]:
Expand Down
43 changes: 43 additions & 0 deletions pydoctor/test/test_epydoc2stan.py
Original file line number Diff line number Diff line change
Expand Up @@ -2120,3 +2120,46 @@ def func():
assert docstring2html(mod.contents['func'], docformat='plaintext') == expected
captured = capsys.readouterr().out
assert captured == ''

def test_regression_not_found_linenumbers(capsys: CapSys) -> None:
"""
Test for issue https://github.com/twisted/pydoctor/issues/745
"""
code = '''
__docformat__ = 'restructuredtext'
class Settings:
"""
Object that manages the configuration for Twine.
This object can only be instantiated with keyword arguments.
For example,
.. code-block:: python
Settings(True, username='fakeusername')
Will raise a :class:`TypeError`. Instead, you would want
.. code-block:: python
Settings(sign=True, username='fakeusername')
"""
def check_repository_url(self) -> None:
"""
Verify we are not using legacy PyPI.
"""
...
def create_repository(self) -> repository.Repository:
"""
Create a new repository for uploading.
"""
...
'''

mod = fromText(code, )
docstring2html(mod.contents['Settings'])
captured = capsys.readouterr().out
assert captured == '<test>:15: Cannot find link target for "TypeError"\n'

0 comments on commit 09243b3

Please sign in to comment.