Skip to content

Commit 6879a45

Browse files
committed
Fix incorrect typing of optional default values
1 parent 6655741 commit 6879a45

File tree

4 files changed

+14
-7
lines changed

4 files changed

+14
-7
lines changed

astroid/brain/brain_re.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html
22
# For details: https://github.com/PyCQA/astroid/blob/main/LICENSE
3+
from typing import Optional
4+
35
from astroid import context, inference_tip, nodes
46
from astroid.brain.helpers import register_module_extender
57
from astroid.builder import extract_node, parse
@@ -64,7 +66,9 @@ def _looks_like_pattern_or_match(node: nodes.Call) -> bool:
6466
)
6567

6668

67-
def infer_pattern_match(node: nodes.Call, ctx: context.InferenceContext = None):
69+
def infer_pattern_match(
70+
node: nodes.Call, ctx: Optional[context.InferenceContext] = None
71+
):
6872
"""Infer re.Pattern and re.Match as classes. For PY39+ add `__class_getitem__`."""
6973
class_def = nodes.ClassDef(
7074
name=node.parent.targets[0].name,

astroid/builder.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
import textwrap
2626
import types
2727
from tokenize import detect_encoding
28-
from typing import List, Union
28+
from typing import List, Optional, Union
2929

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

8484
def module_build(
85-
self, module: types.ModuleType, modname: str = None
85+
self, module: types.ModuleType, modname: Optional[str] = None
8686
) -> nodes.Module:
8787
"""Build an astroid from a living module instance."""
8888
node = None

astroid/manager.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
import os
3333
import types
3434
import zipimport
35-
from typing import TYPE_CHECKING, ClassVar, List
35+
from typing import TYPE_CHECKING, ClassVar, List, Optional
3636

3737
from astroid.exceptions import AstroidBuildingError, AstroidImportError
3838
from astroid.interpreter._import import spec
@@ -268,7 +268,7 @@ def file_from_module_name(self, modname, contextfile):
268268
raise value.with_traceback(None)
269269
return value
270270

271-
def ast_from_module(self, module: types.ModuleType, modname: str = None):
271+
def ast_from_module(self, module: types.ModuleType, modname: Optional[str] = None):
272272
"""given an imported module, return the astroid object"""
273273
modname = modname or module.__name__
274274
if modname in self.astroid_cache:

astroid/raw_building.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ def attach_import_node(node, modname, membername):
106106
_attach_local_node(node, from_node, membername)
107107

108108

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

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

0 commit comments

Comments
 (0)