Skip to content

Commit

Permalink
Fix incorrect typing of optional default values
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielNoord authored and tushar-deepsource committed Dec 20, 2021
1 parent a6b36f2 commit 0356594
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 7 deletions.
6 changes: 5 additions & 1 deletion astroid/brain/brain_re.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html
# For details: https://github.com/PyCQA/astroid/blob/main/LICENSE
from typing import Optional

from astroid import context, inference_tip, nodes
from astroid.brain.helpers import register_module_extender
from astroid.builder import extract_node, parse
Expand Down Expand Up @@ -64,7 +66,9 @@ def _looks_like_pattern_or_match(node: nodes.Call) -> bool:
)


def infer_pattern_match(node: nodes.Call, ctx: context.InferenceContext = None):
def infer_pattern_match(
node: nodes.Call, ctx: Optional[context.InferenceContext] = None
):
"""Infer re.Pattern and re.Match as classes. For PY39+ add `__class_getitem__`."""
class_def = nodes.ClassDef(
name=node.parent.targets[0].name,
Expand Down
4 changes: 2 additions & 2 deletions astroid/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import textwrap
import types
from tokenize import detect_encoding
from typing import List, Union
from typing import List, Optional, Union

from astroid import bases, modutils, nodes, raw_building, rebuilder, util
from astroid._ast import get_parser_module
Expand Down Expand Up @@ -82,7 +82,7 @@ def __init__(self, manager=None, apply_transforms=True):
self._apply_transforms = apply_transforms

def module_build(
self, module: types.ModuleType, modname: str = None
self, module: types.ModuleType, modname: Optional[str] = None
) -> nodes.Module:
"""Build an astroid from a living module instance."""
node = None
Expand Down
4 changes: 2 additions & 2 deletions astroid/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import os
import types
import zipimport
from typing import TYPE_CHECKING, ClassVar, List
from typing import TYPE_CHECKING, ClassVar, List, Optional

from astroid.exceptions import AstroidBuildingError, AstroidImportError
from astroid.interpreter._import import spec
Expand Down Expand Up @@ -268,7 +268,7 @@ def file_from_module_name(self, modname, contextfile):
raise value.with_traceback(None)
return value

def ast_from_module(self, module: types.ModuleType, modname: str = None):
def ast_from_module(self, module: types.ModuleType, modname: Optional[str] = None):
"""given an imported module, return the astroid object"""
modname = modname or module.__name__
if modname in self.astroid_cache:
Expand Down
7 changes: 5 additions & 2 deletions astroid/raw_building.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def attach_import_node(node, modname, membername):
_attach_local_node(node, from_node, membername)


def build_module(name: str, doc: str = None) -> nodes.Module:
def build_module(name: str, doc: Optional[str] = None) -> nodes.Module:
"""create and initialize an astroid Module node"""
node = nodes.Module(name, doc, pure_python=False)
node.package = False
Expand Down Expand Up @@ -304,7 +304,10 @@ def __init__(self, manager_instance=None):
self._module = None

def inspect_build(
self, module: types.ModuleType, modname: str = None, path: str = None
self,
module: types.ModuleType,
modname: Optional[str] = None,
path: Optional[str] = None,
) -> nodes.Module:
"""build astroid from a living module (i.e. using inspect)
this is used when there is no python source code available (either
Expand Down

0 comments on commit 0356594

Please sign in to comment.