summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniël van Noord <13665637+DanielNoord@users.noreply.github.com>2021-12-15 16:20:34 +0100
committerDaniël van Noord <13665637+DanielNoord@users.noreply.github.com>2021-12-15 16:33:43 +0100
commit6879a45f382ae396e88d16e75a7b13bbbd6309a2 (patch)
treee3a4dccb828811a581bf6b11256313494350f9fc
parent665574122cb6302fa5342c6f3570c674fcaf0a44 (diff)
downloadastroid-git-6879a45f382ae396e88d16e75a7b13bbbd6309a2.tar.gz
Fix incorrect typing of optional default values
-rw-r--r--astroid/brain/brain_re.py6
-rw-r--r--astroid/builder.py4
-rw-r--r--astroid/manager.py4
-rw-r--r--astroid/raw_building.py7
4 files changed, 14 insertions, 7 deletions
diff --git a/astroid/brain/brain_re.py b/astroid/brain/brain_re.py
index 693acc41..ecd4235d 100644
--- a/astroid/brain/brain_re.py
+++ b/astroid/brain/brain_re.py
@@ -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
@@ -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,
diff --git a/astroid/builder.py b/astroid/builder.py
index b2c83262..ea9d7dc8 100644
--- a/astroid/builder.py
+++ b/astroid/builder.py
@@ -25,7 +25,7 @@ import os
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
@@ -82,7 +82,7 @@ class AstroidBuilder(raw_building.InspectBuilder):
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
diff --git a/astroid/manager.py b/astroid/manager.py
index 82adefdb..36740fc7 100644
--- a/astroid/manager.py
+++ b/astroid/manager.py
@@ -32,7 +32,7 @@ from various source and using a cache of built modules)
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
@@ -268,7 +268,7 @@ class AstroidManager:
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:
diff --git a/astroid/raw_building.py b/astroid/raw_building.py
index 57e8d354..63257072 100644
--- a/astroid/raw_building.py
+++ b/astroid/raw_building.py
@@ -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
@@ -304,7 +304,10 @@ class InspectBuilder:
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