mirror of
https://github.com/davidhalter/django-stubs.git
synced 2025-12-11 06:21:58 +08:00
lint fixes
This commit is contained in:
@@ -1,11 +1,12 @@
|
||||
from typing import Union, Tuple, List, Optional, NamedTuple, cast
|
||||
from typing import List, NamedTuple, Optional, Tuple, Union, cast
|
||||
|
||||
from mypy.nodes import Argument, FuncDef, Var, TypeInfo
|
||||
from mypy.plugin import DynamicClassDefContext, ClassDefContext
|
||||
from mypy.nodes import Argument, FuncDef, TypeInfo, Var
|
||||
from mypy.plugin import ClassDefContext, DynamicClassDefContext
|
||||
from mypy.plugins.common import add_method
|
||||
from mypy.semanal import SemanticAnalyzer
|
||||
from mypy.types import Instance, CallableType, AnyType, TypeOfAny, PlaceholderType
|
||||
from mypy.types import AnyType, CallableType, Instance
|
||||
from mypy.types import Type as MypyType
|
||||
from mypy.types import TypeOfAny
|
||||
|
||||
|
||||
class IncompleteDefnException(Exception):
|
||||
@@ -39,7 +40,7 @@ def prepare_unannotated_method_signature(method_node: FuncDef) -> Tuple[List[Arg
|
||||
|
||||
|
||||
class SignatureTuple(NamedTuple):
|
||||
arguments: Optional[List[Argument]]
|
||||
arguments: List[Argument]
|
||||
return_type: Optional[MypyType]
|
||||
cannot_be_bound: bool
|
||||
|
||||
@@ -53,16 +54,14 @@ def analyze_callable_signature(api: SemanticAnalyzer, method_node: FuncDef) -> S
|
||||
for arg_name, arg_type, original_argument in zip(method_type.arg_names[1:],
|
||||
method_type.arg_types[1:],
|
||||
method_node.arguments[1:]):
|
||||
arg_type = api.anal_type(arg_type, allow_placeholder=True)
|
||||
if isinstance(arg_type, PlaceholderType):
|
||||
analyzed_arg_type = api.anal_type(arg_type)
|
||||
if analyzed_arg_type is None:
|
||||
unbound = True
|
||||
|
||||
var = Var(name=original_argument.variable.name,
|
||||
type=arg_type)
|
||||
type=analyzed_arg_type)
|
||||
var.set_line(original_argument.variable)
|
||||
|
||||
if isinstance(arg_type, PlaceholderType):
|
||||
unbound = True
|
||||
argument = Argument(variable=var,
|
||||
type_annotation=arg_type,
|
||||
initializer=original_argument.initializer,
|
||||
@@ -70,10 +69,10 @@ def analyze_callable_signature(api: SemanticAnalyzer, method_node: FuncDef) -> S
|
||||
argument.set_line(original_argument)
|
||||
arguments.append(argument)
|
||||
|
||||
ret_type = api.anal_type(method_type.ret_type, allow_placeholder=True)
|
||||
if isinstance(ret_type, PlaceholderType):
|
||||
analyzed_ret_type = api.anal_type(method_type.ret_type)
|
||||
if analyzed_ret_type is None:
|
||||
unbound = True
|
||||
return SignatureTuple(arguments, ret_type, unbound)
|
||||
return SignatureTuple(arguments, analyzed_ret_type, unbound)
|
||||
|
||||
|
||||
def copy_method_or_incomplete_defn_exception(ctx: ClassDefContext,
|
||||
@@ -103,15 +102,17 @@ def copy_method_or_incomplete_defn_exception(ctx: ClassDefContext,
|
||||
and name not in semanal_api.cur_mod_node.names):
|
||||
semanal_api.add_imported_symbol(name, sym, context=semanal_api.cur_mod_node)
|
||||
|
||||
arguments, return_type, unbound = analyze_callable_signature(semanal_api, method_node)
|
||||
arguments, analyzed_return_type, unbound = analyze_callable_signature(semanal_api, method_node)
|
||||
assert len(arguments) + 1 == len(method_node.arguments)
|
||||
if unbound:
|
||||
raise IncompleteDefnException(f'Signature of method {method_node.fullname!r} is not ready')
|
||||
|
||||
assert analyzed_return_type is not None
|
||||
|
||||
if new_method_name in ctx.cls.info.names:
|
||||
del ctx.cls.info.names[new_method_name]
|
||||
add_method(ctx,
|
||||
new_method_name,
|
||||
args=arguments,
|
||||
return_type=return_type,
|
||||
return_type=analyzed_return_type,
|
||||
self_type=self_type)
|
||||
|
||||
Reference in New Issue
Block a user