summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Drozd <nicholasdrozd@gmail.com>2022-12-15 16:00:12 -0600
committerGitHub <noreply@github.com>2022-12-15 23:00:12 +0100
commit39d9cafb8b39432957f4e640d5ef222b66a7096e (patch)
treecd1bbaec9764d9634918a361707130921a62301e
parent6eb6bde7809c9ad2cc8d91c32804d9c8844207d6 (diff)
downloadastroid-git-39d9cafb8b39432957f4e640d5ef222b66a7096e.tar.gz
Misc type stuff (#1888)
-rw-r--r--astroid/_ast.py2
-rw-r--r--astroid/brain/brain_builtin_inference.py2
-rw-r--r--astroid/brain/brain_uuid.py2
-rw-r--r--astroid/brain/helpers.py11
-rw-r--r--astroid/transforms.py4
-rw-r--r--astroid/util.py5
6 files changed, 18 insertions, 8 deletions
diff --git a/astroid/_ast.py b/astroid/_ast.py
index 3a866c2c..edd822b6 100644
--- a/astroid/_ast.py
+++ b/astroid/_ast.py
@@ -7,6 +7,7 @@ from __future__ import annotations
import ast
import sys
import types
+from collections.abc import Callable
from functools import partial
from typing import NamedTuple
@@ -36,6 +37,7 @@ class ParserModule(NamedTuple):
context_classes: dict[type[ast.expr_context], Context]
def parse(self, string: str, type_comments: bool = True) -> ast.Module:
+ parse_func: Callable[[str], ast.Module]
if self.module is _ast_py3:
if PY38_PLUS:
parse_func = partial(self.module.parse, type_comments=type_comments)
diff --git a/astroid/brain/brain_builtin_inference.py b/astroid/brain/brain_builtin_inference.py
index a872b38c..61c0baa6 100644
--- a/astroid/brain/brain_builtin_inference.py
+++ b/astroid/brain/brain_builtin_inference.py
@@ -164,7 +164,7 @@ def _builtin_filter_predicate(node, builtin_name) -> bool:
return False
-def register_builtin_transform(transform, builtin_name):
+def register_builtin_transform(transform, builtin_name) -> None:
"""Register a new transform function for the given *builtin_name*.
The transform function must accept two parameters, a node and
diff --git a/astroid/brain/brain_uuid.py b/astroid/brain/brain_uuid.py
index f6ba8883..4890e101 100644
--- a/astroid/brain/brain_uuid.py
+++ b/astroid/brain/brain_uuid.py
@@ -8,7 +8,7 @@ from astroid.nodes.node_classes import Const
from astroid.nodes.scoped_nodes import ClassDef
-def _patch_uuid_class(node):
+def _patch_uuid_class(node: ClassDef) -> None:
# The .int member is patched using __dict__
node.locals["int"] = [Const(0, parent=node)]
diff --git a/astroid/brain/helpers.py b/astroid/brain/helpers.py
index d74f5950..56683c8e 100644
--- a/astroid/brain/helpers.py
+++ b/astroid/brain/helpers.py
@@ -2,11 +2,18 @@
# For details: https://github.com/PyCQA/astroid/blob/main/LICENSE
# Copyright (c) https://github.com/PyCQA/astroid/blob/main/CONTRIBUTORS.txt
+from __future__ import annotations
+
+from collections.abc import Callable
+
+from astroid.manager import AstroidManager
from astroid.nodes.scoped_nodes import Module
-def register_module_extender(manager, module_name, get_extension_mod):
- def transform(node):
+def register_module_extender(
+ manager: AstroidManager, module_name: str, get_extension_mod: Callable[[], Module]
+) -> None:
+ def transform(node: Module) -> None:
extension_module = get_extension_mod()
for name, objs in extension_module.locals.items():
node.locals[name] = objs
diff --git a/astroid/transforms.py b/astroid/transforms.py
index 42e348dd..6f312633 100644
--- a/astroid/transforms.py
+++ b/astroid/transforms.py
@@ -66,7 +66,7 @@ class TransformVisitor:
return self._visit(node)
- def register_transform(self, node_class, transform, predicate=None):
+ def register_transform(self, node_class, transform, predicate=None) -> None:
"""Register `transform(node)` function to be applied on the given
astroid's `node_class` if `predicate` is None or returns true
when called with the node as argument.
@@ -76,7 +76,7 @@ class TransformVisitor:
"""
self.transforms[node_class].append((transform, predicate))
- def unregister_transform(self, node_class, transform, predicate=None):
+ def unregister_transform(self, node_class, transform, predicate=None) -> None:
"""Unregister the given transform."""
self.transforms[node_class].remove((transform, predicate))
diff --git a/astroid/util.py b/astroid/util.py
index 54519e45..51595ca7 100644
--- a/astroid/util.py
+++ b/astroid/util.py
@@ -5,6 +5,7 @@
import importlib
import sys
import warnings
+from typing import Any
import lazy_object_proxy
@@ -22,7 +23,7 @@ def lazy_descriptor(obj):
return DescriptorProxy(obj)
-def lazy_import(module_name):
+def lazy_import(module_name: str) -> lazy_object_proxy.Proxy:
return lazy_object_proxy.Proxy(
lambda: importlib.import_module("." + module_name, "astroid")
)
@@ -37,7 +38,7 @@ class Uninferable:
__str__ = __repr__
- def __getattribute__(self, name):
+ def __getattribute__(self, name: str) -> Any:
if name == "next":
raise AttributeError("next method should not be called")
if name.startswith("__") and name.endswith("__"):