From 575abc49bc700b1cac4d154046d76b290fe9d7e4 Mon Sep 17 00:00:00 2001 From: Daniel Costa Date: Tue, 29 Jan 2019 15:59:03 -0200 Subject: [PATCH 01/42] Return section only required if at least one return is not None nor commentary --- scripts/tests/test_validate_docstrings.py | 16 +++++++++++++++- scripts/validate_docstrings.py | 4 +++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/scripts/tests/test_validate_docstrings.py b/scripts/tests/test_validate_docstrings.py index bb58449843096..389f6f2db5406 100644 --- a/scripts/tests/test_validate_docstrings.py +++ b/scripts/tests/test_validate_docstrings.py @@ -229,6 +229,20 @@ def good_imports(self): """ pass + def does_nothing(self, x): + """ + Do nothing and always return none. + + Parameters + ---------- + x : int + Useless parameter. + """ + if random.random()%2: + return #the method might return here + else: + return None #or perhaps here + class BadGenericDocStrings(object): """Everything here has a bad docstring @@ -783,7 +797,7 @@ def test_good_class(self, capsys): @pytest.mark.parametrize("func", [ 'plot', 'sample', 'random_letters', 'sample_values', 'head', 'head1', - 'contains', 'mode', 'good_imports']) + 'contains', 'mode', 'good_imports', 'does_nothing']) def test_good_functions(self, capsys, func): errors = validate_one(self._import_path( klass='GoodDocStrings', func=func))['errors'] diff --git a/scripts/validate_docstrings.py b/scripts/validate_docstrings.py index bce33f7e78daa..f262cad098591 100755 --- a/scripts/validate_docstrings.py +++ b/scripts/validate_docstrings.py @@ -691,7 +691,9 @@ def get_validation_data(doc): if doc.is_function_or_method: if not doc.returns: - if 'return' in doc.method_source: + if re.search('\n[ \t\f\v]*return' + + '(?![ \t\f\v]*(None)?[ \t\f\v]*[\n#])', + doc.method_source): errs.append(error('RT01')) else: if len(doc.returns) == 1 and doc.returns[0][1]: From 4b6406fae38c1ccbfa39d91d47a1dbd6a504310a Mon Sep 17 00:00:00 2001 From: Daniel Costa Date: Tue, 29 Jan 2019 16:24:52 -0200 Subject: [PATCH 02/42] fixed PEP8 issues --- scripts/tests/test_validate_docstrings.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/tests/test_validate_docstrings.py b/scripts/tests/test_validate_docstrings.py index 389f6f2db5406..56ecaa31692e1 100644 --- a/scripts/tests/test_validate_docstrings.py +++ b/scripts/tests/test_validate_docstrings.py @@ -238,10 +238,10 @@ def does_nothing(self, x): x : int Useless parameter. """ - if random.random()%2: - return #the method might return here + if random.random() % 2: + return # the method might return here else: - return None #or perhaps here + return None # or perhaps here class BadGenericDocStrings(object): From b204f11e97b9d3d5fa71b6a46fb7db3e5bf3a905 Mon Sep 17 00:00:00 2001 From: Daniel Costa Date: Tue, 29 Jan 2019 16:35:17 -0200 Subject: [PATCH 03/42] added another "return" on test --- scripts/tests/test_validate_docstrings.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/tests/test_validate_docstrings.py b/scripts/tests/test_validate_docstrings.py index 56ecaa31692e1..97f4663b9dfbe 100644 --- a/scripts/tests/test_validate_docstrings.py +++ b/scripts/tests/test_validate_docstrings.py @@ -231,7 +231,8 @@ def good_imports(self): def does_nothing(self, x): """ - Do nothing and always return none. + Do nothing and always return none, but might + return nothing as well. Parameters ---------- From 0a76a3af882d69cd983c7c6d800f0938b2264a1e Mon Sep 17 00:00:00 2001 From: Daniel Costa Date: Tue, 29 Jan 2019 16:54:15 -0200 Subject: [PATCH 04/42] now respects summary in a single line --- scripts/tests/test_validate_docstrings.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/scripts/tests/test_validate_docstrings.py b/scripts/tests/test_validate_docstrings.py index 97f4663b9dfbe..615c81b8b9ec2 100644 --- a/scripts/tests/test_validate_docstrings.py +++ b/scripts/tests/test_validate_docstrings.py @@ -231,8 +231,10 @@ def good_imports(self): def does_nothing(self, x): """ - Do nothing and always return none, but might - return nothing as well. + Do nothing and always return none. + + But in other cases it might also + return nothing at all. Parameters ---------- From d35ec842ae7308a6fba31bb296d8e5c049bb5aed Mon Sep 17 00:00:00 2001 From: Daniel Costa Date: Tue, 29 Jan 2019 16:55:22 -0200 Subject: [PATCH 05/42] only look for return commands after docstring --- scripts/validate_docstrings.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/scripts/validate_docstrings.py b/scripts/validate_docstrings.py index f262cad098591..37a40862592fe 100755 --- a/scripts/validate_docstrings.py +++ b/scripts/validate_docstrings.py @@ -691,9 +691,10 @@ def get_validation_data(doc): if doc.is_function_or_method: if not doc.returns: - if re.search('\n[ \t\f\v]*return' + + if re.search('\"\"\".*\"\"\".*' + + '\n[ \t\f\v]*return' + '(?![ \t\f\v]*(None)?[ \t\f\v]*[\n#])', - doc.method_source): + doc.method_source, flags=re.DOTALL): errs.append(error('RT01')) else: if len(doc.returns) == 1 and doc.returns[0][1]: From e7d9bed481382c00e9eb172b9dcb1cc1bf3e3753 Mon Sep 17 00:00:00 2001 From: Daniel Costa Date: Wed, 30 Jan 2019 15:53:10 -0200 Subject: [PATCH 06/42] Added comments to regex that finds non-bare return commands --- scripts/validate_docstrings.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/scripts/validate_docstrings.py b/scripts/validate_docstrings.py index 37a40862592fe..0df4bec7776db 100755 --- a/scripts/validate_docstrings.py +++ b/scripts/validate_docstrings.py @@ -691,10 +691,11 @@ def get_validation_data(doc): if doc.is_function_or_method: if not doc.returns: - if re.search('\"\"\".*\"\"\".*' + - '\n[ \t\f\v]*return' + - '(?![ \t\f\v]*(None)?[ \t\f\v]*[\n#])', - doc.method_source, flags=re.DOTALL): + if re.search(r""" \"\"\".*\"\"\".* # Skip the docstring. + \n[ \t\f\v]*return # Find a return command. + # Check if it's not bare or simply returns None. + (?![ \t\f\v]*(None)?[ \t\f\v]*[\n#]) """, + doc.method_source, flags=re.DOTALL|re.VERBOSE): errs.append(error('RT01')) else: if len(doc.returns) == 1 and doc.returns[0][1]: From 2cdd367b44946e1c6d795ad5e550fc5e71376d11 Mon Sep 17 00:00:00 2001 From: Daniel Costa Date: Wed, 30 Jan 2019 16:34:07 -0200 Subject: [PATCH 07/42] added space around bitwise or operator --- scripts/validate_docstrings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/validate_docstrings.py b/scripts/validate_docstrings.py index 0df4bec7776db..47211d60ad805 100755 --- a/scripts/validate_docstrings.py +++ b/scripts/validate_docstrings.py @@ -695,7 +695,7 @@ def get_validation_data(doc): \n[ \t\f\v]*return # Find a return command. # Check if it's not bare or simply returns None. (?![ \t\f\v]*(None)?[ \t\f\v]*[\n#]) """, - doc.method_source, flags=re.DOTALL|re.VERBOSE): + doc.method_source, re.DOTALL | re.VERBOSE): errs.append(error('RT01')) else: if len(doc.returns) == 1 and doc.returns[0][1]: From 0e25d93b075500b6faf44ae5ae9b506d1d9ecf85 Mon Sep 17 00:00:00 2001 From: Daniel Costa Date: Thu, 31 Jan 2019 21:08:04 -0200 Subject: [PATCH 08/42] Replaced [ \t\f\v] for \s on regex. --- scripts/validate_docstrings.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/validate_docstrings.py b/scripts/validate_docstrings.py index 47211d60ad805..8626615e2f024 100755 --- a/scripts/validate_docstrings.py +++ b/scripts/validate_docstrings.py @@ -692,9 +692,9 @@ def get_validation_data(doc): if doc.is_function_or_method: if not doc.returns: if re.search(r""" \"\"\".*\"\"\".* # Skip the docstring. - \n[ \t\f\v]*return # Find a return command. + \n\s*return # Find a return command. # Check if it's not bare or simply returns None. - (?![ \t\f\v]*(None)?[ \t\f\v]*[\n#]) """, + (?!\s*(None)?\s*[\n#]) """, doc.method_source, re.DOTALL | re.VERBOSE): errs.append(error('RT01')) else: From d5d9800c5c4da484f8a14fa40a572b3f79b4a758 Mon Sep 17 00:00:00 2001 From: Daniel Costa Date: Fri, 1 Feb 2019 00:14:47 -0200 Subject: [PATCH 09/42] Added test with valued return after bare returns --- scripts/tests/test_validate_docstrings.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/scripts/tests/test_validate_docstrings.py b/scripts/tests/test_validate_docstrings.py index 615c81b8b9ec2..fa3d204bb3a4e 100644 --- a/scripts/tests/test_validate_docstrings.py +++ b/scripts/tests/test_validate_docstrings.py @@ -613,6 +613,19 @@ def return_not_documented(self): """ return "Hello world!" + def return_not_documented_some_bare_returns(self): + """ + Lacks section for Returns. + + A section for Returns is needed if at least one + return is not bare or simply returns None. + """ + return None + return + return # just an empty return + return None # another empty return + return "Hello world!" + def yield_not_documented(self): """ Lacks section for Yields @@ -880,6 +893,8 @@ def test_bad_generic_functions(self, capsys, func): marks=pytest.mark.xfail), # Returns tests ('BadReturns', 'return_not_documented', ('No Returns section found',)), + ('BadReturns', 'return_not_documented_some_bare_returns', + ('No Returns section found',)), ('BadReturns', 'yield_not_documented', ('No Yields section found',)), pytest.param('BadReturns', 'no_type', ('foo',), marks=pytest.mark.xfail), From 073a6b649097f0a61549903c8649b36cc8c58179 Mon Sep 17 00:00:00 2001 From: Daniel Costa Date: Sat, 2 Feb 2019 18:01:52 -0200 Subject: [PATCH 10/42] method_source now returns source without docstring --- scripts/validate_docstrings.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/scripts/validate_docstrings.py b/scripts/validate_docstrings.py index 8626615e2f024..f789f26c69f56 100755 --- a/scripts/validate_docstrings.py +++ b/scripts/validate_docstrings.py @@ -490,7 +490,9 @@ def yields(self): @property def method_source(self): try: - return inspect.getsource(self.obj) + src = inspect.getsource(self.obj) + doc = re.search(r'""".*"""', src, re.DOTALL) # Find docstring. + return src[:doc.start()] + src[doc.end():] if doc else src except TypeError: return '' @@ -691,11 +693,10 @@ def get_validation_data(doc): if doc.is_function_or_method: if not doc.returns: - if re.search(r""" \"\"\".*\"\"\".* # Skip the docstring. - \n\s*return # Find a return command. + if re.search(r""" \n\s*return # Find a return command. # Check if it's not bare or simply returns None. (?!\s*(None)?\s*[\n#]) """, - doc.method_source, re.DOTALL | re.VERBOSE): + doc.method_source, re.VERBOSE): errs.append(error('RT01')) else: if len(doc.returns) == 1 and doc.returns[0][1]: From 0143b7c060777f1aade49ff4fdf007ace786c42a Mon Sep 17 00:00:00 2001 From: Daniel Costa Date: Sat, 2 Feb 2019 18:07:33 -0200 Subject: [PATCH 11/42] Updated to search string without whitespaces. --- scripts/validate_docstrings.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/validate_docstrings.py b/scripts/validate_docstrings.py index f789f26c69f56..0e0e0e930cd00 100755 --- a/scripts/validate_docstrings.py +++ b/scripts/validate_docstrings.py @@ -693,10 +693,10 @@ def get_validation_data(doc): if doc.is_function_or_method: if not doc.returns: - if re.search(r""" \n\s*return # Find a return command. + if re.search(r""" \nreturn # Find a return command. # Check if it's not bare or simply returns None. - (?!\s*(None)?\s*[\n#]) """, - doc.method_source, re.VERBOSE): + (?!(None)?[\n#]) """, + re.sub(' ', '', doc.method_source), re.VERBOSE): errs.append(error('RT01')) else: if len(doc.returns) == 1 and doc.returns[0][1]: From 76188dda8e8a5313a573f7c436fa4fe54b8ba1ed Mon Sep 17 00:00:00 2001 From: Daniel Costa Date: Sat, 2 Feb 2019 18:10:41 -0200 Subject: [PATCH 12/42] Simplified regex. --- scripts/validate_docstrings.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/scripts/validate_docstrings.py b/scripts/validate_docstrings.py index 0e0e0e930cd00..178995cd15f72 100755 --- a/scripts/validate_docstrings.py +++ b/scripts/validate_docstrings.py @@ -693,10 +693,8 @@ def get_validation_data(doc): if doc.is_function_or_method: if not doc.returns: - if re.search(r""" \nreturn # Find a return command. - # Check if it's not bare or simply returns None. - (?!(None)?[\n#]) """, - re.sub(' ', '', doc.method_source), re.VERBOSE): + if re.search(r"\nreturn(?!(None)?[\n#])", + re.sub(' ', '', doc.method_source)): errs.append(error('RT01')) else: if len(doc.returns) == 1 and doc.returns[0][1]: From 2051ea6d35137c9aca4132d7a4d88e5c7e9c75b2 Mon Sep 17 00:00:00 2001 From: Daniel Costa Date: Sat, 2 Feb 2019 18:40:22 -0200 Subject: [PATCH 13/42] Created clean_method_source property without comments or docstring. --- scripts/validate_docstrings.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/scripts/validate_docstrings.py b/scripts/validate_docstrings.py index 178995cd15f72..2e33816ad425d 100755 --- a/scripts/validate_docstrings.py +++ b/scripts/validate_docstrings.py @@ -490,12 +490,16 @@ def yields(self): @property def method_source(self): try: - src = inspect.getsource(self.obj) - doc = re.search(r'""".*"""', src, re.DOTALL) # Find docstring. - return src[:doc.start()] + src[doc.end():] if doc else src + return inspect.getsource(self.obj) except TypeError: return '' + @property + def clean_method_source(self): + src = self.method_source + src = re.sub(r'""".*"""', '', src, flags=re.DOTALL) # Remove docstring. + return src + @property def first_line_ends_in_dot(self): if self.doc: @@ -694,7 +698,7 @@ def get_validation_data(doc): if doc.is_function_or_method: if not doc.returns: if re.search(r"\nreturn(?!(None)?[\n#])", - re.sub(' ', '', doc.method_source)): + re.sub(' ', '', doc.clean_method_source)): errs.append(error('RT01')) else: if len(doc.returns) == 1 and doc.returns[0][1]: From ff17a79c97bf4d8e18545b22e60e55be4ca4a41a Mon Sep 17 00:00:00 2001 From: Daniel Costa Date: Sat, 2 Feb 2019 18:49:16 -0200 Subject: [PATCH 14/42] Updated clean_method_source to remove comments. --- scripts/validate_docstrings.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/validate_docstrings.py b/scripts/validate_docstrings.py index 2e33816ad425d..66add6555c776 100755 --- a/scripts/validate_docstrings.py +++ b/scripts/validate_docstrings.py @@ -498,6 +498,7 @@ def method_source(self): def clean_method_source(self): src = self.method_source src = re.sub(r'""".*"""', '', src, flags=re.DOTALL) # Remove docstring. + src = re.sub(r'#.*\n', r'\n', src) # Remove comments. return src @property @@ -697,7 +698,7 @@ def get_validation_data(doc): if doc.is_function_or_method: if not doc.returns: - if re.search(r"\nreturn(?!(None)?[\n#])", + if re.search(r"\nreturn(?!(None)?\n)", re.sub(' ', '', doc.clean_method_source)): errs.append(error('RT01')) else: From bafc25de8ce9d96562470141674e6822dc0153d8 Mon Sep 17 00:00:00 2001 From: Daniel Costa Date: Sat, 2 Feb 2019 19:03:46 -0200 Subject: [PATCH 15/42] Updated clean_method_source, remove duplicate and trailing whitespaces. --- scripts/validate_docstrings.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/scripts/validate_docstrings.py b/scripts/validate_docstrings.py index 66add6555c776..7abb7309ad016 100755 --- a/scripts/validate_docstrings.py +++ b/scripts/validate_docstrings.py @@ -499,6 +499,8 @@ def clean_method_source(self): src = self.method_source src = re.sub(r'""".*"""', '', src, flags=re.DOTALL) # Remove docstring. src = re.sub(r'#.*\n', r'\n', src) # Remove comments. + src = re.sub(r' +', ' ', src) # Remove duplicate whitespaces. + src = re.sub(r' \n', r'\n', src) # Remove trailing whitespaces. return src @property @@ -698,8 +700,7 @@ def get_validation_data(doc): if doc.is_function_or_method: if not doc.returns: - if re.search(r"\nreturn(?!(None)?\n)", - re.sub(' ', '', doc.clean_method_source)): + if re.search(r"return(?!( None)?\n)", doc.clean_method_source): errs.append(error('RT01')) else: if len(doc.returns) == 1 and doc.returns[0][1]: From 172115a5ed9a42ce7fd9b36479db6ba687bac71c Mon Sep 17 00:00:00 2001 From: Daniel Costa Date: Sat, 2 Feb 2019 19:10:34 -0200 Subject: [PATCH 16/42] Included test coverage for variable with "return" on the name. --- scripts/tests/test_validate_docstrings.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/tests/test_validate_docstrings.py b/scripts/tests/test_validate_docstrings.py index fa3d204bb3a4e..7d2b31e40285c 100644 --- a/scripts/tests/test_validate_docstrings.py +++ b/scripts/tests/test_validate_docstrings.py @@ -241,7 +241,8 @@ def does_nothing(self, x): x : int Useless parameter. """ - if random.random() % 2: + var_with_return_on_the_name = random.random() + if var_with_return_on_the_name % 2: return # the method might return here else: return None # or perhaps here From d5e0de8c8f4e3ada732255703dc22e045466de9a Mon Sep 17 00:00:00 2001 From: Daniel Costa Date: Sat, 2 Feb 2019 19:14:24 -0200 Subject: [PATCH 17/42] Updated regex with word bondaries. --- scripts/validate_docstrings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/validate_docstrings.py b/scripts/validate_docstrings.py index 7abb7309ad016..45dbd429f115f 100755 --- a/scripts/validate_docstrings.py +++ b/scripts/validate_docstrings.py @@ -700,7 +700,7 @@ def get_validation_data(doc): if doc.is_function_or_method: if not doc.returns: - if re.search(r"return(?!( None)?\n)", doc.clean_method_source): + if re.search(r"\breturn\b(?!( None)?\n)", doc.clean_method_source): errs.append(error('RT01')) else: if len(doc.returns) == 1 and doc.returns[0][1]: From 0e61d2c6d4a6d174e919f63f0c2a27ab2ebbc3b7 Mon Sep 17 00:00:00 2001 From: Daniel Costa Date: Sat, 2 Feb 2019 20:23:23 -0200 Subject: [PATCH 18/42] Shortened line. --- scripts/validate_docstrings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/validate_docstrings.py b/scripts/validate_docstrings.py index 45dbd429f115f..f508b605a2a0a 100755 --- a/scripts/validate_docstrings.py +++ b/scripts/validate_docstrings.py @@ -497,7 +497,7 @@ def method_source(self): @property def clean_method_source(self): src = self.method_source - src = re.sub(r'""".*"""', '', src, flags=re.DOTALL) # Remove docstring. + src = re.sub(r'""".*"""', '', src, 0, re.DOTALL) # Remove docstring. src = re.sub(r'#.*\n', r'\n', src) # Remove comments. src = re.sub(r' +', ' ', src) # Remove duplicate whitespaces. src = re.sub(r' \n', r'\n', src) # Remove trailing whitespaces. From 4c89bebb2c80919238e4091ba9cb7c4cc3d9a30e Mon Sep 17 00:00:00 2001 From: Daniel Costa Date: Sat, 2 Feb 2019 23:14:28 -0200 Subject: [PATCH 19/42] Merged return_not_documented tests into simplified version. --- scripts/tests/test_validate_docstrings.py | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/scripts/tests/test_validate_docstrings.py b/scripts/tests/test_validate_docstrings.py index 7d2b31e40285c..d489c5a8959f9 100644 --- a/scripts/tests/test_validate_docstrings.py +++ b/scripts/tests/test_validate_docstrings.py @@ -612,20 +612,10 @@ def return_not_documented(self): """ Lacks section for Returns """ - return "Hello world!" - - def return_not_documented_some_bare_returns(self): - """ - Lacks section for Returns. - - A section for Returns is needed if at least one - return is not bare or simply returns None. - """ - return None - return - return # just an empty return - return None # another empty return - return "Hello world!" + if random.random() % 2: + return None + else: + return "Hello world!" def yield_not_documented(self): """ @@ -894,8 +884,6 @@ def test_bad_generic_functions(self, capsys, func): marks=pytest.mark.xfail), # Returns tests ('BadReturns', 'return_not_documented', ('No Returns section found',)), - ('BadReturns', 'return_not_documented_some_bare_returns', - ('No Returns section found',)), ('BadReturns', 'yield_not_documented', ('No Yields section found',)), pytest.param('BadReturns', 'no_type', ('foo',), marks=pytest.mark.xfail), From b04110ae9dd5152666941c708e5fed5451fc275c Mon Sep 17 00:00:00 2001 From: Daniel Costa Date: Tue, 5 Feb 2019 09:36:29 -0200 Subject: [PATCH 20/42] Removed random elements from tests. --- scripts/tests/test_validate_docstrings.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/tests/test_validate_docstrings.py b/scripts/tests/test_validate_docstrings.py index d489c5a8959f9..de54ff70ae385 100644 --- a/scripts/tests/test_validate_docstrings.py +++ b/scripts/tests/test_validate_docstrings.py @@ -241,8 +241,8 @@ def does_nothing(self, x): x : int Useless parameter. """ - var_with_return_on_the_name = random.random() - if var_with_return_on_the_name % 2: + var_with_return_on_the_name = None + if True: return # the method might return here else: return None # or perhaps here @@ -612,7 +612,7 @@ def return_not_documented(self): """ Lacks section for Returns """ - if random.random() % 2: + if False: return None else: return "Hello world!" From 4b010922956287d46ff1c2fd2a8d9dba6cf81b0c Mon Sep 17 00:00:00 2001 From: Daniel Costa Date: Tue, 5 Feb 2019 11:16:46 -0200 Subject: [PATCH 21/42] Switched to AST approach. --- scripts/validate_docstrings.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/scripts/validate_docstrings.py b/scripts/validate_docstrings.py index f508b605a2a0a..df360aa0360ff 100755 --- a/scripts/validate_docstrings.py +++ b/scripts/validate_docstrings.py @@ -26,6 +26,7 @@ import importlib import doctest import tempfile +import ast import flake8.main.application @@ -699,8 +700,14 @@ def get_validation_data(doc): errs.append(error('PR09', param_name=param)) if doc.is_function_or_method: + (tree, ) = ast.parse(doc.method_source.strip()).body if not doc.returns: - if re.search(r"\breturn\b(?!( None)?\n)", doc.clean_method_source): + returns = [node.value for node in ast.walk(tree) + if isinstance(node, ast.Return)] + non_bare_returns = [r for r in returns if r is not None and + not (isinstance(r, ast.NameConstant) and + r.value is None)] + if any(non_bare_returns): errs.append(error('RT01')) else: if len(doc.returns) == 1 and doc.returns[0][1]: From 0928ba61afcba7d8b0b2b3860c0151931077043e Mon Sep 17 00:00:00 2001 From: Daniel Costa Date: Tue, 5 Feb 2019 11:17:24 -0200 Subject: [PATCH 22/42] Removed clean_method_source property. --- scripts/validate_docstrings.py | 9 --------- 1 file changed, 9 deletions(-) diff --git a/scripts/validate_docstrings.py b/scripts/validate_docstrings.py index df360aa0360ff..a9d9f94a538ff 100755 --- a/scripts/validate_docstrings.py +++ b/scripts/validate_docstrings.py @@ -495,15 +495,6 @@ def method_source(self): except TypeError: return '' - @property - def clean_method_source(self): - src = self.method_source - src = re.sub(r'""".*"""', '', src, 0, re.DOTALL) # Remove docstring. - src = re.sub(r'#.*\n', r'\n', src) # Remove comments. - src = re.sub(r' +', ' ', src) # Remove duplicate whitespaces. - src = re.sub(r' \n', r'\n', src) # Remove trailing whitespaces. - return src - @property def first_line_ends_in_dot(self): if self.doc: From 57fdb1ee32f012e505a4d7b594909de0ab54ebee Mon Sep 17 00:00:00 2001 From: Daniel Costa Date: Tue, 5 Feb 2019 12:34:28 -0200 Subject: [PATCH 23/42] Updated does_nothing test not to leave variable unused. --- scripts/tests/test_validate_docstrings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/tests/test_validate_docstrings.py b/scripts/tests/test_validate_docstrings.py index de54ff70ae385..010f9a91b9bfe 100644 --- a/scripts/tests/test_validate_docstrings.py +++ b/scripts/tests/test_validate_docstrings.py @@ -242,7 +242,7 @@ def does_nothing(self, x): Useless parameter. """ var_with_return_on_the_name = None - if True: + if var_with_return_on_the_name: return # the method might return here else: return None # or perhaps here From 00d5fdb9f492f2658f219d1dde8afd04933303a7 Mon Sep 17 00:00:00 2001 From: Daniel Costa Date: Thu, 7 Feb 2019 13:29:45 -0200 Subject: [PATCH 24/42] Reestructured and minimized tests. --- scripts/tests/test_validate_docstrings.py | 31 +++++++++++++---------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/scripts/tests/test_validate_docstrings.py b/scripts/tests/test_validate_docstrings.py index 010f9a91b9bfe..c9ce75635184c 100644 --- a/scripts/tests/test_validate_docstrings.py +++ b/scripts/tests/test_validate_docstrings.py @@ -229,23 +229,26 @@ def good_imports(self): """ pass - def does_nothing(self, x): + def no_returns(self): """ - Do nothing and always return none. + Say hello and have no returns. + """ + print("Hello World!") - But in other cases it might also - return nothing at all. + def empty_returns(self): + """ + Say hello and always return None. - Parameters - ---------- - x : int - Useless parameter. + Since this function never returns a value, this + docstring doesn't need a return section. """ - var_with_return_on_the_name = None - if var_with_return_on_the_name: - return # the method might return here + def say_hello(): + return "Hello World!" + say_hello() + if True: + return else: - return None # or perhaps here + return None class BadGenericDocStrings(object): @@ -615,7 +618,7 @@ def return_not_documented(self): if False: return None else: - return "Hello world!" + return True def yield_not_documented(self): """ @@ -804,7 +807,7 @@ def test_good_class(self, capsys): @pytest.mark.parametrize("func", [ 'plot', 'sample', 'random_letters', 'sample_values', 'head', 'head1', - 'contains', 'mode', 'good_imports', 'does_nothing']) + 'contains', 'mode', 'good_imports', 'no_returns', 'empty_returns']) def test_good_functions(self, capsys, func): errors = validate_one(self._import_path( klass='GoodDocStrings', func=func))['errors'] From 0a0c05e674f83018f3190e1179d591167fd52a95 Mon Sep 17 00:00:00 2001 From: Daniel Costa Date: Thu, 7 Feb 2019 13:42:35 -0200 Subject: [PATCH 25/42] Encapsulated search for returns on method_returns property. --- scripts/validate_docstrings.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/scripts/validate_docstrings.py b/scripts/validate_docstrings.py index a9d9f94a538ff..2b56c12cb3594 100755 --- a/scripts/validate_docstrings.py +++ b/scripts/validate_docstrings.py @@ -495,6 +495,16 @@ def method_source(self): except TypeError: return '' + @property + def method_returns(self): + (tree, ) = ast.parse(self.method_source.strip()).body + returns = [node.value for node in ast.walk(tree) + if isinstance(node, ast.Return)] + non_bare_returns = [r for r in returns if r is not None and + not (isinstance(r, ast.NameConstant) and + r.value is None)] + return non_bare_returns + @property def first_line_ends_in_dot(self): if self.doc: @@ -691,14 +701,8 @@ def get_validation_data(doc): errs.append(error('PR09', param_name=param)) if doc.is_function_or_method: - (tree, ) = ast.parse(doc.method_source.strip()).body if not doc.returns: - returns = [node.value for node in ast.walk(tree) - if isinstance(node, ast.Return)] - non_bare_returns = [r for r in returns if r is not None and - not (isinstance(r, ast.NameConstant) and - r.value is None)] - if any(non_bare_returns): + if any(ret is not None for ret in doc.method_returns): errs.append(error('RT01')) else: if len(doc.returns) == 1 and doc.returns[0][1]: From 6ab25349b9bd1dc3980fb4ad7ff848b154b50680 Mon Sep 17 00:00:00 2001 From: Daniel Costa Date: Thu, 7 Feb 2019 14:24:15 -0200 Subject: [PATCH 26/42] Updated method_returns property to ignore nested functions. --- scripts/validate_docstrings.py | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/scripts/validate_docstrings.py b/scripts/validate_docstrings.py index 2b56c12cb3594..29ad38575e6f9 100755 --- a/scripts/validate_docstrings.py +++ b/scripts/validate_docstrings.py @@ -498,12 +498,20 @@ def method_source(self): @property def method_returns(self): (tree, ) = ast.parse(self.method_source.strip()).body - returns = [node.value for node in ast.walk(tree) - if isinstance(node, ast.Return)] - non_bare_returns = [r for r in returns if r is not None and - not (isinstance(r, ast.NameConstant) and - r.value is None)] - return non_bare_returns + # Walk the tree recursively and gather the return nodes. + def gather_returns(node): + gathered = [node] if isinstance(node, ast.Return) else [] + for child in ast.iter_child_nodes(node): + # Ignore nested functions and its subtrees. + if not isinstance(child, ast.FunctionDef): + gathered.extend(gather_returns(child)) + return gathered + return_values = [r.value for r in gather_returns(tree)] + # Replace NameConstant nodes valued None for None. + for i,v in enumerate(return_values): + if isinstance(v, ast.NameConstant) and v.value is None: + return_values[i] = None + return return_values @property def first_line_ends_in_dot(self): From 504ea1008d6cb93af4f2543fac377ff4d28472ae Mon Sep 17 00:00:00 2001 From: Daniel Costa Date: Thu, 7 Feb 2019 14:40:35 -0200 Subject: [PATCH 27/42] Updated ast.parse call. --- scripts/validate_docstrings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/validate_docstrings.py b/scripts/validate_docstrings.py index 29ad38575e6f9..33b01b1136ad9 100755 --- a/scripts/validate_docstrings.py +++ b/scripts/validate_docstrings.py @@ -497,7 +497,7 @@ def method_source(self): @property def method_returns(self): - (tree, ) = ast.parse(self.method_source.strip()).body + tree = ast.parse(self.method_source.strip()).body[0] # Walk the tree recursively and gather the return nodes. def gather_returns(node): gathered = [node] if isinstance(node, ast.Return) else [] From 17737d125747c3034eb64078cf49ce96d7221cfa Mon Sep 17 00:00:00 2001 From: Daniel Costa Date: Thu, 7 Feb 2019 15:02:59 -0200 Subject: [PATCH 28/42] Fixed linting errors. --- scripts/validate_docstrings.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/scripts/validate_docstrings.py b/scripts/validate_docstrings.py index 33b01b1136ad9..3030db571d67f 100755 --- a/scripts/validate_docstrings.py +++ b/scripts/validate_docstrings.py @@ -498,7 +498,7 @@ def method_source(self): @property def method_returns(self): tree = ast.parse(self.method_source.strip()).body[0] - # Walk the tree recursively and gather the return nodes. + def gather_returns(node): gathered = [node] if isinstance(node, ast.Return) else [] for child in ast.iter_child_nodes(node): @@ -506,9 +506,11 @@ def gather_returns(node): if not isinstance(child, ast.FunctionDef): gathered.extend(gather_returns(child)) return gathered + # Walk the tree recursively and gather the return nodes. return_values = [r.value for r in gather_returns(tree)] + # Replace NameConstant nodes valued None for None. - for i,v in enumerate(return_values): + for i, v in enumerate(return_values): if isinstance(v, ast.NameConstant) and v.value is None: return_values[i] = None return return_values From fe233512e36bd15785508e58a16d491f34fcd5e1 Mon Sep 17 00:00:00 2001 From: Daniel Costa Date: Thu, 7 Feb 2019 15:38:47 -0200 Subject: [PATCH 29/42] Updated method_source to remove common indentation from lines. --- scripts/validate_docstrings.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/scripts/validate_docstrings.py b/scripts/validate_docstrings.py index 3030db571d67f..4f4b49b812e04 100755 --- a/scripts/validate_docstrings.py +++ b/scripts/validate_docstrings.py @@ -491,13 +491,19 @@ def yields(self): @property def method_source(self): try: - return inspect.getsource(self.obj) + source = inspect.getsource(self.obj) + # Remove common indentation. + first_spaces = re.match(' +', source).group(0) + if first_spaces: + source = re.sub('^' + first_spaces, '', source) + source = re.sub(r'\n' + first_spaces, r'\n', source) + return source except TypeError: return '' @property def method_returns(self): - tree = ast.parse(self.method_source.strip()).body[0] + tree = ast.parse(self.method_source).body[0] def gather_returns(node): gathered = [node] if isinstance(node, ast.Return) else [] From 783eb396e60eac51c932c42ec26df856f9fe0d51 Mon Sep 17 00:00:00 2001 From: Daniel Costa Date: Thu, 7 Feb 2019 20:05:54 -0200 Subject: [PATCH 30/42] Corrected method_source. --- scripts/validate_docstrings.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/validate_docstrings.py b/scripts/validate_docstrings.py index 4f4b49b812e04..3dab748a6ac50 100755 --- a/scripts/validate_docstrings.py +++ b/scripts/validate_docstrings.py @@ -493,8 +493,9 @@ def method_source(self): try: source = inspect.getsource(self.obj) # Remove common indentation. - first_spaces = re.match(' +', source).group(0) + first_spaces = re.match(' +', source) if first_spaces: + first_spaces = first_spaces.group(0) source = re.sub('^' + first_spaces, '', source) source = re.sub(r'\n' + first_spaces, r'\n', source) return source From 2c41bd7a4fc1261848b8fffe23ec6b2b64b6feb4 Mon Sep 17 00:00:00 2001 From: Daniel Costa Date: Thu, 7 Feb 2019 20:50:13 -0200 Subject: [PATCH 31/42] Reverted ast.parse call. --- scripts/validate_docstrings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/validate_docstrings.py b/scripts/validate_docstrings.py index 3dab748a6ac50..189f918badb4a 100755 --- a/scripts/validate_docstrings.py +++ b/scripts/validate_docstrings.py @@ -504,7 +504,7 @@ def method_source(self): @property def method_returns(self): - tree = ast.parse(self.method_source).body[0] + (tree, ) = ast.parse(self.method_source).body def gather_returns(node): gathered = [node] if isinstance(node, ast.Return) else [] From 6e532154f9fb6be860134d7b40dfadafbe4973b9 Mon Sep 17 00:00:00 2001 From: Daniel Costa Date: Thu, 7 Feb 2019 22:00:36 -0200 Subject: [PATCH 32/42] Updated method_returns to respect empty method_sources. --- scripts/validate_docstrings.py | 37 ++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/scripts/validate_docstrings.py b/scripts/validate_docstrings.py index 189f918badb4a..f963fa8eb5d3f 100755 --- a/scripts/validate_docstrings.py +++ b/scripts/validate_docstrings.py @@ -504,23 +504,26 @@ def method_source(self): @property def method_returns(self): - (tree, ) = ast.parse(self.method_source).body - - def gather_returns(node): - gathered = [node] if isinstance(node, ast.Return) else [] - for child in ast.iter_child_nodes(node): - # Ignore nested functions and its subtrees. - if not isinstance(child, ast.FunctionDef): - gathered.extend(gather_returns(child)) - return gathered - # Walk the tree recursively and gather the return nodes. - return_values = [r.value for r in gather_returns(tree)] - - # Replace NameConstant nodes valued None for None. - for i, v in enumerate(return_values): - if isinstance(v, ast.NameConstant) and v.value is None: - return_values[i] = None - return return_values + tree = ast.parse(self.method_source).body + if tree: + root = tree[0] + def gather_returns(node): + gathered = [node] if isinstance(node, ast.Return) else [] + for child in ast.iter_child_nodes(node): + # Ignore nested functions and its subtrees. + if not isinstance(child, ast.FunctionDef): + gathered.extend(gather_returns(child)) + return gathered + # Walk the tree recursively and gather the return nodes. + return_values = [r.value for r in gather_returns(root)] + + # Replace NameConstant nodes valued None for None. + for i, v in enumerate(return_values): + if isinstance(v, ast.NameConstant) and v.value is None: + return_values[i] = None + return return_values + else: + return [] @property def first_line_ends_in_dot(self): From 2c60e4d3044001726282fdd37d9be2bc5dc0a323 Mon Sep 17 00:00:00 2001 From: Daniel Costa Date: Fri, 8 Feb 2019 04:57:53 -0200 Subject: [PATCH 33/42] Fixed linting error. --- scripts/validate_docstrings.py | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/validate_docstrings.py b/scripts/validate_docstrings.py index f963fa8eb5d3f..066709b1817d9 100755 --- a/scripts/validate_docstrings.py +++ b/scripts/validate_docstrings.py @@ -507,6 +507,7 @@ def method_returns(self): tree = ast.parse(self.method_source).body if tree: root = tree[0] + def gather_returns(node): gathered = [node] if isinstance(node, ast.Return) else [] for child in ast.iter_child_nodes(node): From 3e93cbe2eb12e58e17de332a00c3d593f3c73f32 Mon Sep 17 00:00:00 2001 From: Daniel Costa Date: Wed, 13 Feb 2019 15:30:20 -0200 Subject: [PATCH 34/42] Updated method_source property, removing from try block what can't fail. --- scripts/validate_docstrings.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/scripts/validate_docstrings.py b/scripts/validate_docstrings.py index 066709b1817d9..4149be66994a8 100755 --- a/scripts/validate_docstrings.py +++ b/scripts/validate_docstrings.py @@ -492,15 +492,15 @@ def yields(self): def method_source(self): try: source = inspect.getsource(self.obj) - # Remove common indentation. - first_spaces = re.match(' +', source) - if first_spaces: - first_spaces = first_spaces.group(0) - source = re.sub('^' + first_spaces, '', source) - source = re.sub(r'\n' + first_spaces, r'\n', source) - return source except TypeError: return '' + # Remove common indentation. + first_spaces = re.match(' +', source) + if first_spaces: + first_spaces = first_spaces.group(0) + source = re.sub('^' + first_spaces, '', source) + source = re.sub(r'\n' + first_spaces, r'\n', source) + return source @property def method_returns(self): From 1660060a1cda3969ac4cf64dafedcdf4e8e6d65d Mon Sep 17 00:00:00 2001 From: Daniel Costa Date: Wed, 13 Feb 2019 15:37:21 -0200 Subject: [PATCH 35/42] Refactored method_returns to method_returns_something. --- scripts/validate_docstrings.py | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/scripts/validate_docstrings.py b/scripts/validate_docstrings.py index 4149be66994a8..c735779b8d6f4 100755 --- a/scripts/validate_docstrings.py +++ b/scripts/validate_docstrings.py @@ -503,28 +503,28 @@ def method_source(self): return source @property - def method_returns(self): + def method_returns_something(self): + + def gather_returns(node): + gathered = [node] if isinstance(node, ast.Return) else [] + for child in ast.iter_child_nodes(node): + # Ignore nested functions and its subtrees. + if not isinstance(child, ast.FunctionDef): + gathered.extend(gather_returns(child)) + return gathered + tree = ast.parse(self.method_source).body if tree: root = tree[0] - - def gather_returns(node): - gathered = [node] if isinstance(node, ast.Return) else [] - for child in ast.iter_child_nodes(node): - # Ignore nested functions and its subtrees. - if not isinstance(child, ast.FunctionDef): - gathered.extend(gather_returns(child)) - return gathered # Walk the tree recursively and gather the return nodes. return_values = [r.value for r in gather_returns(root)] - # Replace NameConstant nodes valued None for None. for i, v in enumerate(return_values): if isinstance(v, ast.NameConstant) and v.value is None: return_values[i] = None - return return_values + return any(return_values) else: - return [] + return False @property def first_line_ends_in_dot(self): @@ -723,7 +723,7 @@ def get_validation_data(doc): if doc.is_function_or_method: if not doc.returns: - if any(ret is not None for ret in doc.method_returns): + if doc.method_returns_something: errs.append(error('RT01')) else: if len(doc.returns) == 1 and doc.returns[0][1]: From be6c9067300a688c32a6435794ac20819fd0ae29 Mon Sep 17 00:00:00 2001 From: Daniel Costa Date: Wed, 13 Feb 2019 15:46:17 -0200 Subject: [PATCH 36/42] Added docstring to method_returns_something. --- scripts/validate_docstrings.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/scripts/validate_docstrings.py b/scripts/validate_docstrings.py index c735779b8d6f4..346fd48207934 100755 --- a/scripts/validate_docstrings.py +++ b/scripts/validate_docstrings.py @@ -504,7 +504,18 @@ def method_source(self): @property def method_returns_something(self): + ''' + Check if a method can return something. + Bare returns, returns valued None and returns from nested functions are + disconsidered. + + Returns + ------- + bool + Whether the method can return something. + ''' + def gather_returns(node): gathered = [node] if isinstance(node, ast.Return) else [] for child in ast.iter_child_nodes(node): From 0b361de7f08b4673667fd369d9910c2c5c2c0481 Mon Sep 17 00:00:00 2001 From: Daniel Costa Date: Wed, 13 Feb 2019 16:01:18 -0200 Subject: [PATCH 37/42] Improved method_returns_something readability. --- scripts/validate_docstrings.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/scripts/validate_docstrings.py b/scripts/validate_docstrings.py index 346fd48207934..362a2cea7e440 100755 --- a/scripts/validate_docstrings.py +++ b/scripts/validate_docstrings.py @@ -515,20 +515,20 @@ def method_returns_something(self): bool Whether the method can return something. ''' - - def gather_returns(node): - gathered = [node] if isinstance(node, ast.Return) else [] + + def get_returns_not_on_nested_functions(node): + returns = [node] if isinstance(node, ast.Return) else [] for child in ast.iter_child_nodes(node): # Ignore nested functions and its subtrees. if not isinstance(child, ast.FunctionDef): - gathered.extend(gather_returns(child)) - return gathered + child_returns = get_returns_not_on_nested_functions(child) + returns.extend(child_returns) + return returns tree = ast.parse(self.method_source).body if tree: - root = tree[0] - # Walk the tree recursively and gather the return nodes. - return_values = [r.value for r in gather_returns(root)] + returns = get_returns_not_on_nested_functions(tree[0]) + return_values = [r.value for r in returns] # Replace NameConstant nodes valued None for None. for i, v in enumerate(return_values): if isinstance(v, ast.NameConstant) and v.value is None: From 2ebfa334b95021c8081f32e009aa29dab573cb6b Mon Sep 17 00:00:00 2001 From: Daniel Costa Date: Wed, 13 Feb 2019 16:04:23 -0200 Subject: [PATCH 38/42] Corrected method_returns_something property docstring. --- scripts/validate_docstrings.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/validate_docstrings.py b/scripts/validate_docstrings.py index 362a2cea7e440..550d6f7fc302b 100755 --- a/scripts/validate_docstrings.py +++ b/scripts/validate_docstrings.py @@ -505,7 +505,7 @@ def method_source(self): @property def method_returns_something(self): ''' - Check if a method can return something. + Check if the docstrings method can return something. Bare returns, returns valued None and returns from nested functions are disconsidered. @@ -513,7 +513,7 @@ def method_returns_something(self): Returns ------- bool - Whether the method can return something. + Whether the docstrings method can return something. ''' def get_returns_not_on_nested_functions(node): From 65b0f564f07f311d0fcfbad7de4346f5b4820b0b Mon Sep 17 00:00:00 2001 From: Marc Garcia Date: Wed, 13 Feb 2019 16:08:08 -0200 Subject: [PATCH 39/42] Removed unecessary print from test no_returns. Co-Authored-By: dluiscosta --- scripts/tests/test_validate_docstrings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/tests/test_validate_docstrings.py b/scripts/tests/test_validate_docstrings.py index c9ce75635184c..0b769b549966c 100644 --- a/scripts/tests/test_validate_docstrings.py +++ b/scripts/tests/test_validate_docstrings.py @@ -233,7 +233,7 @@ def no_returns(self): """ Say hello and have no returns. """ - print("Hello World!") + pass def empty_returns(self): """ From bbf39d0b3aee35c20416e5c5689ad6400f7624f5 Mon Sep 17 00:00:00 2001 From: Daniel Costa Date: Wed, 13 Feb 2019 16:24:22 -0200 Subject: [PATCH 40/42] Simplified return_not_documented test. --- scripts/tests/test_validate_docstrings.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/scripts/tests/test_validate_docstrings.py b/scripts/tests/test_validate_docstrings.py index 0b769b549966c..c8bda95595072 100644 --- a/scripts/tests/test_validate_docstrings.py +++ b/scripts/tests/test_validate_docstrings.py @@ -615,11 +615,8 @@ def return_not_documented(self): """ Lacks section for Returns """ - if False: - return None - else: - return True - + return "Hello world!" + def yield_not_documented(self): """ Lacks section for Yields From 2c66c896c267bf933d8599d962add392432dcfb4 Mon Sep 17 00:00:00 2001 From: Daniel Costa Date: Wed, 13 Feb 2019 16:29:16 -0200 Subject: [PATCH 41/42] Removed mistakenly added whitespaces. --- scripts/tests/test_validate_docstrings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/tests/test_validate_docstrings.py b/scripts/tests/test_validate_docstrings.py index c8bda95595072..6f78b91653a3f 100644 --- a/scripts/tests/test_validate_docstrings.py +++ b/scripts/tests/test_validate_docstrings.py @@ -616,7 +616,7 @@ def return_not_documented(self): Lacks section for Returns """ return "Hello world!" - + def yield_not_documented(self): """ Lacks section for Yields From 07a4b01b729e42444a726181ed00a3def64eeaad Mon Sep 17 00:00:00 2001 From: Daniel Costa Date: Thu, 14 Feb 2019 10:32:46 -0200 Subject: [PATCH 42/42] Added dedent. --- scripts/validate_docstrings.py | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/scripts/validate_docstrings.py b/scripts/validate_docstrings.py index 550d6f7fc302b..446cd60968312 100755 --- a/scripts/validate_docstrings.py +++ b/scripts/validate_docstrings.py @@ -27,6 +27,7 @@ import doctest import tempfile import ast +import textwrap import flake8.main.application @@ -494,13 +495,7 @@ def method_source(self): source = inspect.getsource(self.obj) except TypeError: return '' - # Remove common indentation. - first_spaces = re.match(' +', source) - if first_spaces: - first_spaces = first_spaces.group(0) - source = re.sub('^' + first_spaces, '', source) - source = re.sub(r'\n' + first_spaces, r'\n', source) - return source + return textwrap.dedent(source) @property def method_returns_something(self):