mirror of
https://github.com/graphql-python/graphene.git
synced 2024-11-22 09:36:44 +03:00
Merge pull request #419 from yen223/fix-docstring-whitespace
Fix docstring whitespace
This commit is contained in:
commit
62e58bd953
|
@ -3,6 +3,7 @@ from collections import OrderedDict
|
|||
import six
|
||||
|
||||
from ..utils.is_base_type import is_base_type
|
||||
from ..utils.trim_docstring import trim_docstring
|
||||
from .options import Options
|
||||
from .unmountedtype import UnmountedType
|
||||
|
||||
|
@ -23,7 +24,7 @@ class EnumTypeMeta(type):
|
|||
options = Options(
|
||||
attrs.pop('Meta', None),
|
||||
name=name,
|
||||
description=attrs.get('__doc__'),
|
||||
description=trim_docstring(attrs.get('__doc__')),
|
||||
enum=None,
|
||||
)
|
||||
if not options.enum:
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import six
|
||||
|
||||
from ..utils.is_base_type import is_base_type
|
||||
from ..utils.trim_docstring import trim_docstring
|
||||
from .abstracttype import AbstractTypeMeta
|
||||
from .inputfield import InputField
|
||||
from .options import Options
|
||||
|
@ -19,7 +20,7 @@ class InputObjectTypeMeta(AbstractTypeMeta):
|
|||
options = Options(
|
||||
attrs.pop('Meta', None),
|
||||
name=name,
|
||||
description=attrs.get('__doc__'),
|
||||
description=trim_docstring(attrs.get('__doc__')),
|
||||
local_fields=None,
|
||||
)
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import six
|
||||
|
||||
from ..utils.is_base_type import is_base_type
|
||||
from ..utils.trim_docstring import trim_docstring
|
||||
from .abstracttype import AbstractTypeMeta
|
||||
from .field import Field
|
||||
from .options import Options
|
||||
|
@ -18,7 +19,7 @@ class InterfaceMeta(AbstractTypeMeta):
|
|||
options = Options(
|
||||
attrs.pop('Meta', None),
|
||||
name=name,
|
||||
description=attrs.get('__doc__'),
|
||||
description=trim_docstring(attrs.get('__doc__')),
|
||||
local_fields=None,
|
||||
)
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@ from collections import OrderedDict
|
|||
import six
|
||||
|
||||
from ..utils.is_base_type import is_base_type
|
||||
from ..utils.trim_docstring import trim_docstring
|
||||
from .abstracttype import AbstractTypeMeta
|
||||
from .field import Field
|
||||
from .interface import Interface
|
||||
|
@ -22,7 +23,7 @@ class ObjectTypeMeta(AbstractTypeMeta):
|
|||
options = _meta or Options(
|
||||
attrs.pop('Meta', None),
|
||||
name=name,
|
||||
description=attrs.get('__doc__'),
|
||||
description=trim_docstring(attrs.get('__doc__')),
|
||||
interfaces=(),
|
||||
local_fields=OrderedDict(),
|
||||
)
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
import six
|
||||
|
||||
from graphql.language.ast import (BooleanValue, FloatValue, IntValue,
|
||||
StringValue)
|
||||
|
||||
from ..utils.is_base_type import is_base_type
|
||||
from ..utils.trim_docstring import trim_docstring
|
||||
from .options import Options
|
||||
from .unmountedtype import UnmountedType
|
||||
|
||||
|
@ -19,7 +19,7 @@ class ScalarTypeMeta(type):
|
|||
options = Options(
|
||||
attrs.pop('Meta', None),
|
||||
name=name,
|
||||
description=attrs.get('__doc__'),
|
||||
description=trim_docstring(attrs.get('__doc__')),
|
||||
)
|
||||
|
||||
return type.__new__(cls, name, bases, dict(attrs, _meta=options))
|
||||
|
|
|
@ -173,3 +173,14 @@ def test_objecttype_container_benchmark(benchmark):
|
|||
@benchmark
|
||||
def create_objecttype():
|
||||
Container(field1='field1', field2='field2')
|
||||
|
||||
|
||||
def test_generate_objecttype_description():
|
||||
class MyObjectType(ObjectType):
|
||||
'''
|
||||
Documentation
|
||||
|
||||
Documentation line 2
|
||||
'''
|
||||
|
||||
assert MyObjectType._meta.description == "Documentation\n\nDocumentation line 2"
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import six
|
||||
|
||||
from ..utils.is_base_type import is_base_type
|
||||
from ..utils.trim_docstring import trim_docstring
|
||||
from .options import Options
|
||||
from .unmountedtype import UnmountedType
|
||||
|
||||
|
@ -16,7 +17,7 @@ class UnionMeta(type):
|
|||
options = Options(
|
||||
attrs.pop('Meta', None),
|
||||
name=name,
|
||||
description=attrs.get('__doc__'),
|
||||
description=trim_docstring(attrs.get('__doc__')),
|
||||
types=(),
|
||||
)
|
||||
|
||||
|
|
21
graphene/utils/tests/test_trim_docstring.py
Normal file
21
graphene/utils/tests/test_trim_docstring.py
Normal file
|
@ -0,0 +1,21 @@
|
|||
from ..trim_docstring import trim_docstring
|
||||
|
||||
|
||||
def test_trim_docstring():
|
||||
class WellDocumentedObject(object):
|
||||
"""
|
||||
This object is very well-documented. It has multiple lines in its
|
||||
description.
|
||||
|
||||
Multiple paragraphs too
|
||||
"""
|
||||
pass
|
||||
|
||||
assert (trim_docstring(WellDocumentedObject.__doc__) ==
|
||||
"This object is very well-documented. It has multiple lines in its\n"
|
||||
"description.\n\nMultiple paragraphs too")
|
||||
|
||||
class UndocumentedObject(object):
|
||||
pass
|
||||
|
||||
assert trim_docstring(UndocumentedObject.__doc__) is None
|
9
graphene/utils/trim_docstring.py
Normal file
9
graphene/utils/trim_docstring.py
Normal file
|
@ -0,0 +1,9 @@
|
|||
import inspect
|
||||
|
||||
|
||||
def trim_docstring(docstring):
|
||||
# Cleans up whitespaces from an indented docstring
|
||||
#
|
||||
# See https://www.python.org/dev/peps/pep-0257/
|
||||
# and https://docs.python.org/2/library/inspect.html#inspect.cleandoc
|
||||
return inspect.cleandoc(docstring) if docstring else None
|
Loading…
Reference in New Issue
Block a user