Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix link not found line numbers #748

Merged
merged 1 commit into from
Nov 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ This is the last major release to support Python 3.7.
* `ExtRegistrar.register_post_processor()` now supports a `priority` argument that is an int.
Highest priority callables will be called first during post-processing.

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'
Loading