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

Refactor various typing related issues #4940

Merged
merged 21 commits into from
Sep 3, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
5a1e21d
Add type annotations to ``visit`` & ``leave`` calls
DanielNoord Aug 31, 2021
c81f02f
Fix outstanding mypy issues
DanielNoord Aug 31, 2021
8ea6f70
Fix remaining references to node_classes
DanielNoord Aug 31, 2021
7d2062c
Update typing and mypy configuration
DanielNoord Aug 31, 2021
3fe7bc4
Fix cyclic import in `deprecated.py`
DanielNoord Aug 31, 2021
6bbf2b3
Apply suggestions from code review
DanielNoord Aug 31, 2021
c004d75
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 31, 2021
596fc28
Apply suggestions from code review
DanielNoord Aug 31, 2021
c45ac73
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Aug 31, 2021
1f2d7a7
Add changes from code review
DanielNoord Aug 31, 2021
3c31ed0
Additional typing
DanielNoord Aug 31, 2021
8dbb8fb
Merge branch 'main' of https://github.com/PyCQA/pylint into typing
DanielNoord Sep 1, 2021
8dd90cd
Apply suggestions from code review
DanielNoord Sep 1, 2021
4bf1c59
Merge branch 'main' into typing
DanielNoord Sep 1, 2021
3a47b64
Implement code review
DanielNoord Sep 1, 2021
49aa00c
Fix test
DanielNoord Sep 1, 2021
ce1aa3d
Reverse removal of ``visit_package``
DanielNoord Sep 1, 2021
c2299df
Merge branch 'main' into typing
DanielNoord Sep 2, 2021
1bfe966
Update import of ``objects.ExceptionInstance``
DanielNoord Sep 2, 2021
4e99175
Merge branch 'main' of https://github.com/PyCQA/pylint into typing
DanielNoord Sep 2, 2021
7aeb8c4
Merge branch 'typing' of https://github.com/DanielNoord/pylint into t…
DanielNoord Sep 2, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions doc/how_tos/custom_checkers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,11 @@ Firstly we will need to fill in some required boilerplate:
.. code-block:: python

import astroid
from astroid import nodes

from pylint.checkers import BaseChecker
from pylint.interfaces import IAstroidChecker
from pylint.lint import PyLinter

class UniqueReturnChecker(BaseChecker):
__implements__ = IAstroidChecker
Expand Down
17 changes: 3 additions & 14 deletions pylint/checkers/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,7 @@
import re
import string
from functools import lru_cache, partial
from typing import (
Any,
Callable,
Dict,
Iterable,
List,
Match,
Optional,
Set,
Tuple,
Union,
)
from typing import Callable, Dict, Iterable, List, Match, Optional, Set, Tuple, Union

import _string
import astroid
Expand Down Expand Up @@ -1245,15 +1234,15 @@ def is_none(node: nodes.NodeNG) -> bool:
)


def node_type(node: nodes.NodeNG) -> Optional[Any]:
def node_type(node: nodes.NodeNG) -> Optional[nodes.NodeNG]:
DanielNoord marked this conversation as resolved.
Show resolved Hide resolved
"""Return the inferred type for `node`

If there is more than one possible type, or if inferred type is Uninferable or None,
return None
"""
# check there is only one possible type for the assign node. Else we
# don't handle it for now
types = set()
types: Set[nodes.NodeNG] = set()
cdce8p marked this conversation as resolved.
Show resolved Hide resolved
try:
for var_type in node.infer():
if var_type == astroid.Uninferable or is_none(var_type):
Expand Down
10 changes: 0 additions & 10 deletions pylint/pyreverse/inspector.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,16 +152,6 @@ def visit_project(self, node: Project) -> None:
for module in node.modules:
self.visit(module)

def visit_package(self, node) -> None:
"""visit an astroid.Package node
DanielNoord marked this conversation as resolved.
Show resolved Hide resolved

* optionally tag the node with a unique id
"""
if self.tag:
node.uid = self.generate_id()
for subelmt in node.values():
self.visit(subelmt)

def visit_module(self, node: nodes.Module) -> None:
"""visit an astroid.Module node

Expand Down