Skip to content

Commit 557bba5

Browse files
authored
Merge pull request #48 from WhyNotHugo/linting
Minor linting tweaks
2 parents 09744e4 + 04fcc5c commit 557bba5

File tree

3 files changed

+11
-13
lines changed

3 files changed

+11
-13
lines changed

sphinxcontrib_django/docstrings/field_utils.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,20 +31,19 @@ def get_field_type(field, include_role=True):
3131
f":class:`~{type(field).__module__}.{type(field).__name__}` to"
3232
f" :class:`~{to.__module__}.{to.__name__}`"
3333
)
34-
elif isinstance(field, models.fields.reverse_related.ForeignObjectRel):
34+
if isinstance(field, models.fields.reverse_related.ForeignObjectRel):
3535
to = field.remote_field.model
3636
return (
3737
"Reverse"
3838
f" :class:`~{type(field.remote_field).__module__}.{type(field.remote_field).__name__}`"
3939
f" from :class:`~{to.__module__}.{to.__name__}`"
4040
)
41-
else:
42-
if include_role:
43-
# For the docstrings of attributes, the :class: role is required
44-
return f":class:`~{type(field).__module__}.{type(field).__name__}`"
45-
else:
46-
# For the :param: role in class docstrings, the :class: role is not required
47-
return f"~{type(field).__module__}.{type(field).__name__}"
41+
if include_role:
42+
# For the docstrings of attributes, the :class: role is required
43+
return f":class:`~{type(field).__module__}.{type(field).__name__}`"
44+
45+
# For the :param: role in class docstrings, the :class: role is not required
46+
return f"~{type(field).__module__}.{type(field).__name__}"
4847

4948

5049
def get_field_verbose_name(field):

sphinxcontrib_django/docstrings/patches.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
"""
22
This module contains patches for Django to improve its interaction with Sphinx.
33
"""
4+
import contextlib
5+
46
from django import apps, forms, test
57
from django.db import models
68

@@ -84,10 +86,8 @@ def patch_django_for_autodoc():
8486
for parent_module_str, django_modules in DJANGO_MODULE_PATHS.items():
8587
for django_module in django_modules:
8688
for module_class in map(django_module.__dict__.get, django_module.__all__):
87-
try:
89+
with contextlib.suppress(AttributeError):
8890
module_class.__module__ = parent_module_str
89-
except AttributeError:
90-
pass
9191

9292
# Fix module path of model manager
9393
models.manager.Manager.__module__ = "django.db.models"

tests/conftest.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@ def setup_app_with_different_config(app_params, make_app):
4343
def setup_app_with_different_config(**confoverrides):
4444
args, kwargs = app_params
4545
kwargs["confoverrides"] = confoverrides
46-
_app = make_app(*args, **kwargs)
47-
return _app
46+
return make_app(*args, **kwargs)
4847

4948
return setup_app_with_different_config
5049

0 commit comments

Comments
 (0)