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

[Scripts - 3] Added types for pylint and docstring_checker #16548

Merged
merged 7 commits into from
Nov 19, 2022

Conversation

aasiffaizal
Copy link
Contributor

@aasiffaizal aasiffaizal commented Nov 15, 2022

Overview

  1. This PR fixes or fixes part of #[fill_in_number_here].
  2. This PR does the following: This PR covers type annotation for the files scripts/docstrings_checker.py, scripts/linters/pylint_extensions.py .

Essential Checklist

  • The PR title starts with "Fix #bugnum: ", followed by a short, clear summary of the changes. (If this PR fixes part of an issue, prefix the title with "Fix part of #bugnum: ...".)
  • The linter/Karma presubmit checks have passed locally on your machine.
  • "Allow edits from maintainers" is checked. (See here for instructions on how to enable it.)
    • This lets reviewers restart your CircleCI tests for you.
  • The PR is made from a branch that's not called "develop".

Proof that changes are correct

Screenshot 2022-11-15 at 10 31 36 AM

Proof of changes on desktop with slow/throttled network

Proof of changes on mobile phone

Proof of changes in Arabic language

PR Pointers

  • Make sure to follow the instructions for making a code change.
  • If you need a review or an answer to a question, and don't have permissions to assign people, leave a comment like the following: "{{Question/comment}} @{{reviewer_username}} PTAL". Oppiabot will help assign that person for you.
  • For what code owners will expect, see the Code Owner's wiki page.
  • Make sure your PR follows conventions in the style guide, otherwise this will lead to review delays.
  • Never force push. If you do, your PR will be closed.
  • Some of the e2e tests are flaky, and can fail for reasons unrelated to your PR. We are working on fixing this, but in the meantime, if you need to restart the tests, please check the "If your build fails" wiki page.

@oppiabot
Copy link

oppiabot bot commented Nov 15, 2022

Hi @aasiffaizal, can you complete the following:

  1. The body of this PR is missing the required description, please update the body with a description of what this PR does.
  2. The karma and linter checklist has not been checked, please make sure to run the frontend tests and lint tests before pushing.
    Thanks!

@oppiabot
Copy link

oppiabot bot commented Nov 15, 2022

Hi @aasiffaizal please assign the required reviewer(s) for this PR. Thanks!

# Thus to avoid MyPy's error
# (Class cannot subclass 'BaseChecker' (has type 'Any')),
# we added an ignore here.
class GoogleDocstring(_check_docs_utils.GoogleDocstring): # type: ignore[misc]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pylint is partially typed and has the use of many Any, and hence it throws an error when inheriting any classes from them. Since stubs weren't available and specific stubbing of what we use wasn't also working since mypy doesn't support partial stubbing and can be found over here

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree but please create a different issue and mention it here, because issue #15613 was filed for missing stubs of the apache beam library. ( or if you want to use the same issue, then please update the content of #15613 ).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to close the conversation!

A new issue is created refer: #16548 (comment)

@aasiffaizal aasiffaizal marked this pull request as ready for review November 15, 2022 15:33
@aasiffaizal aasiffaizal requested a review from a team November 15, 2022 15:33
@aasiffaizal aasiffaizal requested a review from a team as a code owner November 15, 2022 15:33
@aasiffaizal
Copy link
Contributor Author

@vojtechjelinek @sahiljoster32 @U8NWXD Could you, please take a look?

@aasiffaizal aasiffaizal removed their assignment Nov 15, 2022
scripts/linters/pylint_extensions.py Outdated Show resolved Hide resolved
@U8NWXD U8NWXD assigned aasiffaizal and unassigned U8NWXD Nov 16, 2022
Copy link
Contributor

@vojtechjelinek vojtechjelinek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Took a pass.

scripts/linters/pylint_extensions.py Outdated Show resolved Hide resolved
@vojtechjelinek vojtechjelinek removed their assignment Nov 16, 2022
@aasiffaizal
Copy link
Contributor Author

@vojtechjelinek @U8NWXD I've addressed all the comments. Can you PTAL?

Copy link
Contributor

@sahiljoster32 sahiljoster32 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR looks good just some minor nits, Thanks @aasiffaizal!

"""Checks whether the object class in a module has been documented
or not. If the object class is not documented then adds an error
message.

Args:
tokens: Token. Object to access all tokens of a module.
node: astroid.scoped_nodes.Module. Node to access module content.
tokens: List[Token]. Object to access all tokens of a module.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
tokens: List[Token]. Object to access all tokens of a module.
tokens: List[TokenInfo]. Object to access all tokens of a module.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

"""Checks whether the Any type in a module has been documented
or not. If the Any type is not documented then adds an error
message.

Args:
tokens: Token. Object to access all tokens of a module.
node: astroid.scoped_nodes.Module. Node to access module content.
tokens: List[Token]. Object to access all tokens of a module.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -2113,7 +2284,13 @@ def _process_module_tokens(self, tokens, node):
'redundant-type-comment', line=comment_line_number, node=node)


class SingleSpaceAfterKeyWordChecker(checkers.BaseChecker):
# TODO(#15613): Here we use MyPy ignore because of the incomplete typing of
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a bit confused why #15613 issue used here, I think #15613 is filed for Apache beam stub. I would suggest to create a new issue for this pylint library.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah my bad. I have created a new issue #16567

@@ -2027,7 +2194,9 @@ def visit_module(self, node):
tokens = pylint_utils.tokenize_module(node)
self._process_module_tokens(tokens, node)

def _process_module_tokens(self, tokens, node):
def _process_module_tokens(
self, tokens: List[tokenize.TokenInfo], node: astroid.Module
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please update the docstring as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -1486,7 +1603,7 @@ class FunctionArgsOrderChecker(checkers.BaseChecker):
'\'cls\' should come first'),
}

def visit_functiondef(self, node):
def visit_functiondef(self, node: astroid.nodes.FunctionDef) -> None:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please update the docstring with FunctionDef

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -1348,7 +1437,9 @@ def check_single_constructor_params(self, class_doc, init_doc, class_node):
args=(class_node.name,),
node=class_node)

def _handle_no_raise_doc(self, excs, node):
def _handle_no_raise_doc(
self, excs: Set[str], node: astroid.nodes.FunctionDef
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

update docstring, please

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

self,
class_doc: _check_docs_utils.Docstring,
init_doc: _check_docs_utils.Docstring,
class_node: astroid.nodes.ClassDef
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please update docstring!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -863,7 +918,9 @@ def check_docstring_structure(self, node):
any(word in docstring[-2] for word in EXCLUDED_PHRASES)):
self.add_message('no-period-used', node=node)

def check_docstring_section_indentation(self, node):
def check_docstring_section_indentation(
self, node: astroid.nodes.FunctionDef
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please update docstring! Function -> FunctionDef

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

def check_functiondef_returns(self, node, node_doc):
def check_functiondef_returns(
self,
node: astroid.nodes.FunctionDef,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update docstring Function -> FunctionDef

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

# Thus to avoid MyPy's error
# (Class cannot subclass 'BaseChecker' (has type 'Any')),
# we added an ignore here.
class GoogleDocstring(_check_docs_utils.GoogleDocstring): # type: ignore[misc]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree but please create a different issue and mention it here, because issue #15613 was filed for missing stubs of the apache beam library. ( or if you want to use the same issue, then please update the content of #15613 ).

@oppiabot
Copy link

oppiabot bot commented Nov 17, 2022

Unassigning @sahiljoster32 since the review is done.

@oppiabot
Copy link

oppiabot bot commented Nov 17, 2022

Hi @aasiffaizal, it looks like some changes were requested on this pull request by @sahiljoster32. PTAL. Thanks!

Copy link
Contributor

@vojtechjelinek vojtechjelinek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@oppiabot
Copy link

oppiabot bot commented Nov 17, 2022

Unassigning @vojtechjelinek since they have already approved the PR.

@aasiffaizal
Copy link
Contributor Author

@sahiljoster32 Addressed all the comments. Could you PTAL?

Copy link
Contributor

@sahiljoster32 sahiljoster32 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!, Just one nit!!

scripts/linters/pylint_extensions.py Outdated Show resolved Hide resolved
@oppiabot
Copy link

oppiabot bot commented Nov 18, 2022

Unassigning @sahiljoster32 since they have already approved the PR.

@oppiabot
Copy link

oppiabot bot commented Nov 19, 2022

Hi @aasiffaizal. Due to recent changes in the "develop" branch, this PR now has a merge conflict. Please follow this link if you need help resolving the conflict, so that the PR can be merged. Thanks!

@U8NWXD U8NWXD removed their assignment Nov 19, 2022
@oppiabot oppiabot bot added the PR: LGTM label Nov 19, 2022
@oppiabot
Copy link

oppiabot bot commented Nov 19, 2022

Hi @aasiffaizal, this PR is ready to be merged. Please address any remaining comments prior to merging, and feel free to merge this PR once the CI checks pass and you're happy with it. Thanks!

@sahiljoster32
Copy link
Contributor

Since all the comments are addressed and all the reviewers approved the PR. I'm going to merge this, Thanks @aasiffaizal!

@sahiljoster32 sahiljoster32 merged commit ff82e55 into oppia:develop Nov 19, 2022
@aasiffaizal aasiffaizal deleted the scripts-typing-3 branch November 19, 2022 13:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants