From 338ea42ed942f4d01723fdc58ecec5d188beb507 Mon Sep 17 00:00:00 2001 From: Simon Ruggier Date: Thu, 27 Apr 2017 14:05:48 -0400 Subject: [PATCH 1/2] docstrings: fix "Sphinx param with type" pattern (#807) * docstrings: fix "Sphinx param with type" pattern Previously, the pattern only matched if the parameter description followed on the same line, like so: :param type foo: A param named foo. However, it's also valid for the parameter description to be wrapped onto the next line, like so: :param type foo: A param named foo. This change updates the pattern to match the second example as well, and adds a test to verify this behaviour. Fixes #806. * Add Simon Ruggier to the AUTHORS file --- AUTHORS.txt | 1 + jedi/evaluate/docstrings.py | 2 +- test/completion/docstring.py | 11 +++++++++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/AUTHORS.txt b/AUTHORS.txt index 48cb385f..b5619dcb 100644 --- a/AUTHORS.txt +++ b/AUTHORS.txt @@ -42,6 +42,7 @@ Cristi Burcă (@scribu) bstaint (@bstaint) Mathias Rav (@Mortal) Daniel Fiterman (@dfit99) +Simon Ruggier (@sruggier) Note: (@user) means a github user name. diff --git a/jedi/evaluate/docstrings.py b/jedi/evaluate/docstrings.py index 1b7db0da..788decb0 100644 --- a/jedi/evaluate/docstrings.py +++ b/jedi/evaluate/docstrings.py @@ -29,7 +29,7 @@ from jedi.evaluate.iterable import SequenceLiteralContext, FakeSequence DOCSTRING_PARAM_PATTERNS = [ r'\s*:type\s+%s:\s*([^\n]+)', # Sphinx - r'\s*:param\s+(\w+)\s+%s:[^\n]+', # Sphinx param with type + r'\s*:param\s+(\w+)\s+%s:[^\n]*', # Sphinx param with type r'\s*@type\s+%s:\s*([^\n]+)', # Epydoc ] diff --git a/test/completion/docstring.py b/test/completion/docstring.py index 338080a4..88db52d1 100644 --- a/test/completion/docstring.py +++ b/test/completion/docstring.py @@ -49,6 +49,17 @@ def sphinxy2(a, b, x): #? sphinxy2() + +def sphinxy_param_type_wrapped(a): + """ + :param str a: + Some description wrapped onto the next line with no space after the + colon. + """ + #? str() + a + + # local classes -> github #370 class ProgramNode(): pass From 6f1ee0cfa8c2b3790284ee5a13fb9495e82d774e Mon Sep 17 00:00:00 2001 From: Matthias Bussonnier Date: Fri, 21 Apr 2017 16:41:40 -0700 Subject: [PATCH 2/2] Use stacklevel in warnings or filters don't work. In particular with the right stacklevel IPython will display the warning if code is directly entered by the user. Without this info it does not. Use the opportunity to add in the warning since when things are deprecated. This leads to one less lookup of information for the user. --- jedi/api/__init__.py | 6 +++--- jedi/api/classes.py | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/jedi/api/__init__.py b/jedi/api/__init__.py index d8c6ede1..084a3483 100644 --- a/jedi/api/__init__.py +++ b/jedi/api/__init__.py @@ -93,10 +93,10 @@ class Script(object): encoding='utf-8', source_path=None, source_encoding=None, sys_path=None): if source_path is not None: - warnings.warn("Use path instead of source_path.", DeprecationWarning) + warnings.warn("Deprecated since version 0.7. Use path instead of source_path.", DeprecationWarning, stacklevel=2) path = source_path if source_encoding is not None: - warnings.warn("Use encoding instead of source_encoding.", DeprecationWarning) + warnings.warn("Deprecated since version 0.8. Use encoding instead of source_encoding.", DeprecationWarning, stacklevel=2) encoding = source_encoding self._orig_path = path @@ -158,7 +158,7 @@ class Script(object): Use :attr:`.path` instead. .. todo:: Remove! """ - warnings.warn("Use path instead of source_path.", DeprecationWarning) + warnings.warn("Deprecated since version 0.7. Use path instead of source_path.", DeprecationWarning, stacklevel=2) return self.path def __repr__(self): diff --git a/jedi/api/classes.py b/jedi/api/classes.py index 315195db..24b1bee3 100644 --- a/jedi/api/classes.py +++ b/jedi/api/classes.py @@ -254,7 +254,7 @@ class BaseDefinition(object): Use :meth:`.docstring` instead. .. todo:: Remove! """ - warnings.warn("Use docstring() instead.", DeprecationWarning) + warnings.warn("Deprecated since Jedi 0.8. Use docstring() instead.", DeprecationWarning, stacklevel=2) return self.docstring(raw=False) @property @@ -264,7 +264,7 @@ class BaseDefinition(object): Use :meth:`.docstring` instead. .. todo:: Remove! """ - warnings.warn("Use docstring() instead.", DeprecationWarning) + warnings.warn("Deprecated since Jedi 0.8. Use docstring() instead.", DeprecationWarning, stacklevel=2) return self.docstring(raw=True) @property @@ -656,7 +656,7 @@ class CallSignature(Definition): The name (e.g. 'isinstance') as a string. """ - warnings.warn("Use name instead.", DeprecationWarning) + warnings.warn("Deprecated since Jedi 0.8. Use name instead.", DeprecationWarning, stacklevel=2) return self.name @property @@ -685,7 +685,7 @@ class _Param(Definition): A function to get the whole code of the param. """ - warnings.warn("Use description instead.", DeprecationWarning) + warnings.warn("Deprecated since version 0.8. Use description instead.", DeprecationWarning, stacklevel=2) return self.description