Skip to content

Commit

Permalink
Refactor from old style typing to new style typing
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierre-Sassoulas committed Mar 30, 2021
1 parent 1a960b9 commit 9da9c6c
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 26 deletions.
25 changes: 12 additions & 13 deletions pylint/checkers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,16 +80,17 @@


class NamingStyle:
# It may seem counterintuitive that single naming style
# has multiple "accepted" forms of regular expressions,
# but we need to special-case stuff like dunder names
# in method names.
CLASS_NAME_RGX = None # type: Pattern[str]
MOD_NAME_RGX = None # type: Pattern[str]
CONST_NAME_RGX = None # type: Pattern[str]
COMP_VAR_RGX = None # type: Pattern[str]
DEFAULT_NAME_RGX = None # type: Pattern[str]
CLASS_ATTRIBUTE_RGX = None # type: Pattern[str]
"""It may seem counterintuitive that single naming style has multiple "accepted"
forms of regular expressions, but we need to special-case stuff like dunder names
in method names."""

ANY: Pattern[str] = re.compile(".*")
CLASS_NAME_RGX: Pattern[str] = ANY
MOD_NAME_RGX: Pattern[str] = ANY
CONST_NAME_RGX: Pattern[str] = ANY
COMP_VAR_RGX: Pattern[str] = ANY
DEFAULT_NAME_RGX: Pattern[str] = ANY
CLASS_ATTRIBUTE_RGX: Pattern[str] = ANY

@classmethod
def get_regex(cls, name_type):
Expand Down Expand Up @@ -155,9 +156,7 @@ class UpperCaseStyle(NamingStyle):


class AnyStyle(NamingStyle):
@classmethod
def get_regex(cls, name_type):
return re.compile(".*")
pass


NAMING_STYLES = {
Expand Down
10 changes: 5 additions & 5 deletions pylint/checkers/base_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,17 @@
class BaseChecker(OptionsProviderMixIn):

# checker name (you may reuse an existing one)
name = None # type: str
name: str = ""
# options level (0 will be displaying in --help, 1 in --long-help)
level = 1
# ordered list of options to control the checker behaviour
options = () # type: Any
options: Any = ()
# messages issued by this checker
msgs = {} # type: Any
msgs: Any = {}
# reports issued by this checker
reports = () # type: Any
reports: Any = ()
# mark this checker as enabled or not.
enabled = True
enabled: bool = True

def __init__(self, linter=None):
"""checker instances should have the linter as argument
Expand Down
2 changes: 1 addition & 1 deletion pylint/checkers/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ def _check_try_except_raise(self, node):
def gather_exceptions_from_handler(
handler,
) -> typing.Optional[typing.List[astroid.node_classes.NodeNG]]:
exceptions = [] # type: typing.List[astroid.node_classes.NodeNG]
exceptions: typing.List[astroid.node_classes.NodeNG] = []
if handler.type:
exceptions_in_handler = utils.safe_infer(handler.type)
if isinstance(exceptions_in_handler, astroid.Tuple):
Expand Down
2 changes: 1 addition & 1 deletion pylint/checkers/raw_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class RawMetricsChecker(BaseTokenChecker):
# configuration options
options = ()
# messages
msgs = {} # type: Any
msgs: Any = {}
# reports
reports = (("RP0701", "Raw metrics", report_raw_stats),)

Expand Down
5 changes: 2 additions & 3 deletions pylint/checkers/strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@
import numbers
import re
import tokenize
import typing
from typing import Iterable
from typing import Counter, Iterable

import astroid

Expand Down Expand Up @@ -750,7 +749,7 @@ def check_for_consistent_string_delimiters(
Args:
tokens: The tokens to be checked against for consistent usage.
"""
string_delimiters = collections.Counter() # type: typing.Counter[str]
string_delimiters: Counter[str] = collections.Counter()

# First, figure out which quote character predominates in the module
for tok_type, token, _, _, _ in tokens:
Expand Down
2 changes: 1 addition & 1 deletion pylint/checkers/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -867,7 +867,7 @@ def unimplemented_abstract_methods(
"""
if is_abstract_cb is None:
is_abstract_cb = partial(decorated_with, qnames=ABC_METHODS)
visited = {} # type: Dict[str, astroid.node_classes.NodeNG]
visited: Dict[str, astroid.node_classes.NodeNG] = {}
try:
mro = reversed(node.mro())
except NotImplementedError:
Expand Down
2 changes: 1 addition & 1 deletion pylint/config/options_provider_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class OptionsProviderMixIn:
# those attributes should be overridden
priority = -1
name = "default"
options = () # type: Tuple[Tuple[str, Dict[str, Any]], ...]
options: Tuple[Tuple[str, Dict[str, Any]], ...] = ()
level = 0

def __init__(self):
Expand Down
2 changes: 1 addition & 1 deletion pylint/utils/pragma_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class InvalidPragmaError(PragmaParserError):

def parse_pragma(pylint_pragma: str) -> Generator[PragmaRepresenter, None, None]:
action = None
messages = [] # type: List[str]
messages: List[str] = []
assignment_required = False
previous_token = ""

Expand Down

0 comments on commit 9da9c6c

Please sign in to comment.