after_merge
stringlengths
28
79.6k
before_merge
stringlengths
20
79.6k
url
stringlengths
38
71
full_traceback
stringlengths
43
922k
traceback_type
stringclasses
555 values
def __init__( self, item: Union[Instance, AnyType, TypeVarType, TupleType, NoneTyp, CallableType], *, line: int = -1, column: int = -1, ) -> None: """To ensure Type[Union[A, B]] is always represented as Union[Type[A], Type[B]], item of type UnionType must be handled through make_normalized static method. """ super().__init__(line, column) self.item = item
def __init__( self, item: Union[Instance, AnyType, TypeVarType, TupleType, NoneTyp, CallableType], *, line: int = -1, column: int = -1, ) -> None: """To ensure Type[Union[A, B]] is always represented as Union[Type[A], Type[B]], item of type UnionType must be handled through make_normalized static method. """ super().__init__(line, column) if isinstance(item, CallableType) and item.is_type_obj(): self.item = item.fallback else: self.item = item
https://github.com/python/mypy/issues/3852
$ bin/mypy python/ Traceback (most recent call last): File "bin/mypy", line 33, in <module> sys.exit(console_entry()) File "dist/lib/python3.6/mypy/__main__.py", line 7, in console_entry main(None) File "dist/lib/python3.6/mypy/main.py", line 50, in main res = type_check_only(sources, bin_dir, options) File "dist/lib/python3.6/mypy/main.py", line 97, in type_check_only options=options) File "dist/lib/python3.6/mypy/build.py", line 196, in build graph = dispatch(sources, manager) File "dist/lib/python3.6/mypy/build.py", line 1801, in dispatch process_graph(graph, manager) File "dist/lib/python3.6/mypy/build.py", line 2037, in process_graph process_fresh_scc(graph, prev_scc) File "dist/lib/python3.6/mypy/build.py", line 2106, in process_fresh_scc graph[id].fix_cross_refs() File "dist/lib/python3.6/mypy/build.py", line 1547, in fix_cross_refs self.manager.options.quick_and_dirty) File "dist/lib/python3.6/mypy/fixup.py", line 22, in fixup_module_pass_one node_fixer.visit_symbol_table(tree.names) File "dist/lib/python3.6/mypy/fixup.py", line 105, in visit_symbol_table self.visit_type_info(value.node) File "dist/lib/python3.6/mypy/fixup.py", line 62, in visit_type_info base.accept(self.type_fixer) File "dist/lib/python3.6/mypy/types.py", line 435, in accept return visitor.visit_instance(self) File "dist/lib/python3.6/mypy/fixup.py", line 176, in visit_instance assert self.quick_and_dirty, "Should never get here in normal mode" AssertionError: Should never get here in normal mode
AssertionError
def check_lvalue( self, lvalue: Lvalue ) -> Tuple[Optional[Type], Optional[IndexExpr], Optional[Var]]: lvalue_type = None # type: Optional[Type] index_lvalue = None # type: Optional[IndexExpr] inferred = None # type: Optional[Var] if self.is_definition(lvalue): if isinstance(lvalue, NameExpr): inferred = cast(Var, lvalue.node) assert isinstance(inferred, Var) else: assert isinstance(lvalue, MemberExpr) self.expr_checker.accept(lvalue.expr) inferred = lvalue.def_var elif isinstance(lvalue, IndexExpr): index_lvalue = lvalue elif isinstance(lvalue, MemberExpr): lvalue_type = self.expr_checker.analyze_ordinary_member_access(lvalue, True) self.store_type(lvalue, lvalue_type) elif isinstance(lvalue, NameExpr): lvalue_type = self.expr_checker.analyze_ref_expr(lvalue, lvalue=True) self.store_type(lvalue, lvalue_type) elif isinstance(lvalue, TupleExpr) or isinstance(lvalue, ListExpr): types = [ self.check_lvalue(sub_expr)[0] or # This type will be used as a context for further inference of rvalue, # we put Uninhabited if there is no information available from lvalue. UninhabitedType() for sub_expr in lvalue.items ] lvalue_type = TupleType(types, self.named_type("builtins.tuple")) else: lvalue_type = self.expr_checker.accept(lvalue) return lvalue_type, index_lvalue, inferred
def check_lvalue( self, lvalue: Lvalue ) -> Tuple[Optional[Type], Optional[IndexExpr], Optional[Var]]: lvalue_type = None # type: Optional[Type] index_lvalue = None # type: Optional[IndexExpr] inferred = None # type: Optional[Var] if self.is_definition(lvalue): if isinstance(lvalue, NameExpr): inferred = cast(Var, lvalue.node) assert isinstance(inferred, Var) else: assert isinstance(lvalue, MemberExpr) self.expr_checker.accept(lvalue.expr) inferred = lvalue.def_var elif isinstance(lvalue, IndexExpr): index_lvalue = lvalue elif isinstance(lvalue, MemberExpr): lvalue_type = self.expr_checker.analyze_ordinary_member_access(lvalue, True) self.store_type(lvalue, lvalue_type) elif isinstance(lvalue, NameExpr): lvalue_type = self.expr_checker.analyze_ref_expr(lvalue, lvalue=True) self.store_type(lvalue, lvalue_type) elif isinstance(lvalue, TupleExpr) or isinstance(lvalue, ListExpr): types = [self.check_lvalue(sub_expr)[0] for sub_expr in lvalue.items] lvalue_type = TupleType(types, self.named_type("builtins.tuple")) else: lvalue_type = self.expr_checker.accept(lvalue) return lvalue_type, index_lvalue, inferred
https://github.com/python/mypy/issues/4046
Traceback (most recent call last): File "/Users/ambv/.venvs/mypy/bin/mypy", line 11, in <module> load_entry_point('mypy', 'console_scripts', 'mypy')() File "mypy/__main__.py", line 7, in console_entry main(None) File "mypy/main.py", line 50, in main res = type_check_only(sources, bin_dir, options) File "mypy/main.py", line 103, in type_check_only options=options) File "mypy/build.py", line 198, in build graph = dispatch(sources, manager) File "mypy/build.py", line 1841, in dispatch process_graph(graph, manager) File "mypy/build.py", line 2091, in process_graph process_stale_scc(graph, scc, manager) File "mypy/build.py", line 2194, in process_stale_scc graph[id].type_check_first_pass() File "mypy/build.py", line 1753, in type_check_first_pass self.type_checker.check_first_pass() File "mypy/checker.py", line 194, in check_first_pass self.accept(d) File "mypy/checker.py", line 282, in accept stmt.accept(self) File "mypy/nodes.py", line 519, in accept return visitor.visit_func_def(self) File "mypy/checker.py", line 530, in visit_func_def self.check_func_item(defn, name=defn.name()) File "mypy/checker.py", line 590, in check_func_item self.check_func_def(defn, typ, name) File "mypy/checker.py", line 750, in check_func_def self.accept(item.body) File "mypy/checker.py", line 282, in accept stmt.accept(self) File "mypy/nodes.py", line 773, in accept return visitor.visit_block(self) File "mypy/checker.py", line 1304, in visit_block self.accept(s) File "mypy/checker.py", line 282, in accept stmt.accept(self) File "mypy/nodes.py", line 817, in accept return visitor.visit_assignment_stmt(self) File "mypy/checker.py", line 1311, in visit_assignment_stmt self.check_assignment(s.lvalues[-1], s.rvalue, s.type is None, s.new_syntax) File "mypy/checker.py", line 1339, in check_assignment infer_lvalue_type) File "mypy/checker.py", line 1589, in check_assignment_to_multiple_lvalues self.check_multi_assignment(lvalues, rvalue, context, infer_lvalue_type) File "mypy/checker.py", line 1630, in check_multi_assignment context, undefined_rvalue, infer_lvalue_type) File "mypy/checker.py", line 1650, in check_multi_assignment_from_tuple reinferred_rvalue_type = self.expr_checker.accept(rvalue, lvalue_type) File "mypy/checkexpr.py", line 2372, in accept typ = node.accept(self) File "mypy/nodes.py", line 1256, in accept return visitor.visit_call_expr(self) File "mypy/checkexpr.py", line 266, in visit_call_expr ret_type = self.check_call_expr_with_callee_type(callee_type, e, fullname, object_type) File "mypy/checkexpr.py", line 503, in check_call_expr_with_callee_type object_type=object_type)[0] File "mypy/checkexpr.py", line 563, in check_call callee, context) File "mypy/checkexpr.py", line 752, in infer_function_type_arguments_using_context erased_ctx = replace_meta_vars(ctx, ErasedType()) File "mypy/erasetype.py", line 94, in replace_meta_vars return t.accept(TypeVarEraser(lambda id: id.is_meta_var(), target_type)) File "mypy/types.py", line 982, in accept return visitor.visit_tuple_type(self) File "mypy/types.py", line 1554, in visit_tuple_type return TupleType(self.translate_types(t.items), File "mypy/types.py", line 1574, in translate_types return [t.accept(self) for t in types] File "mypy/types.py", line 1574, in <listcomp> return [t.accept(self) for t in types] File "mypy/types.py", line 982, in accept return visitor.visit_tuple_type(self) File "mypy/types.py", line 1554, in visit_tuple_type return TupleType(self.translate_types(t.items), File "mypy/types.py", line 1574, in translate_types return [t.accept(self) for t in types] File "mypy/types.py", line 1574, in <listcomp> return [t.accept(self) for t in types] AttributeError: 'NoneType' object has no attribute 'accept' /tmp/test.py:13: : note: use --pdb to drop into pdb
AttributeError
def infer_function_type_arguments_using_context( self, callable: CallableType, error_context: Context ) -> CallableType: """Unify callable return type to type context to infer type vars. For example, if the return type is set[t] where 't' is a type variable of callable, and if the context is set[int], return callable modified by substituting 't' with 'int'. """ ctx = self.type_context[-1] if not ctx: return callable # The return type may have references to type metavariables that # we are inferring right now. We must consider them as indeterminate # and they are not potential results; thus we replace them with the # special ErasedType type. On the other hand, class type variables are # valid results. erased_ctx = replace_meta_vars(ctx, ErasedType()) ret_type = callable.ret_type if isinstance(ret_type, TypeVarType): if ret_type.values or (not isinstance(ctx, Instance) or not ctx.args): # The return type is a type variable. If it has values, we can't easily restrict # type inference to conform to the valid values. If it's unrestricted, we could # infer a too general type for the type variable if we use context, and this could # result in confusing and spurious type errors elsewhere. # # Give up and just use function arguments for type inference. As an exception, # if the context is a generic instance type, actually use it as context, as # this *seems* to usually be the reasonable thing to do. # # See also github issues #462 and #360. ret_type = NoneTyp() args = infer_type_arguments(callable.type_var_ids(), ret_type, erased_ctx) # Only substitute non-Uninhabited and non-erased types. new_args = [] # type: List[Optional[Type]] for arg in args: if has_uninhabited_component(arg) or has_erased_component(arg): new_args.append(None) else: new_args.append(arg) return self.apply_generic_arguments(callable, new_args, error_context)
def infer_function_type_arguments_using_context( self, callable: CallableType, error_context: Context ) -> CallableType: """Unify callable return type to type context to infer type vars. For example, if the return type is set[t] where 't' is a type variable of callable, and if the context is set[int], return callable modified by substituting 't' with 'int'. """ ctx = self.type_context[-1] if not ctx: return callable # The return type may have references to type metavariables that # we are inferring right now. We must consider them as indeterminate # and they are not potential results; thus we replace them with the # special ErasedType type. On the other hand, class type variables are # valid results. erased_ctx = replace_meta_vars(ctx, ErasedType()) ret_type = callable.ret_type if isinstance(ret_type, TypeVarType): if ret_type.values or (not isinstance(ctx, Instance) or not ctx.args): # The return type is a type variable. If it has values, we can't easily restrict # type inference to conform to the valid values. If it's unrestricted, we could # infer a too general type for the type variable if we use context, and this could # result in confusing and spurious type errors elsewhere. # # Give up and just use function arguments for type inference. As an exception, # if the context is a generic instance type, actually use it as context, as # this *seems* to usually be the reasonable thing to do. # # See also github issues #462 and #360. ret_type = NoneTyp() args = infer_type_arguments(callable.type_var_ids(), ret_type, erased_ctx) # Only substitute non-Uninhabited and non-erased types. new_args = [] # type: List[Optional[Type]] for arg in args: if isinstance(arg, UninhabitedType) or has_erased_component(arg): new_args.append(None) else: new_args.append(arg) return self.apply_generic_arguments(callable, new_args, error_context)
https://github.com/python/mypy/issues/4046
Traceback (most recent call last): File "/Users/ambv/.venvs/mypy/bin/mypy", line 11, in <module> load_entry_point('mypy', 'console_scripts', 'mypy')() File "mypy/__main__.py", line 7, in console_entry main(None) File "mypy/main.py", line 50, in main res = type_check_only(sources, bin_dir, options) File "mypy/main.py", line 103, in type_check_only options=options) File "mypy/build.py", line 198, in build graph = dispatch(sources, manager) File "mypy/build.py", line 1841, in dispatch process_graph(graph, manager) File "mypy/build.py", line 2091, in process_graph process_stale_scc(graph, scc, manager) File "mypy/build.py", line 2194, in process_stale_scc graph[id].type_check_first_pass() File "mypy/build.py", line 1753, in type_check_first_pass self.type_checker.check_first_pass() File "mypy/checker.py", line 194, in check_first_pass self.accept(d) File "mypy/checker.py", line 282, in accept stmt.accept(self) File "mypy/nodes.py", line 519, in accept return visitor.visit_func_def(self) File "mypy/checker.py", line 530, in visit_func_def self.check_func_item(defn, name=defn.name()) File "mypy/checker.py", line 590, in check_func_item self.check_func_def(defn, typ, name) File "mypy/checker.py", line 750, in check_func_def self.accept(item.body) File "mypy/checker.py", line 282, in accept stmt.accept(self) File "mypy/nodes.py", line 773, in accept return visitor.visit_block(self) File "mypy/checker.py", line 1304, in visit_block self.accept(s) File "mypy/checker.py", line 282, in accept stmt.accept(self) File "mypy/nodes.py", line 817, in accept return visitor.visit_assignment_stmt(self) File "mypy/checker.py", line 1311, in visit_assignment_stmt self.check_assignment(s.lvalues[-1], s.rvalue, s.type is None, s.new_syntax) File "mypy/checker.py", line 1339, in check_assignment infer_lvalue_type) File "mypy/checker.py", line 1589, in check_assignment_to_multiple_lvalues self.check_multi_assignment(lvalues, rvalue, context, infer_lvalue_type) File "mypy/checker.py", line 1630, in check_multi_assignment context, undefined_rvalue, infer_lvalue_type) File "mypy/checker.py", line 1650, in check_multi_assignment_from_tuple reinferred_rvalue_type = self.expr_checker.accept(rvalue, lvalue_type) File "mypy/checkexpr.py", line 2372, in accept typ = node.accept(self) File "mypy/nodes.py", line 1256, in accept return visitor.visit_call_expr(self) File "mypy/checkexpr.py", line 266, in visit_call_expr ret_type = self.check_call_expr_with_callee_type(callee_type, e, fullname, object_type) File "mypy/checkexpr.py", line 503, in check_call_expr_with_callee_type object_type=object_type)[0] File "mypy/checkexpr.py", line 563, in check_call callee, context) File "mypy/checkexpr.py", line 752, in infer_function_type_arguments_using_context erased_ctx = replace_meta_vars(ctx, ErasedType()) File "mypy/erasetype.py", line 94, in replace_meta_vars return t.accept(TypeVarEraser(lambda id: id.is_meta_var(), target_type)) File "mypy/types.py", line 982, in accept return visitor.visit_tuple_type(self) File "mypy/types.py", line 1554, in visit_tuple_type return TupleType(self.translate_types(t.items), File "mypy/types.py", line 1574, in translate_types return [t.accept(self) for t in types] File "mypy/types.py", line 1574, in <listcomp> return [t.accept(self) for t in types] File "mypy/types.py", line 982, in accept return visitor.visit_tuple_type(self) File "mypy/types.py", line 1554, in visit_tuple_type return TupleType(self.translate_types(t.items), File "mypy/types.py", line 1574, in translate_types return [t.accept(self) for t in types] File "mypy/types.py", line 1574, in <listcomp> return [t.accept(self) for t in types] AttributeError: 'NoneType' object has no attribute 'accept' /tmp/test.py:13: : note: use --pdb to drop into pdb
AttributeError
def __init__( self, data_dir: str, lib_path: List[str], ignore_prefix: str, source_set: BuildSourceSet, reports: Reports, options: Options, version_id: str, plugin: Plugin, errors: Errors, ) -> None: self.start_time = time.time() self.data_dir = data_dir self.errors = errors self.errors.set_ignore_prefix(ignore_prefix) self.lib_path = tuple(lib_path) self.source_set = source_set self.reports = reports self.options = options self.version_id = version_id self.modules = {} # type: Dict[str, MypyFile] self.missing_modules = set() # type: Set[str] self.plugin = plugin self.semantic_analyzer = SemanticAnalyzer( self.modules, self.missing_modules, lib_path, self.errors, self.plugin ) self.modules = self.semantic_analyzer.modules self.semantic_analyzer_pass3 = ThirdPass( self.modules, self.errors, self.semantic_analyzer ) self.all_types = {} # type: Dict[Expression, Type] self.indirection_detector = TypeIndirectionVisitor() self.stale_modules = set() # type: Set[str] self.rechecked_modules = set() # type: Set[str] self.plugin = plugin
def __init__( self, data_dir: str, lib_path: List[str], ignore_prefix: str, source_set: BuildSourceSet, reports: Reports, options: Options, version_id: str, plugin: Plugin, errors: Errors, ) -> None: self.start_time = time.time() self.data_dir = data_dir self.errors = errors self.errors.set_ignore_prefix(ignore_prefix) self.lib_path = tuple(lib_path) self.source_set = source_set self.reports = reports self.options = options self.version_id = version_id self.modules = {} # type: Dict[str, MypyFile] self.missing_modules = set() # type: Set[str] self.plugin = plugin self.semantic_analyzer = SemanticAnalyzer( self.modules, self.missing_modules, lib_path, self.errors, self.plugin ) self.modules = self.semantic_analyzer.modules self.semantic_analyzer_pass3 = ThirdPass(self.modules, self.errors) self.all_types = {} # type: Dict[Expression, Type] self.indirection_detector = TypeIndirectionVisitor() self.stale_modules = set() # type: Set[str] self.rechecked_modules = set() # type: Set[str] self.plugin = plugin
https://github.com/python/mypy/issues/3836
mypy --show-traceback Deduction.py Deduction.py:102: error: The return type of "__init__" must be None Deduction.py:103: error: INTERNAL ERROR -- please report a bug at https://github.com/python/mypy/issues version: 0.521-858f7512cf3b4e39c0f4e8de5a13eee0e1e138fb-dirty Traceback (most recent call last): File "/usr/local/Cellar/mypy/0.521/libexec/bin/mypy", line 11, in <module> load_entry_point('mypy===0.521-858f7512cf3b4e39c0f4e8de5a13eee0e1e138fb-dirty', 'console_scripts', 'mypy')() File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/__main__.py", line 7, in console_entry main(None) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/main.py", line 50, in main res = type_check_only(sources, bin_dir, options) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/main.py", line 97, in type_check_only options=options) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 196, in build graph = dispatch(sources, manager) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 1801, in dispatch process_graph(graph, manager) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 2044, in process_graph process_stale_scc(graph, scc, manager) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 2147, in process_stale_scc graph[id].type_check_first_pass() File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 1716, in type_check_first_pass self.type_checker.check_first_pass() File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 185, in check_first_pass self.accept(d) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 754, in accept return visitor.visit_class_def(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1109, in visit_class_def self.accept(defn.defs) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 815, in accept return visitor.visit_block(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1202, in visit_block self.accept(s) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 565, in accept return visitor.visit_func_def(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 519, in visit_func_def self.check_func_item(defn, name=defn.name()) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 578, in check_func_item self.check_func_def(defn, typ, name) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 738, in check_func_def self.accept(item.body) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 815, in accept return visitor.visit_block(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1202, in visit_block self.accept(s) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 974, in accept return visitor.visit_if_stmt(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1977, in visit_if_stmt if_map, else_map = self.find_isinstance_check(e) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 2559, in find_isinstance_check return find_isinstance_check(n, self.type_map) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 2810, in find_isinstance_check return conditional_type_map(expr, vartype, type) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 2613, in conditional_type_map and is_proper_subtype(current_type, proposed_type)): File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 569, in is_proper_subtype return left.accept(ProperSubtypeVisitor(right)) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/types.py", line 1114, in accept return visitor.visit_union_type(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 693, in visit_union_type return all([is_proper_subtype(item, self.right) for item in left.items]) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 693, in <listcomp> return all([is_proper_subtype(item, self.right) for item in left.items]) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 569, in is_proper_subtype return left.accept(ProperSubtypeVisitor(right)) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/types.py", line 900, in accept return visitor.visit_tuple_type(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 671, in visit_tuple_type if not is_proper_subtype(l, r): File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 569, in is_proper_subtype return left.accept(ProperSubtypeVisitor(right)) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/types.py", line 435, in accept return visitor.visit_instance(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 605, in visit_instance for base in left.type.mro: TypeError: 'NoneType' object is not iterable Deduction.py:103: note: use --pdb to drop into pdb
TypeError
def semantic_analysis_pass_three(self) -> None: assert self.tree is not None, ( "Internal error: method must be called on parsed file only" ) patches = [] # type: List[Callable[[], None]] with self.wrap_context(): self.manager.semantic_analyzer_pass3.visit_file( self.tree, self.xpath, self.options, patches ) if self.options.dump_type_stats: dump_type_stats(self.tree, self.xpath) self.patches = patches + self.patches
def semantic_analysis_pass_three(self) -> None: assert self.tree is not None, ( "Internal error: method must be called on parsed file only" ) with self.wrap_context(): self.manager.semantic_analyzer_pass3.visit_file( self.tree, self.xpath, self.options ) if self.options.dump_type_stats: dump_type_stats(self.tree, self.xpath)
https://github.com/python/mypy/issues/3836
mypy --show-traceback Deduction.py Deduction.py:102: error: The return type of "__init__" must be None Deduction.py:103: error: INTERNAL ERROR -- please report a bug at https://github.com/python/mypy/issues version: 0.521-858f7512cf3b4e39c0f4e8de5a13eee0e1e138fb-dirty Traceback (most recent call last): File "/usr/local/Cellar/mypy/0.521/libexec/bin/mypy", line 11, in <module> load_entry_point('mypy===0.521-858f7512cf3b4e39c0f4e8de5a13eee0e1e138fb-dirty', 'console_scripts', 'mypy')() File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/__main__.py", line 7, in console_entry main(None) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/main.py", line 50, in main res = type_check_only(sources, bin_dir, options) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/main.py", line 97, in type_check_only options=options) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 196, in build graph = dispatch(sources, manager) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 1801, in dispatch process_graph(graph, manager) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 2044, in process_graph process_stale_scc(graph, scc, manager) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 2147, in process_stale_scc graph[id].type_check_first_pass() File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 1716, in type_check_first_pass self.type_checker.check_first_pass() File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 185, in check_first_pass self.accept(d) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 754, in accept return visitor.visit_class_def(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1109, in visit_class_def self.accept(defn.defs) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 815, in accept return visitor.visit_block(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1202, in visit_block self.accept(s) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 565, in accept return visitor.visit_func_def(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 519, in visit_func_def self.check_func_item(defn, name=defn.name()) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 578, in check_func_item self.check_func_def(defn, typ, name) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 738, in check_func_def self.accept(item.body) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 815, in accept return visitor.visit_block(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1202, in visit_block self.accept(s) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 974, in accept return visitor.visit_if_stmt(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1977, in visit_if_stmt if_map, else_map = self.find_isinstance_check(e) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 2559, in find_isinstance_check return find_isinstance_check(n, self.type_map) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 2810, in find_isinstance_check return conditional_type_map(expr, vartype, type) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 2613, in conditional_type_map and is_proper_subtype(current_type, proposed_type)): File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 569, in is_proper_subtype return left.accept(ProperSubtypeVisitor(right)) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/types.py", line 1114, in accept return visitor.visit_union_type(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 693, in visit_union_type return all([is_proper_subtype(item, self.right) for item in left.items]) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 693, in <listcomp> return all([is_proper_subtype(item, self.right) for item in left.items]) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 569, in is_proper_subtype return left.accept(ProperSubtypeVisitor(right)) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/types.py", line 900, in accept return visitor.visit_tuple_type(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 671, in visit_tuple_type if not is_proper_subtype(l, r): File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 569, in is_proper_subtype return left.accept(ProperSubtypeVisitor(right)) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/types.py", line 435, in accept return visitor.visit_instance(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 605, in visit_instance for base in left.type.mro: TypeError: 'NoneType' object is not iterable Deduction.py:103: note: use --pdb to drop into pdb
TypeError
def quote_type_string(self, type_string: str) -> str: """Quotes a type representation for use in messages.""" no_quote_regex = r"^<(tuple|union): \d+ items>$" if ( type_string in ["Module", "overloaded function", "<nothing>", "<deleted>"] or re.match(no_quote_regex, type_string) is not None or type_string.endswith("?") ): # Messages are easier to read if these aren't quoted. We use a # regex to match strings with variable contents. return type_string return '"{}"'.format(type_string)
def quote_type_string(self, type_string: str) -> str: """Quotes a type representation for use in messages.""" no_quote_regex = r"^<(tuple|union): \d+ items>$" if ( type_string in ["Module", "overloaded function", "<nothing>", "<deleted>"] or re.match(no_quote_regex, type_string) is not None ): # Messages are easier to read if these aren't quoted. We use a # regex to match strings with variable contents. return type_string return '"{}"'.format(type_string)
https://github.com/python/mypy/issues/3836
mypy --show-traceback Deduction.py Deduction.py:102: error: The return type of "__init__" must be None Deduction.py:103: error: INTERNAL ERROR -- please report a bug at https://github.com/python/mypy/issues version: 0.521-858f7512cf3b4e39c0f4e8de5a13eee0e1e138fb-dirty Traceback (most recent call last): File "/usr/local/Cellar/mypy/0.521/libexec/bin/mypy", line 11, in <module> load_entry_point('mypy===0.521-858f7512cf3b4e39c0f4e8de5a13eee0e1e138fb-dirty', 'console_scripts', 'mypy')() File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/__main__.py", line 7, in console_entry main(None) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/main.py", line 50, in main res = type_check_only(sources, bin_dir, options) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/main.py", line 97, in type_check_only options=options) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 196, in build graph = dispatch(sources, manager) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 1801, in dispatch process_graph(graph, manager) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 2044, in process_graph process_stale_scc(graph, scc, manager) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 2147, in process_stale_scc graph[id].type_check_first_pass() File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 1716, in type_check_first_pass self.type_checker.check_first_pass() File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 185, in check_first_pass self.accept(d) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 754, in accept return visitor.visit_class_def(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1109, in visit_class_def self.accept(defn.defs) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 815, in accept return visitor.visit_block(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1202, in visit_block self.accept(s) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 565, in accept return visitor.visit_func_def(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 519, in visit_func_def self.check_func_item(defn, name=defn.name()) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 578, in check_func_item self.check_func_def(defn, typ, name) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 738, in check_func_def self.accept(item.body) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 815, in accept return visitor.visit_block(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1202, in visit_block self.accept(s) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 974, in accept return visitor.visit_if_stmt(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1977, in visit_if_stmt if_map, else_map = self.find_isinstance_check(e) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 2559, in find_isinstance_check return find_isinstance_check(n, self.type_map) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 2810, in find_isinstance_check return conditional_type_map(expr, vartype, type) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 2613, in conditional_type_map and is_proper_subtype(current_type, proposed_type)): File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 569, in is_proper_subtype return left.accept(ProperSubtypeVisitor(right)) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/types.py", line 1114, in accept return visitor.visit_union_type(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 693, in visit_union_type return all([is_proper_subtype(item, self.right) for item in left.items]) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 693, in <listcomp> return all([is_proper_subtype(item, self.right) for item in left.items]) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 569, in is_proper_subtype return left.accept(ProperSubtypeVisitor(right)) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/types.py", line 900, in accept return visitor.visit_tuple_type(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 671, in visit_tuple_type if not is_proper_subtype(l, r): File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 569, in is_proper_subtype return left.accept(ProperSubtypeVisitor(right)) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/types.py", line 435, in accept return visitor.visit_instance(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 605, in visit_instance for base in left.type.mro: TypeError: 'NoneType' object is not iterable Deduction.py:103: note: use --pdb to drop into pdb
TypeError
def format_bare(self, typ: Type, verbosity: int = 0) -> str: """ Convert a type to a relatively short string suitable for error messages. This method will return an unquoted string. If a caller doesn't need to perform post-processing on the string output, .format should be used instead. (The caller may want to use .quote_type_string after processing has happened, to maintain consistent quoting in messages.) """ if isinstance(typ, Instance): itype = typ # Get the short name of the type. if itype.type.fullname() in ( "types.ModuleType", "_importlib_modulespec.ModuleType", ): # Make some common error messages simpler and tidier. return "Module" if verbosity >= 2: base_str = itype.type.fullname() else: base_str = itype.type.name() if itype.args == []: # No type arguments, just return the type name return base_str elif itype.type.fullname() == "builtins.tuple": item_type_str = self.format_bare(itype.args[0]) return "Tuple[{}, ...]".format(item_type_str) elif itype.type.fullname() in reverse_type_aliases: alias = reverse_type_aliases[itype.type.fullname()] alias = alias.split(".")[-1] items = [self.format_bare(arg) for arg in itype.args] return "{}[{}]".format(alias, ", ".join(items)) else: # There are type arguments. Convert the arguments to strings. # If the result is too long, replace arguments with [...]. a = [] # type: List[str] for arg in itype.args: a.append(self.format_bare(arg)) s = ", ".join(a) if len((base_str + s)) < 150: return "{}[{}]".format(base_str, s) else: return "{}[...]".format(base_str) elif isinstance(typ, TypeVarType): # This is similar to non-generic instance types. return typ.name elif isinstance(typ, TupleType): # Prefer the name of the fallback class (if not tuple), as it's more informative. if typ.fallback.type.fullname() != "builtins.tuple": return self.format_bare(typ.fallback) items = [] for t in typ.items: items.append(self.format_bare(t)) s = "Tuple[{}]".format(", ".join(items)) if len(s) < 400: return s else: return "<tuple: {} items>".format(len(items)) elif isinstance(typ, TypedDictType): # If the TypedDictType is named, return the name if not typ.is_anonymous(): return self.format_bare(typ.fallback) items = [] for item_name, item_type in typ.items.items(): modifier = "" if item_name in typ.required_keys else "?" items.append( "{!r}{}: {}".format(item_name, modifier, self.format_bare(item_type)) ) s = "TypedDict({{{}}})".format(", ".join(items)) return s elif isinstance(typ, UnionType): # Only print Unions as Optionals if the Optional wouldn't have to contain another Union print_as_optional = ( len(typ.items) - sum(isinstance(t, NoneTyp) for t in typ.items) == 1 ) if print_as_optional: rest = [t for t in typ.items if not isinstance(t, NoneTyp)] return "Optional[{}]".format(self.format_bare(rest[0])) else: items = [] for t in typ.items: items.append(self.format_bare(t)) s = "Union[{}]".format(", ".join(items)) if len(s) < 400: return s else: return "<union: {} items>".format(len(items)) elif isinstance(typ, NoneTyp): return "None" elif isinstance(typ, AnyType): return "Any" elif isinstance(typ, DeletedType): return "<deleted>" elif isinstance(typ, UninhabitedType): if typ.is_noreturn: return "NoReturn" else: return "<nothing>" elif isinstance(typ, TypeType): return "Type[{}]".format(self.format_bare(typ.item, verbosity)) elif isinstance(typ, ForwardRef): # may appear in semanal.py return self.format_bare(typ.link, verbosity) elif isinstance(typ, FunctionLike): func = typ if func.is_type_obj(): # The type of a type object type can be derived from the # return type (this always works). return self.format_bare( TypeType.make_normalized(erase_type(func.items()[0].ret_type)), verbosity, ) elif isinstance(func, CallableType): return_type = self.format_bare(func.ret_type) if func.is_ellipsis_args: return "Callable[..., {}]".format(return_type) arg_strings = [] for arg_name, arg_type, arg_kind in zip( func.arg_names, func.arg_types, func.arg_kinds ): if ( arg_kind == ARG_POS and arg_name is None or verbosity == 0 and arg_kind in (ARG_POS, ARG_OPT) ): arg_strings.append( self.format_bare(arg_type, verbosity=max(verbosity - 1, 0)) ) else: constructor = ARG_CONSTRUCTOR_NAMES[arg_kind] if arg_kind in (ARG_STAR, ARG_STAR2) or arg_name is None: arg_strings.append( "{}({})".format(constructor, self.format_bare(arg_type)) ) else: arg_strings.append( "{}({}, {})".format( constructor, self.format_bare(arg_type), repr(arg_name) ) ) return "Callable[[{}], {}]".format(", ".join(arg_strings), return_type) else: # Use a simple representation for function types; proper # function types may result in long and difficult-to-read # error messages. return "overloaded function" elif isinstance(typ, UnboundType): return str(typ) elif typ is None: raise RuntimeError("Type is None") else: # Default case; we simply have to return something meaningful here. return "object"
def format_bare(self, typ: Type, verbosity: int = 0) -> str: """ Convert a type to a relatively short string suitable for error messages. This method will return an unquoted string. If a caller doesn't need to perform post-processing on the string output, .format should be used instead. (The caller may want to use .quote_type_string after processing has happened, to maintain consistent quoting in messages.) """ if isinstance(typ, Instance): itype = typ # Get the short name of the type. if itype.type.fullname() in ( "types.ModuleType", "_importlib_modulespec.ModuleType", ): # Make some common error messages simpler and tidier. return "Module" if verbosity >= 2: base_str = itype.type.fullname() else: base_str = itype.type.name() if itype.args == []: # No type arguments, just return the type name return base_str elif itype.type.fullname() == "builtins.tuple": item_type_str = self.format_bare(itype.args[0]) return "Tuple[{}, ...]".format(item_type_str) elif itype.type.fullname() in reverse_type_aliases: alias = reverse_type_aliases[itype.type.fullname()] alias = alias.split(".")[-1] items = [self.format_bare(arg) for arg in itype.args] return "{}[{}]".format(alias, ", ".join(items)) else: # There are type arguments. Convert the arguments to strings. # If the result is too long, replace arguments with [...]. a = [] # type: List[str] for arg in itype.args: a.append(self.format_bare(arg)) s = ", ".join(a) if len((base_str + s)) < 150: return "{}[{}]".format(base_str, s) else: return "{}[...]".format(base_str) elif isinstance(typ, TypeVarType): # This is similar to non-generic instance types. return typ.name elif isinstance(typ, TupleType): # Prefer the name of the fallback class (if not tuple), as it's more informative. if typ.fallback.type.fullname() != "builtins.tuple": return self.format_bare(typ.fallback) items = [] for t in typ.items: items.append(self.format_bare(t)) s = "Tuple[{}]".format(", ".join(items)) if len(s) < 400: return s else: return "<tuple: {} items>".format(len(items)) elif isinstance(typ, TypedDictType): # If the TypedDictType is named, return the name if not typ.is_anonymous(): return self.format_bare(typ.fallback) items = [] for item_name, item_type in typ.items.items(): modifier = "" if item_name in typ.required_keys else "?" items.append( "{!r}{}: {}".format(item_name, modifier, self.format_bare(item_type)) ) s = "TypedDict({{{}}})".format(", ".join(items)) return s elif isinstance(typ, UnionType): # Only print Unions as Optionals if the Optional wouldn't have to contain another Union print_as_optional = ( len(typ.items) - sum(isinstance(t, NoneTyp) for t in typ.items) == 1 ) if print_as_optional: rest = [t for t in typ.items if not isinstance(t, NoneTyp)] return "Optional[{}]".format(self.format_bare(rest[0])) else: items = [] for t in typ.items: items.append(self.format_bare(t)) s = "Union[{}]".format(", ".join(items)) if len(s) < 400: return s else: return "<union: {} items>".format(len(items)) elif isinstance(typ, NoneTyp): return "None" elif isinstance(typ, AnyType): return "Any" elif isinstance(typ, DeletedType): return "<deleted>" elif isinstance(typ, UninhabitedType): if typ.is_noreturn: return "NoReturn" else: return "<nothing>" elif isinstance(typ, TypeType): return "Type[{}]".format(self.format_bare(typ.item, verbosity)) elif isinstance(typ, FunctionLike): func = typ if func.is_type_obj(): # The type of a type object type can be derived from the # return type (this always works). return self.format_bare( TypeType.make_normalized(erase_type(func.items()[0].ret_type)), verbosity, ) elif isinstance(func, CallableType): return_type = self.format_bare(func.ret_type) if func.is_ellipsis_args: return "Callable[..., {}]".format(return_type) arg_strings = [] for arg_name, arg_type, arg_kind in zip( func.arg_names, func.arg_types, func.arg_kinds ): if ( arg_kind == ARG_POS and arg_name is None or verbosity == 0 and arg_kind in (ARG_POS, ARG_OPT) ): arg_strings.append( self.format_bare(arg_type, verbosity=max(verbosity - 1, 0)) ) else: constructor = ARG_CONSTRUCTOR_NAMES[arg_kind] if arg_kind in (ARG_STAR, ARG_STAR2) or arg_name is None: arg_strings.append( "{}({})".format(constructor, self.format_bare(arg_type)) ) else: arg_strings.append( "{}({}, {})".format( constructor, self.format_bare(arg_type), repr(arg_name) ) ) return "Callable[[{}], {}]".format(", ".join(arg_strings), return_type) else: # Use a simple representation for function types; proper # function types may result in long and difficult-to-read # error messages. return "overloaded function" elif typ is None: raise RuntimeError("Type is None") else: # Default case; we simply have to return something meaningful here. return "object"
https://github.com/python/mypy/issues/3836
mypy --show-traceback Deduction.py Deduction.py:102: error: The return type of "__init__" must be None Deduction.py:103: error: INTERNAL ERROR -- please report a bug at https://github.com/python/mypy/issues version: 0.521-858f7512cf3b4e39c0f4e8de5a13eee0e1e138fb-dirty Traceback (most recent call last): File "/usr/local/Cellar/mypy/0.521/libexec/bin/mypy", line 11, in <module> load_entry_point('mypy===0.521-858f7512cf3b4e39c0f4e8de5a13eee0e1e138fb-dirty', 'console_scripts', 'mypy')() File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/__main__.py", line 7, in console_entry main(None) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/main.py", line 50, in main res = type_check_only(sources, bin_dir, options) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/main.py", line 97, in type_check_only options=options) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 196, in build graph = dispatch(sources, manager) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 1801, in dispatch process_graph(graph, manager) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 2044, in process_graph process_stale_scc(graph, scc, manager) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 2147, in process_stale_scc graph[id].type_check_first_pass() File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 1716, in type_check_first_pass self.type_checker.check_first_pass() File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 185, in check_first_pass self.accept(d) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 754, in accept return visitor.visit_class_def(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1109, in visit_class_def self.accept(defn.defs) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 815, in accept return visitor.visit_block(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1202, in visit_block self.accept(s) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 565, in accept return visitor.visit_func_def(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 519, in visit_func_def self.check_func_item(defn, name=defn.name()) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 578, in check_func_item self.check_func_def(defn, typ, name) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 738, in check_func_def self.accept(item.body) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 815, in accept return visitor.visit_block(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1202, in visit_block self.accept(s) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 974, in accept return visitor.visit_if_stmt(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1977, in visit_if_stmt if_map, else_map = self.find_isinstance_check(e) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 2559, in find_isinstance_check return find_isinstance_check(n, self.type_map) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 2810, in find_isinstance_check return conditional_type_map(expr, vartype, type) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 2613, in conditional_type_map and is_proper_subtype(current_type, proposed_type)): File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 569, in is_proper_subtype return left.accept(ProperSubtypeVisitor(right)) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/types.py", line 1114, in accept return visitor.visit_union_type(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 693, in visit_union_type return all([is_proper_subtype(item, self.right) for item in left.items]) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 693, in <listcomp> return all([is_proper_subtype(item, self.right) for item in left.items]) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 569, in is_proper_subtype return left.accept(ProperSubtypeVisitor(right)) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/types.py", line 900, in accept return visitor.visit_tuple_type(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 671, in visit_tuple_type if not is_proper_subtype(l, r): File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 569, in is_proper_subtype return left.accept(ProperSubtypeVisitor(right)) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/types.py", line 435, in accept return visitor.visit_instance(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 605, in visit_instance for base in left.type.mro: TypeError: 'NoneType' object is not iterable Deduction.py:103: note: use --pdb to drop into pdb
TypeError
def analyze_namedtuple_classdef(self, defn: ClassDef) -> Optional[TypeInfo]: # special case for NamedTuple for base_expr in defn.base_type_exprs: if isinstance(base_expr, RefExpr): base_expr.accept(self) if base_expr.fullname == "typing.NamedTuple": node = self.lookup(defn.name, defn) if node is not None: node.kind = ( GDEF # TODO in process_namedtuple_definition also applies here ) items, types, default_items = self.check_namedtuple_classdef(defn) info = self.build_namedtuple_typeinfo( defn.name, items, types, default_items ) node.node = info defn.info.replaced = info defn.info = info defn.analyzed = NamedTupleExpr(info) defn.analyzed.line = defn.line defn.analyzed.column = defn.column return info return None
def analyze_namedtuple_classdef(self, defn: ClassDef) -> Optional[TypeInfo]: # special case for NamedTuple for base_expr in defn.base_type_exprs: if isinstance(base_expr, RefExpr): base_expr.accept(self) if base_expr.fullname == "typing.NamedTuple": node = self.lookup(defn.name, defn) if node is not None: node.kind = ( GDEF # TODO in process_namedtuple_definition also applies here ) items, types, default_items = self.check_namedtuple_classdef(defn) info = self.build_namedtuple_typeinfo( defn.name, items, types, default_items ) node.node = info defn.info = info defn.analyzed = NamedTupleExpr(info) return info return None
https://github.com/python/mypy/issues/3836
mypy --show-traceback Deduction.py Deduction.py:102: error: The return type of "__init__" must be None Deduction.py:103: error: INTERNAL ERROR -- please report a bug at https://github.com/python/mypy/issues version: 0.521-858f7512cf3b4e39c0f4e8de5a13eee0e1e138fb-dirty Traceback (most recent call last): File "/usr/local/Cellar/mypy/0.521/libexec/bin/mypy", line 11, in <module> load_entry_point('mypy===0.521-858f7512cf3b4e39c0f4e8de5a13eee0e1e138fb-dirty', 'console_scripts', 'mypy')() File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/__main__.py", line 7, in console_entry main(None) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/main.py", line 50, in main res = type_check_only(sources, bin_dir, options) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/main.py", line 97, in type_check_only options=options) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 196, in build graph = dispatch(sources, manager) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 1801, in dispatch process_graph(graph, manager) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 2044, in process_graph process_stale_scc(graph, scc, manager) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 2147, in process_stale_scc graph[id].type_check_first_pass() File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 1716, in type_check_first_pass self.type_checker.check_first_pass() File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 185, in check_first_pass self.accept(d) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 754, in accept return visitor.visit_class_def(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1109, in visit_class_def self.accept(defn.defs) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 815, in accept return visitor.visit_block(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1202, in visit_block self.accept(s) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 565, in accept return visitor.visit_func_def(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 519, in visit_func_def self.check_func_item(defn, name=defn.name()) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 578, in check_func_item self.check_func_def(defn, typ, name) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 738, in check_func_def self.accept(item.body) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 815, in accept return visitor.visit_block(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1202, in visit_block self.accept(s) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 974, in accept return visitor.visit_if_stmt(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1977, in visit_if_stmt if_map, else_map = self.find_isinstance_check(e) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 2559, in find_isinstance_check return find_isinstance_check(n, self.type_map) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 2810, in find_isinstance_check return conditional_type_map(expr, vartype, type) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 2613, in conditional_type_map and is_proper_subtype(current_type, proposed_type)): File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 569, in is_proper_subtype return left.accept(ProperSubtypeVisitor(right)) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/types.py", line 1114, in accept return visitor.visit_union_type(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 693, in visit_union_type return all([is_proper_subtype(item, self.right) for item in left.items]) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 693, in <listcomp> return all([is_proper_subtype(item, self.right) for item in left.items]) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 569, in is_proper_subtype return left.accept(ProperSubtypeVisitor(right)) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/types.py", line 900, in accept return visitor.visit_tuple_type(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 671, in visit_tuple_type if not is_proper_subtype(l, r): File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 569, in is_proper_subtype return left.accept(ProperSubtypeVisitor(right)) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/types.py", line 435, in accept return visitor.visit_instance(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 605, in visit_instance for base in left.type.mro: TypeError: 'NoneType' object is not iterable Deduction.py:103: note: use --pdb to drop into pdb
TypeError
def analyze_base_classes(self, defn: ClassDef) -> None: """Analyze and set up base classes. This computes several attributes on the corresponding TypeInfo defn.info related to the base classes: defn.info.bases, defn.info.mro, and miscellaneous others (at least tuple_type, fallback_to_any, and is_enum.) """ base_types = [] # type: List[Instance] info = defn.info for base_expr in defn.base_type_exprs: try: base = self.expr_to_analyzed_type(base_expr) except TypeTranslationError: self.fail("Invalid base class", base_expr) info.fallback_to_any = True continue if isinstance(base, TupleType): if info.tuple_type: self.fail("Class has two incompatible bases derived from tuple", defn) defn.has_incompatible_baseclass = True info.tuple_type = base base_types.append(base.fallback) if isinstance(base_expr, CallExpr): defn.analyzed = NamedTupleExpr(base.fallback.type) defn.analyzed.line = defn.line defn.analyzed.column = defn.column elif isinstance(base, Instance): if base.type.is_newtype: self.fail("Cannot subclass NewType", defn) base_types.append(base) elif isinstance(base, AnyType): if self.options.disallow_subclassing_any: if isinstance(base_expr, (NameExpr, MemberExpr)): msg = "Class cannot subclass '{}' (has type 'Any')".format( base_expr.name ) else: msg = "Class cannot subclass value of type 'Any'" self.fail(msg, base_expr) info.fallback_to_any = True else: self.fail("Invalid base class", base_expr) info.fallback_to_any = True if "unimported" in self.options.disallow_any and has_any_from_unimported_type( base ): if isinstance(base_expr, (NameExpr, MemberExpr)): prefix = "Base type {}".format(base_expr.name) else: prefix = "Base type" self.msg.unimported_type_becomes_any(prefix, base, base_expr) check_for_explicit_any( base, self.options, self.is_typeshed_stub_file, self.msg, context=base_expr ) # Add 'object' as implicit base if there is no other base class. if not base_types and defn.fullname != "builtins.object": base_types.append(self.object_type()) info.bases = base_types # Calculate the MRO. It might be incomplete at this point if # the bases of defn include classes imported from other # modules in an import loop. We'll recompute it in ThirdPass. if not self.verify_base_classes(defn): # Give it an MRO consisting of just the class itself and object. defn.info.mro = [defn.info, self.object_type().type] return calculate_class_mro(defn, self.fail_blocker) # If there are cyclic imports, we may be missing 'object' in # the MRO. Fix MRO if needed. if info.mro and info.mro[-1].fullname() != "builtins.object": info.mro.append(self.object_type().type) if defn.info.is_enum and defn.type_vars: self.fail("Enum class cannot be generic", defn)
def analyze_base_classes(self, defn: ClassDef) -> None: """Analyze and set up base classes. This computes several attributes on the corresponding TypeInfo defn.info related to the base classes: defn.info.bases, defn.info.mro, and miscellaneous others (at least tuple_type, fallback_to_any, and is_enum.) """ base_types = [] # type: List[Instance] info = defn.info for base_expr in defn.base_type_exprs: try: base = self.expr_to_analyzed_type(base_expr) except TypeTranslationError: self.fail("Invalid base class", base_expr) info.fallback_to_any = True continue if isinstance(base, TupleType): if info.tuple_type: self.fail("Class has two incompatible bases derived from tuple", defn) defn.has_incompatible_baseclass = True info.tuple_type = base base_types.append(base.fallback) elif isinstance(base, Instance): if base.type.is_newtype: self.fail("Cannot subclass NewType", defn) base_types.append(base) elif isinstance(base, AnyType): if self.options.disallow_subclassing_any: if isinstance(base_expr, (NameExpr, MemberExpr)): msg = "Class cannot subclass '{}' (has type 'Any')".format( base_expr.name ) else: msg = "Class cannot subclass value of type 'Any'" self.fail(msg, base_expr) info.fallback_to_any = True else: self.fail("Invalid base class", base_expr) info.fallback_to_any = True if "unimported" in self.options.disallow_any and has_any_from_unimported_type( base ): if isinstance(base_expr, (NameExpr, MemberExpr)): prefix = "Base type {}".format(base_expr.name) else: prefix = "Base type" self.msg.unimported_type_becomes_any(prefix, base, base_expr) check_for_explicit_any( base, self.options, self.is_typeshed_stub_file, self.msg, context=base_expr ) # Add 'object' as implicit base if there is no other base class. if not base_types and defn.fullname != "builtins.object": base_types.append(self.object_type()) info.bases = base_types # Calculate the MRO. It might be incomplete at this point if # the bases of defn include classes imported from other # modules in an import loop. We'll recompute it in ThirdPass. if not self.verify_base_classes(defn): # Give it an MRO consisting of just the class itself and object. defn.info.mro = [defn.info, self.object_type().type] return calculate_class_mro(defn, self.fail_blocker) # If there are cyclic imports, we may be missing 'object' in # the MRO. Fix MRO if needed. if info.mro and info.mro[-1].fullname() != "builtins.object": info.mro.append(self.object_type().type) if defn.info.is_enum and defn.type_vars: self.fail("Enum class cannot be generic", defn)
https://github.com/python/mypy/issues/3836
mypy --show-traceback Deduction.py Deduction.py:102: error: The return type of "__init__" must be None Deduction.py:103: error: INTERNAL ERROR -- please report a bug at https://github.com/python/mypy/issues version: 0.521-858f7512cf3b4e39c0f4e8de5a13eee0e1e138fb-dirty Traceback (most recent call last): File "/usr/local/Cellar/mypy/0.521/libexec/bin/mypy", line 11, in <module> load_entry_point('mypy===0.521-858f7512cf3b4e39c0f4e8de5a13eee0e1e138fb-dirty', 'console_scripts', 'mypy')() File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/__main__.py", line 7, in console_entry main(None) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/main.py", line 50, in main res = type_check_only(sources, bin_dir, options) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/main.py", line 97, in type_check_only options=options) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 196, in build graph = dispatch(sources, manager) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 1801, in dispatch process_graph(graph, manager) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 2044, in process_graph process_stale_scc(graph, scc, manager) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 2147, in process_stale_scc graph[id].type_check_first_pass() File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 1716, in type_check_first_pass self.type_checker.check_first_pass() File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 185, in check_first_pass self.accept(d) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 754, in accept return visitor.visit_class_def(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1109, in visit_class_def self.accept(defn.defs) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 815, in accept return visitor.visit_block(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1202, in visit_block self.accept(s) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 565, in accept return visitor.visit_func_def(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 519, in visit_func_def self.check_func_item(defn, name=defn.name()) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 578, in check_func_item self.check_func_def(defn, typ, name) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 738, in check_func_def self.accept(item.body) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 815, in accept return visitor.visit_block(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1202, in visit_block self.accept(s) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 974, in accept return visitor.visit_if_stmt(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1977, in visit_if_stmt if_map, else_map = self.find_isinstance_check(e) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 2559, in find_isinstance_check return find_isinstance_check(n, self.type_map) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 2810, in find_isinstance_check return conditional_type_map(expr, vartype, type) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 2613, in conditional_type_map and is_proper_subtype(current_type, proposed_type)): File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 569, in is_proper_subtype return left.accept(ProperSubtypeVisitor(right)) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/types.py", line 1114, in accept return visitor.visit_union_type(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 693, in visit_union_type return all([is_proper_subtype(item, self.right) for item in left.items]) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 693, in <listcomp> return all([is_proper_subtype(item, self.right) for item in left.items]) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 569, in is_proper_subtype return left.accept(ProperSubtypeVisitor(right)) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/types.py", line 900, in accept return visitor.visit_tuple_type(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 671, in visit_tuple_type if not is_proper_subtype(l, r): File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 569, in is_proper_subtype return left.accept(ProperSubtypeVisitor(right)) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/types.py", line 435, in accept return visitor.visit_instance(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 605, in visit_instance for base in left.type.mro: TypeError: 'NoneType' object is not iterable Deduction.py:103: note: use --pdb to drop into pdb
TypeError
def analyze_typeddict_classdef(self, defn: ClassDef) -> bool: # special case for TypedDict possible = False for base_expr in defn.base_type_exprs: if isinstance(base_expr, RefExpr): base_expr.accept(self) if base_expr.fullname == "mypy_extensions.TypedDict" or self.is_typeddict( base_expr ): possible = True if possible: node = self.lookup(defn.name, defn) if node is not None: node.kind = GDEF # TODO in process_namedtuple_definition also applies here if ( len(defn.base_type_exprs) == 1 and isinstance(defn.base_type_exprs[0], RefExpr) and defn.base_type_exprs[0].fullname == "mypy_extensions.TypedDict" ): # Building a new TypedDict fields, types, required_keys = self.check_typeddict_classdef(defn) info = self.build_typeddict_typeinfo( defn.name, fields, types, required_keys ) defn.info.replaced = info node.node = info defn.analyzed = TypedDictExpr(info) defn.analyzed.line = defn.line defn.analyzed.column = defn.column return True # Extending/merging existing TypedDicts if any( not isinstance(expr, RefExpr) or expr.fullname != "mypy_extensions.TypedDict" and not self.is_typeddict(expr) for expr in defn.base_type_exprs ): self.fail("All bases of a new TypedDict must be TypedDict types", defn) typeddict_bases = list(filter(self.is_typeddict, defn.base_type_exprs)) keys = [] # type: List[str] types = [] required_keys = set() for base in typeddict_bases: assert isinstance(base, RefExpr) assert isinstance(base.node, TypeInfo) assert isinstance(base.node.typeddict_type, TypedDictType) base_typed_dict = base.node.typeddict_type base_items = base_typed_dict.items valid_items = base_items.copy() for key in base_items: if key in keys: self.fail( 'Cannot overwrite TypedDict field "{}" while merging'.format( key ), defn, ) valid_items.pop(key) keys.extend(valid_items.keys()) types.extend(valid_items.values()) required_keys.update(base_typed_dict.required_keys) new_keys, new_types, new_required_keys = self.check_typeddict_classdef( defn, keys ) keys.extend(new_keys) types.extend(new_types) required_keys.update(new_required_keys) info = self.build_typeddict_typeinfo(defn.name, keys, types, required_keys) defn.info.replaced = info node.node = info defn.analyzed = TypedDictExpr(info) defn.analyzed.line = defn.line defn.analyzed.column = defn.column return True return False
def analyze_typeddict_classdef(self, defn: ClassDef) -> bool: # special case for TypedDict possible = False for base_expr in defn.base_type_exprs: if isinstance(base_expr, RefExpr): base_expr.accept(self) if base_expr.fullname == "mypy_extensions.TypedDict" or self.is_typeddict( base_expr ): possible = True if possible: node = self.lookup(defn.name, defn) if node is not None: node.kind = GDEF # TODO in process_namedtuple_definition also applies here if ( len(defn.base_type_exprs) == 1 and isinstance(defn.base_type_exprs[0], RefExpr) and defn.base_type_exprs[0].fullname == "mypy_extensions.TypedDict" ): # Building a new TypedDict fields, types, required_keys = self.check_typeddict_classdef(defn) info = self.build_typeddict_typeinfo( defn.name, fields, types, required_keys ) node.node = info defn.analyzed = TypedDictExpr(info) return True # Extending/merging existing TypedDicts if any( not isinstance(expr, RefExpr) or expr.fullname != "mypy_extensions.TypedDict" and not self.is_typeddict(expr) for expr in defn.base_type_exprs ): self.fail("All bases of a new TypedDict must be TypedDict types", defn) typeddict_bases = list(filter(self.is_typeddict, defn.base_type_exprs)) keys = [] # type: List[str] types = [] required_keys = set() for base in typeddict_bases: assert isinstance(base, RefExpr) assert isinstance(base.node, TypeInfo) assert isinstance(base.node.typeddict_type, TypedDictType) base_typed_dict = base.node.typeddict_type base_items = base_typed_dict.items valid_items = base_items.copy() for key in base_items: if key in keys: self.fail( 'Cannot overwrite TypedDict field "{}" while merging'.format( key ), defn, ) valid_items.pop(key) keys.extend(valid_items.keys()) types.extend(valid_items.values()) required_keys.update(base_typed_dict.required_keys) new_keys, new_types, new_required_keys = self.check_typeddict_classdef( defn, keys ) keys.extend(new_keys) types.extend(new_types) required_keys.update(new_required_keys) info = self.build_typeddict_typeinfo(defn.name, keys, types, required_keys) node.node = info defn.analyzed = TypedDictExpr(info) return True return False
https://github.com/python/mypy/issues/3836
mypy --show-traceback Deduction.py Deduction.py:102: error: The return type of "__init__" must be None Deduction.py:103: error: INTERNAL ERROR -- please report a bug at https://github.com/python/mypy/issues version: 0.521-858f7512cf3b4e39c0f4e8de5a13eee0e1e138fb-dirty Traceback (most recent call last): File "/usr/local/Cellar/mypy/0.521/libexec/bin/mypy", line 11, in <module> load_entry_point('mypy===0.521-858f7512cf3b4e39c0f4e8de5a13eee0e1e138fb-dirty', 'console_scripts', 'mypy')() File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/__main__.py", line 7, in console_entry main(None) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/main.py", line 50, in main res = type_check_only(sources, bin_dir, options) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/main.py", line 97, in type_check_only options=options) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 196, in build graph = dispatch(sources, manager) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 1801, in dispatch process_graph(graph, manager) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 2044, in process_graph process_stale_scc(graph, scc, manager) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 2147, in process_stale_scc graph[id].type_check_first_pass() File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 1716, in type_check_first_pass self.type_checker.check_first_pass() File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 185, in check_first_pass self.accept(d) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 754, in accept return visitor.visit_class_def(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1109, in visit_class_def self.accept(defn.defs) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 815, in accept return visitor.visit_block(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1202, in visit_block self.accept(s) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 565, in accept return visitor.visit_func_def(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 519, in visit_func_def self.check_func_item(defn, name=defn.name()) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 578, in check_func_item self.check_func_def(defn, typ, name) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 738, in check_func_def self.accept(item.body) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 815, in accept return visitor.visit_block(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1202, in visit_block self.accept(s) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 974, in accept return visitor.visit_if_stmt(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1977, in visit_if_stmt if_map, else_map = self.find_isinstance_check(e) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 2559, in find_isinstance_check return find_isinstance_check(n, self.type_map) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 2810, in find_isinstance_check return conditional_type_map(expr, vartype, type) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 2613, in conditional_type_map and is_proper_subtype(current_type, proposed_type)): File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 569, in is_proper_subtype return left.accept(ProperSubtypeVisitor(right)) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/types.py", line 1114, in accept return visitor.visit_union_type(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 693, in visit_union_type return all([is_proper_subtype(item, self.right) for item in left.items]) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 693, in <listcomp> return all([is_proper_subtype(item, self.right) for item in left.items]) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 569, in is_proper_subtype return left.accept(ProperSubtypeVisitor(right)) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/types.py", line 900, in accept return visitor.visit_tuple_type(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 671, in visit_tuple_type if not is_proper_subtype(l, r): File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 569, in is_proper_subtype return left.accept(ProperSubtypeVisitor(right)) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/types.py", line 435, in accept return visitor.visit_instance(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 605, in visit_instance for base in left.type.mro: TypeError: 'NoneType' object is not iterable Deduction.py:103: note: use --pdb to drop into pdb
TypeError
def type_analyzer( self, *, tvar_scope: Optional[TypeVarScope] = None, allow_tuple_literal: bool = False, aliasing: bool = False, third_pass: bool = False, ) -> TypeAnalyser: if tvar_scope is None: tvar_scope = self.tvar_scope tpan = TypeAnalyser( self.lookup_qualified, self.lookup_fully_qualified, tvar_scope, self.fail, self.note, self.plugin, self.options, self.is_typeshed_stub_file, aliasing=aliasing, allow_tuple_literal=allow_tuple_literal, allow_unnormalized=self.is_stub_file, third_pass=third_pass, ) tpan.in_dynamic_func = bool( self.function_stack and self.function_stack[-1].is_dynamic() ) tpan.global_scope = not self.type and not self.function_stack return tpan
def type_analyzer( self, *, tvar_scope: Optional[TypeVarScope] = None, allow_tuple_literal: bool = False, aliasing: bool = False, ) -> TypeAnalyser: if tvar_scope is None: tvar_scope = self.tvar_scope return TypeAnalyser( self.lookup_qualified, self.lookup_fully_qualified, tvar_scope, self.fail, self.plugin, self.options, self.is_typeshed_stub_file, aliasing=aliasing, allow_tuple_literal=allow_tuple_literal, allow_unnormalized=self.is_stub_file, )
https://github.com/python/mypy/issues/3836
mypy --show-traceback Deduction.py Deduction.py:102: error: The return type of "__init__" must be None Deduction.py:103: error: INTERNAL ERROR -- please report a bug at https://github.com/python/mypy/issues version: 0.521-858f7512cf3b4e39c0f4e8de5a13eee0e1e138fb-dirty Traceback (most recent call last): File "/usr/local/Cellar/mypy/0.521/libexec/bin/mypy", line 11, in <module> load_entry_point('mypy===0.521-858f7512cf3b4e39c0f4e8de5a13eee0e1e138fb-dirty', 'console_scripts', 'mypy')() File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/__main__.py", line 7, in console_entry main(None) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/main.py", line 50, in main res = type_check_only(sources, bin_dir, options) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/main.py", line 97, in type_check_only options=options) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 196, in build graph = dispatch(sources, manager) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 1801, in dispatch process_graph(graph, manager) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 2044, in process_graph process_stale_scc(graph, scc, manager) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 2147, in process_stale_scc graph[id].type_check_first_pass() File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 1716, in type_check_first_pass self.type_checker.check_first_pass() File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 185, in check_first_pass self.accept(d) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 754, in accept return visitor.visit_class_def(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1109, in visit_class_def self.accept(defn.defs) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 815, in accept return visitor.visit_block(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1202, in visit_block self.accept(s) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 565, in accept return visitor.visit_func_def(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 519, in visit_func_def self.check_func_item(defn, name=defn.name()) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 578, in check_func_item self.check_func_def(defn, typ, name) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 738, in check_func_def self.accept(item.body) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 815, in accept return visitor.visit_block(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1202, in visit_block self.accept(s) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 974, in accept return visitor.visit_if_stmt(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1977, in visit_if_stmt if_map, else_map = self.find_isinstance_check(e) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 2559, in find_isinstance_check return find_isinstance_check(n, self.type_map) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 2810, in find_isinstance_check return conditional_type_map(expr, vartype, type) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 2613, in conditional_type_map and is_proper_subtype(current_type, proposed_type)): File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 569, in is_proper_subtype return left.accept(ProperSubtypeVisitor(right)) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/types.py", line 1114, in accept return visitor.visit_union_type(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 693, in visit_union_type return all([is_proper_subtype(item, self.right) for item in left.items]) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 693, in <listcomp> return all([is_proper_subtype(item, self.right) for item in left.items]) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 569, in is_proper_subtype return left.accept(ProperSubtypeVisitor(right)) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/types.py", line 900, in accept return visitor.visit_tuple_type(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 671, in visit_tuple_type if not is_proper_subtype(l, r): File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 569, in is_proper_subtype return left.accept(ProperSubtypeVisitor(right)) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/types.py", line 435, in accept return visitor.visit_instance(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 605, in visit_instance for base in left.type.mro: TypeError: 'NoneType' object is not iterable Deduction.py:103: note: use --pdb to drop into pdb
TypeError
def anal_type( self, t: Type, *, tvar_scope: Optional[TypeVarScope] = None, allow_tuple_literal: bool = False, aliasing: bool = False, third_pass: bool = False, ) -> Type: if t: a = self.type_analyzer( tvar_scope=tvar_scope, aliasing=aliasing, allow_tuple_literal=allow_tuple_literal, third_pass=third_pass, ) return t.accept(a) else: return None
def anal_type( self, t: Type, *, tvar_scope: Optional[TypeVarScope] = None, allow_tuple_literal: bool = False, aliasing: bool = False, ) -> Type: if t: a = self.type_analyzer( tvar_scope=tvar_scope, aliasing=aliasing, allow_tuple_literal=allow_tuple_literal, ) return t.accept(a) else: return None
https://github.com/python/mypy/issues/3836
mypy --show-traceback Deduction.py Deduction.py:102: error: The return type of "__init__" must be None Deduction.py:103: error: INTERNAL ERROR -- please report a bug at https://github.com/python/mypy/issues version: 0.521-858f7512cf3b4e39c0f4e8de5a13eee0e1e138fb-dirty Traceback (most recent call last): File "/usr/local/Cellar/mypy/0.521/libexec/bin/mypy", line 11, in <module> load_entry_point('mypy===0.521-858f7512cf3b4e39c0f4e8de5a13eee0e1e138fb-dirty', 'console_scripts', 'mypy')() File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/__main__.py", line 7, in console_entry main(None) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/main.py", line 50, in main res = type_check_only(sources, bin_dir, options) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/main.py", line 97, in type_check_only options=options) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 196, in build graph = dispatch(sources, manager) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 1801, in dispatch process_graph(graph, manager) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 2044, in process_graph process_stale_scc(graph, scc, manager) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 2147, in process_stale_scc graph[id].type_check_first_pass() File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 1716, in type_check_first_pass self.type_checker.check_first_pass() File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 185, in check_first_pass self.accept(d) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 754, in accept return visitor.visit_class_def(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1109, in visit_class_def self.accept(defn.defs) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 815, in accept return visitor.visit_block(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1202, in visit_block self.accept(s) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 565, in accept return visitor.visit_func_def(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 519, in visit_func_def self.check_func_item(defn, name=defn.name()) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 578, in check_func_item self.check_func_def(defn, typ, name) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 738, in check_func_def self.accept(item.body) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 815, in accept return visitor.visit_block(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1202, in visit_block self.accept(s) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 974, in accept return visitor.visit_if_stmt(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1977, in visit_if_stmt if_map, else_map = self.find_isinstance_check(e) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 2559, in find_isinstance_check return find_isinstance_check(n, self.type_map) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 2810, in find_isinstance_check return conditional_type_map(expr, vartype, type) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 2613, in conditional_type_map and is_proper_subtype(current_type, proposed_type)): File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 569, in is_proper_subtype return left.accept(ProperSubtypeVisitor(right)) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/types.py", line 1114, in accept return visitor.visit_union_type(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 693, in visit_union_type return all([is_proper_subtype(item, self.right) for item in left.items]) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 693, in <listcomp> return all([is_proper_subtype(item, self.right) for item in left.items]) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 569, in is_proper_subtype return left.accept(ProperSubtypeVisitor(right)) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/types.py", line 900, in accept return visitor.visit_tuple_type(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 671, in visit_tuple_type if not is_proper_subtype(l, r): File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 569, in is_proper_subtype return left.accept(ProperSubtypeVisitor(right)) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/types.py", line 435, in accept return visitor.visit_instance(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 605, in visit_instance for base in left.type.mro: TypeError: 'NoneType' object is not iterable Deduction.py:103: note: use --pdb to drop into pdb
TypeError
def analyze_alias( self, rvalue: Expression, allow_unnormalized: bool ) -> Tuple[Optional[Type], List[str]]: """Check if 'rvalue' represents a valid type allowed for aliasing (e.g. not a type variable). If yes, return the corresponding type and a list of qualified type variable names for generic aliases. If 'allow_unnormalized' is True, allow types like builtins.list[T]. """ dynamic = bool(self.function_stack and self.function_stack[-1].is_dynamic()) global_scope = not self.type and not self.function_stack res = analyze_type_alias( rvalue, self.lookup_qualified, self.lookup_fully_qualified, self.tvar_scope, self.fail, self.note, self.plugin, self.options, self.is_typeshed_stub_file, allow_unnormalized=True, in_dynamic_func=dynamic, global_scope=global_scope, ) if res: alias_tvars = [ name for (name, _) in res.accept( TypeVariableQuery(self.lookup_qualified, self.tvar_scope) ) ] else: alias_tvars = [] return res, alias_tvars
def analyze_alias( self, rvalue: Expression, allow_unnormalized: bool ) -> Tuple[Optional[Type], List[str]]: """Check if 'rvalue' represents a valid type allowed for aliasing (e.g. not a type variable). If yes, return the corresponding type and a list of qualified type variable names for generic aliases. If 'allow_unnormalized' is True, allow types like builtins.list[T]. """ res = analyze_type_alias( rvalue, self.lookup_qualified, self.lookup_fully_qualified, self.tvar_scope, self.fail, self.plugin, self.options, self.is_typeshed_stub_file, allow_unnormalized=True, ) if res: alias_tvars = [ name for (name, _) in res.accept( TypeVariableQuery(self.lookup_qualified, self.tvar_scope) ) ] else: alias_tvars = [] return res, alias_tvars
https://github.com/python/mypy/issues/3836
mypy --show-traceback Deduction.py Deduction.py:102: error: The return type of "__init__" must be None Deduction.py:103: error: INTERNAL ERROR -- please report a bug at https://github.com/python/mypy/issues version: 0.521-858f7512cf3b4e39c0f4e8de5a13eee0e1e138fb-dirty Traceback (most recent call last): File "/usr/local/Cellar/mypy/0.521/libexec/bin/mypy", line 11, in <module> load_entry_point('mypy===0.521-858f7512cf3b4e39c0f4e8de5a13eee0e1e138fb-dirty', 'console_scripts', 'mypy')() File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/__main__.py", line 7, in console_entry main(None) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/main.py", line 50, in main res = type_check_only(sources, bin_dir, options) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/main.py", line 97, in type_check_only options=options) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 196, in build graph = dispatch(sources, manager) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 1801, in dispatch process_graph(graph, manager) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 2044, in process_graph process_stale_scc(graph, scc, manager) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 2147, in process_stale_scc graph[id].type_check_first_pass() File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 1716, in type_check_first_pass self.type_checker.check_first_pass() File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 185, in check_first_pass self.accept(d) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 754, in accept return visitor.visit_class_def(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1109, in visit_class_def self.accept(defn.defs) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 815, in accept return visitor.visit_block(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1202, in visit_block self.accept(s) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 565, in accept return visitor.visit_func_def(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 519, in visit_func_def self.check_func_item(defn, name=defn.name()) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 578, in check_func_item self.check_func_def(defn, typ, name) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 738, in check_func_def self.accept(item.body) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 815, in accept return visitor.visit_block(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1202, in visit_block self.accept(s) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 974, in accept return visitor.visit_if_stmt(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1977, in visit_if_stmt if_map, else_map = self.find_isinstance_check(e) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 2559, in find_isinstance_check return find_isinstance_check(n, self.type_map) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 2810, in find_isinstance_check return conditional_type_map(expr, vartype, type) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 2613, in conditional_type_map and is_proper_subtype(current_type, proposed_type)): File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 569, in is_proper_subtype return left.accept(ProperSubtypeVisitor(right)) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/types.py", line 1114, in accept return visitor.visit_union_type(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 693, in visit_union_type return all([is_proper_subtype(item, self.right) for item in left.items]) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 693, in <listcomp> return all([is_proper_subtype(item, self.right) for item in left.items]) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 569, in is_proper_subtype return left.accept(ProperSubtypeVisitor(right)) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/types.py", line 900, in accept return visitor.visit_tuple_type(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 671, in visit_tuple_type if not is_proper_subtype(l, r): File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 569, in is_proper_subtype return left.accept(ProperSubtypeVisitor(right)) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/types.py", line 435, in accept return visitor.visit_instance(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 605, in visit_instance for base in left.type.mro: TypeError: 'NoneType' object is not iterable Deduction.py:103: note: use --pdb to drop into pdb
TypeError
def process_newtype_declaration(self, s: AssignmentStmt) -> None: """Check if s declares a NewType; if yes, store it in symbol table.""" # Extract and check all information from newtype declaration name, call = self.analyze_newtype_declaration(s) if name is None or call is None: return old_type = self.check_newtype_args(name, call, s) call.analyzed = NewTypeExpr(name, old_type, line=call.line) if old_type is None: return # Create the corresponding class definition if the aliased type is subtypeable if isinstance(old_type, TupleType): newtype_class_info = self.build_newtype_typeinfo( name, old_type, old_type.fallback ) newtype_class_info.tuple_type = old_type elif isinstance(old_type, Instance): if old_type.type.is_protocol: self.fail("NewType cannot be used with protocol classes", s) newtype_class_info = self.build_newtype_typeinfo(name, old_type, old_type) else: message = "Argument 2 to NewType(...) must be subclassable (got {})" self.fail(message.format(self.msg.format(old_type)), s) return check_for_explicit_any( old_type, self.options, self.is_typeshed_stub_file, self.msg, context=s ) if "unimported" in self.options.disallow_any and has_any_from_unimported_type( old_type ): self.msg.unimported_type_becomes_any("Argument 2 to NewType(...)", old_type, s) # If so, add it to the symbol table. node = self.lookup(name, s) if node is None: self.fail("Could not find {} in current namespace".format(name), s) return # TODO: why does NewType work in local scopes despite always being of kind GDEF? node.kind = GDEF call.analyzed.info = node.node = newtype_class_info
def process_newtype_declaration(self, s: AssignmentStmt) -> None: """Check if s declares a NewType; if yes, store it in symbol table.""" # Extract and check all information from newtype declaration name, call = self.analyze_newtype_declaration(s) if name is None or call is None: return old_type = self.check_newtype_args(name, call, s) call.analyzed = NewTypeExpr(name, old_type, line=call.line) if old_type is None: return # Create the corresponding class definition if the aliased type is subtypeable if isinstance(old_type, TupleType): newtype_class_info = self.build_newtype_typeinfo( name, old_type, old_type.fallback ) newtype_class_info.tuple_type = old_type elif isinstance(old_type, Instance): if old_type.type.is_protocol: self.fail("NewType cannot be used with protocol classes", s) newtype_class_info = self.build_newtype_typeinfo(name, old_type, old_type) else: message = "Argument 2 to NewType(...) must be subclassable (got {})" self.fail(message.format(old_type), s) return check_for_explicit_any( old_type, self.options, self.is_typeshed_stub_file, self.msg, context=s ) if "unimported" in self.options.disallow_any and has_any_from_unimported_type( old_type ): self.msg.unimported_type_becomes_any("Argument 2 to NewType(...)", old_type, s) # If so, add it to the symbol table. node = self.lookup(name, s) if node is None: self.fail("Could not find {} in current namespace".format(name), s) return # TODO: why does NewType work in local scopes despite always being of kind GDEF? node.kind = GDEF call.analyzed.info = node.node = newtype_class_info
https://github.com/python/mypy/issues/3836
mypy --show-traceback Deduction.py Deduction.py:102: error: The return type of "__init__" must be None Deduction.py:103: error: INTERNAL ERROR -- please report a bug at https://github.com/python/mypy/issues version: 0.521-858f7512cf3b4e39c0f4e8de5a13eee0e1e138fb-dirty Traceback (most recent call last): File "/usr/local/Cellar/mypy/0.521/libexec/bin/mypy", line 11, in <module> load_entry_point('mypy===0.521-858f7512cf3b4e39c0f4e8de5a13eee0e1e138fb-dirty', 'console_scripts', 'mypy')() File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/__main__.py", line 7, in console_entry main(None) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/main.py", line 50, in main res = type_check_only(sources, bin_dir, options) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/main.py", line 97, in type_check_only options=options) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 196, in build graph = dispatch(sources, manager) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 1801, in dispatch process_graph(graph, manager) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 2044, in process_graph process_stale_scc(graph, scc, manager) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 2147, in process_stale_scc graph[id].type_check_first_pass() File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 1716, in type_check_first_pass self.type_checker.check_first_pass() File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 185, in check_first_pass self.accept(d) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 754, in accept return visitor.visit_class_def(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1109, in visit_class_def self.accept(defn.defs) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 815, in accept return visitor.visit_block(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1202, in visit_block self.accept(s) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 565, in accept return visitor.visit_func_def(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 519, in visit_func_def self.check_func_item(defn, name=defn.name()) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 578, in check_func_item self.check_func_def(defn, typ, name) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 738, in check_func_def self.accept(item.body) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 815, in accept return visitor.visit_block(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1202, in visit_block self.accept(s) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 974, in accept return visitor.visit_if_stmt(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1977, in visit_if_stmt if_map, else_map = self.find_isinstance_check(e) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 2559, in find_isinstance_check return find_isinstance_check(n, self.type_map) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 2810, in find_isinstance_check return conditional_type_map(expr, vartype, type) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 2613, in conditional_type_map and is_proper_subtype(current_type, proposed_type)): File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 569, in is_proper_subtype return left.accept(ProperSubtypeVisitor(right)) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/types.py", line 1114, in accept return visitor.visit_union_type(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 693, in visit_union_type return all([is_proper_subtype(item, self.right) for item in left.items]) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 693, in <listcomp> return all([is_proper_subtype(item, self.right) for item in left.items]) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 569, in is_proper_subtype return left.accept(ProperSubtypeVisitor(right)) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/types.py", line 900, in accept return visitor.visit_tuple_type(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 671, in visit_tuple_type if not is_proper_subtype(l, r): File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 569, in is_proper_subtype return left.accept(ProperSubtypeVisitor(right)) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/types.py", line 435, in accept return visitor.visit_instance(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 605, in visit_instance for base in left.type.mro: TypeError: 'NoneType' object is not iterable Deduction.py:103: note: use --pdb to drop into pdb
TypeError
def basic_new_typeinfo(self, name: str, basetype_or_fallback: Instance) -> TypeInfo: class_def = ClassDef(name, Block([])) class_def.fullname = self.qualified_name(name) info = TypeInfo(SymbolTable(), class_def, self.cur_mod_id) class_def.info = info mro = basetype_or_fallback.type.mro if mro is None: # Forward reference, MRO should be recalculated in third pass. mro = [basetype_or_fallback.type, self.object_type().type] info.mro = [info] + mro info.bases = [basetype_or_fallback] return info
def basic_new_typeinfo(self, name: str, basetype_or_fallback: Instance) -> TypeInfo: class_def = ClassDef(name, Block([])) class_def.fullname = self.qualified_name(name) info = TypeInfo(SymbolTable(), class_def, self.cur_mod_id) info.mro = [info] + basetype_or_fallback.type.mro info.bases = [basetype_or_fallback] return info
https://github.com/python/mypy/issues/3836
mypy --show-traceback Deduction.py Deduction.py:102: error: The return type of "__init__" must be None Deduction.py:103: error: INTERNAL ERROR -- please report a bug at https://github.com/python/mypy/issues version: 0.521-858f7512cf3b4e39c0f4e8de5a13eee0e1e138fb-dirty Traceback (most recent call last): File "/usr/local/Cellar/mypy/0.521/libexec/bin/mypy", line 11, in <module> load_entry_point('mypy===0.521-858f7512cf3b4e39c0f4e8de5a13eee0e1e138fb-dirty', 'console_scripts', 'mypy')() File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/__main__.py", line 7, in console_entry main(None) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/main.py", line 50, in main res = type_check_only(sources, bin_dir, options) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/main.py", line 97, in type_check_only options=options) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 196, in build graph = dispatch(sources, manager) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 1801, in dispatch process_graph(graph, manager) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 2044, in process_graph process_stale_scc(graph, scc, manager) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 2147, in process_stale_scc graph[id].type_check_first_pass() File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 1716, in type_check_first_pass self.type_checker.check_first_pass() File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 185, in check_first_pass self.accept(d) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 754, in accept return visitor.visit_class_def(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1109, in visit_class_def self.accept(defn.defs) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 815, in accept return visitor.visit_block(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1202, in visit_block self.accept(s) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 565, in accept return visitor.visit_func_def(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 519, in visit_func_def self.check_func_item(defn, name=defn.name()) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 578, in check_func_item self.check_func_def(defn, typ, name) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 738, in check_func_def self.accept(item.body) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 815, in accept return visitor.visit_block(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1202, in visit_block self.accept(s) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 974, in accept return visitor.visit_if_stmt(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1977, in visit_if_stmt if_map, else_map = self.find_isinstance_check(e) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 2559, in find_isinstance_check return find_isinstance_check(n, self.type_map) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 2810, in find_isinstance_check return conditional_type_map(expr, vartype, type) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 2613, in conditional_type_map and is_proper_subtype(current_type, proposed_type)): File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 569, in is_proper_subtype return left.accept(ProperSubtypeVisitor(right)) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/types.py", line 1114, in accept return visitor.visit_union_type(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 693, in visit_union_type return all([is_proper_subtype(item, self.right) for item in left.items]) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 693, in <listcomp> return all([is_proper_subtype(item, self.right) for item in left.items]) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 569, in is_proper_subtype return left.accept(ProperSubtypeVisitor(right)) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/types.py", line 900, in accept return visitor.visit_tuple_type(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 671, in visit_tuple_type if not is_proper_subtype(l, r): File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 569, in is_proper_subtype return left.accept(ProperSubtypeVisitor(right)) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/types.py", line 435, in accept return visitor.visit_instance(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 605, in visit_instance for base in left.type.mro: TypeError: 'NoneType' object is not iterable Deduction.py:103: note: use --pdb to drop into pdb
TypeError
def build_namedtuple_typeinfo( self, name: str, items: List[str], types: List[Type], default_items: Dict[str, Expression], ) -> TypeInfo: strtype = self.str_type() implicit_any = AnyType(TypeOfAny.special_form) basetuple_type = self.named_type("__builtins__.tuple", [implicit_any]) dictype = ( self.named_type_or_none("builtins.dict", [strtype, implicit_any]) or self.object_type() ) # Actual signature should return OrderedDict[str, Union[types]] ordereddictype = ( self.named_type_or_none("builtins.dict", [strtype, implicit_any]) or self.object_type() ) fallback = self.named_type("__builtins__.tuple", [implicit_any]) # Note: actual signature should accept an invariant version of Iterable[UnionType[types]]. # but it can't be expressed. 'new' and 'len' should be callable types. iterable_type = self.named_type_or_none("typing.Iterable", [implicit_any]) function_type = self.named_type("__builtins__.function") info = self.basic_new_typeinfo(name, fallback) info.is_named_tuple = True info.tuple_type = TupleType(types, fallback) def patch() -> None: # Calculate the correct value type for the fallback Mapping. fallback.args[0] = join.join_type_list(list(info.tuple_type.items)) # We can't calculate the complete fallback type until after semantic # analysis, since otherwise MROs might be incomplete. Postpone a callback # function that patches the fallback. self.patches.append(patch) def add_field( var: Var, is_initialized_in_class: bool = False, is_property: bool = False ) -> None: var.info = info var.is_initialized_in_class = is_initialized_in_class var.is_property = is_property info.names[var.name()] = SymbolTableNode(MDEF, var) vars = [Var(item, typ) for item, typ in zip(items, types)] for var in vars: add_field(var, is_property=True) tuple_of_strings = TupleType([strtype for _ in items], basetuple_type) add_field(Var("_fields", tuple_of_strings), is_initialized_in_class=True) add_field(Var("_field_types", dictype), is_initialized_in_class=True) add_field(Var("_field_defaults", dictype), is_initialized_in_class=True) add_field(Var("_source", strtype), is_initialized_in_class=True) add_field(Var("__annotations__", ordereddictype), is_initialized_in_class=True) add_field(Var("__doc__", strtype), is_initialized_in_class=True) tvd = TypeVarDef("NT", 1, [], info.tuple_type) selftype = TypeVarType(tvd) def add_method( funcname: str, ret: Type, args: List[Argument], name: str = None, is_classmethod: bool = False, ) -> None: if is_classmethod: first = [ Argument(Var("cls"), TypeType.make_normalized(selftype), None, ARG_POS) ] else: first = [Argument(Var("self"), selftype, None, ARG_POS)] args = first + args types = [arg.type_annotation for arg in args] items = [arg.variable.name() for arg in args] arg_kinds = [arg.kind for arg in args] signature = CallableType( types, arg_kinds, items, ret, function_type, name=name or info.name() + "." + funcname, ) signature.variables = [tvd] func = FuncDef(funcname, args, Block([]), typ=signature) func.info = info func.is_class = is_classmethod if is_classmethod: v = Var(funcname, signature) v.is_classmethod = True v.info = info dec = Decorator(func, [NameExpr("classmethod")], v) info.names[funcname] = SymbolTableNode(MDEF, dec) else: info.names[funcname] = SymbolTableNode(MDEF, func) add_method( "_replace", ret=selftype, args=[Argument(var, var.type, EllipsisExpr(), ARG_NAMED_OPT) for var in vars], ) def make_init_arg(var: Var) -> Argument: default = default_items.get(var.name(), None) kind = ARG_POS if default is None else ARG_OPT return Argument(var, var.type, default, kind) add_method( "__init__", ret=NoneTyp(), name=info.name(), args=[make_init_arg(var) for var in vars], ) add_method("_asdict", args=[], ret=ordereddictype) special_form_any = AnyType(TypeOfAny.special_form) add_method( "_make", ret=selftype, is_classmethod=True, args=[ Argument(Var("iterable", iterable_type), iterable_type, None, ARG_POS), Argument(Var("new"), special_form_any, EllipsisExpr(), ARG_NAMED_OPT), Argument(Var("len"), special_form_any, EllipsisExpr(), ARG_NAMED_OPT), ], ) return info
def build_namedtuple_typeinfo( self, name: str, items: List[str], types: List[Type], default_items: Dict[str, Expression], ) -> TypeInfo: strtype = self.str_type() implicit_any = AnyType(TypeOfAny.special_form) basetuple_type = self.named_type("__builtins__.tuple", [implicit_any]) dictype = ( self.named_type_or_none("builtins.dict", [strtype, implicit_any]) or self.object_type() ) # Actual signature should return OrderedDict[str, Union[types]] ordereddictype = ( self.named_type_or_none("builtins.dict", [strtype, implicit_any]) or self.object_type() ) # 'builtins.tuple' has only one type parameter. # # TODO: The corresponding type argument in the fallback instance should be a join of # all item types, but we can't do joins during this pass of semantic analysis # and we are using Any as a workaround. fallback = self.named_type("__builtins__.tuple", [implicit_any]) # Note: actual signature should accept an invariant version of Iterable[UnionType[types]]. # but it can't be expressed. 'new' and 'len' should be callable types. iterable_type = self.named_type_or_none("typing.Iterable", [implicit_any]) function_type = self.named_type("__builtins__.function") info = self.basic_new_typeinfo(name, fallback) info.is_named_tuple = True info.tuple_type = TupleType(types, fallback) def add_field( var: Var, is_initialized_in_class: bool = False, is_property: bool = False ) -> None: var.info = info var.is_initialized_in_class = is_initialized_in_class var.is_property = is_property info.names[var.name()] = SymbolTableNode(MDEF, var) vars = [Var(item, typ) for item, typ in zip(items, types)] for var in vars: add_field(var, is_property=True) tuple_of_strings = TupleType([strtype for _ in items], basetuple_type) add_field(Var("_fields", tuple_of_strings), is_initialized_in_class=True) add_field(Var("_field_types", dictype), is_initialized_in_class=True) add_field(Var("_field_defaults", dictype), is_initialized_in_class=True) add_field(Var("_source", strtype), is_initialized_in_class=True) add_field(Var("__annotations__", ordereddictype), is_initialized_in_class=True) add_field(Var("__doc__", strtype), is_initialized_in_class=True) tvd = TypeVarDef("NT", 1, [], info.tuple_type) selftype = TypeVarType(tvd) def add_method( funcname: str, ret: Type, args: List[Argument], name: str = None, is_classmethod: bool = False, ) -> None: if is_classmethod: first = [ Argument(Var("cls"), TypeType.make_normalized(selftype), None, ARG_POS) ] else: first = [Argument(Var("self"), selftype, None, ARG_POS)] args = first + args types = [arg.type_annotation for arg in args] items = [arg.variable.name() for arg in args] arg_kinds = [arg.kind for arg in args] signature = CallableType( types, arg_kinds, items, ret, function_type, name=name or info.name() + "." + funcname, ) signature.variables = [tvd] func = FuncDef(funcname, args, Block([]), typ=signature) func.info = info func.is_class = is_classmethod if is_classmethod: v = Var(funcname, signature) v.is_classmethod = True v.info = info dec = Decorator(func, [NameExpr("classmethod")], v) info.names[funcname] = SymbolTableNode(MDEF, dec) else: info.names[funcname] = SymbolTableNode(MDEF, func) add_method( "_replace", ret=selftype, args=[Argument(var, var.type, EllipsisExpr(), ARG_NAMED_OPT) for var in vars], ) def make_init_arg(var: Var) -> Argument: default = default_items.get(var.name(), None) kind = ARG_POS if default is None else ARG_OPT return Argument(var, var.type, default, kind) add_method( "__init__", ret=NoneTyp(), name=info.name(), args=[make_init_arg(var) for var in vars], ) add_method("_asdict", args=[], ret=ordereddictype) special_form_any = AnyType(TypeOfAny.special_form) add_method( "_make", ret=selftype, is_classmethod=True, args=[ Argument(Var("iterable", iterable_type), iterable_type, None, ARG_POS), Argument(Var("new"), special_form_any, EllipsisExpr(), ARG_NAMED_OPT), Argument(Var("len"), special_form_any, EllipsisExpr(), ARG_NAMED_OPT), ], ) return info
https://github.com/python/mypy/issues/3836
mypy --show-traceback Deduction.py Deduction.py:102: error: The return type of "__init__" must be None Deduction.py:103: error: INTERNAL ERROR -- please report a bug at https://github.com/python/mypy/issues version: 0.521-858f7512cf3b4e39c0f4e8de5a13eee0e1e138fb-dirty Traceback (most recent call last): File "/usr/local/Cellar/mypy/0.521/libexec/bin/mypy", line 11, in <module> load_entry_point('mypy===0.521-858f7512cf3b4e39c0f4e8de5a13eee0e1e138fb-dirty', 'console_scripts', 'mypy')() File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/__main__.py", line 7, in console_entry main(None) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/main.py", line 50, in main res = type_check_only(sources, bin_dir, options) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/main.py", line 97, in type_check_only options=options) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 196, in build graph = dispatch(sources, manager) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 1801, in dispatch process_graph(graph, manager) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 2044, in process_graph process_stale_scc(graph, scc, manager) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 2147, in process_stale_scc graph[id].type_check_first_pass() File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 1716, in type_check_first_pass self.type_checker.check_first_pass() File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 185, in check_first_pass self.accept(d) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 754, in accept return visitor.visit_class_def(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1109, in visit_class_def self.accept(defn.defs) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 815, in accept return visitor.visit_block(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1202, in visit_block self.accept(s) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 565, in accept return visitor.visit_func_def(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 519, in visit_func_def self.check_func_item(defn, name=defn.name()) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 578, in check_func_item self.check_func_def(defn, typ, name) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 738, in check_func_def self.accept(item.body) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 815, in accept return visitor.visit_block(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1202, in visit_block self.accept(s) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 974, in accept return visitor.visit_if_stmt(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1977, in visit_if_stmt if_map, else_map = self.find_isinstance_check(e) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 2559, in find_isinstance_check return find_isinstance_check(n, self.type_map) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 2810, in find_isinstance_check return conditional_type_map(expr, vartype, type) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 2613, in conditional_type_map and is_proper_subtype(current_type, proposed_type)): File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 569, in is_proper_subtype return left.accept(ProperSubtypeVisitor(right)) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/types.py", line 1114, in accept return visitor.visit_union_type(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 693, in visit_union_type return all([is_proper_subtype(item, self.right) for item in left.items]) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 693, in <listcomp> return all([is_proper_subtype(item, self.right) for item in left.items]) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 569, in is_proper_subtype return left.accept(ProperSubtypeVisitor(right)) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/types.py", line 900, in accept return visitor.visit_tuple_type(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 671, in visit_tuple_type if not is_proper_subtype(l, r): File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 569, in is_proper_subtype return left.accept(ProperSubtypeVisitor(right)) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/types.py", line 435, in accept return visitor.visit_instance(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 605, in visit_instance for base in left.type.mro: TypeError: 'NoneType' object is not iterable Deduction.py:103: note: use --pdb to drop into pdb
TypeError
def build_typeddict_typeinfo( self, name: str, items: List[str], types: List[Type], required_keys: Set[str] ) -> TypeInfo: fallback = ( self.named_type_or_none("typing.Mapping", [self.str_type(), self.object_type()]) or self.object_type() ) info = self.basic_new_typeinfo(name, fallback) info.typeddict_type = TypedDictType( OrderedDict(zip(items, types)), required_keys, fallback ) def patch() -> None: # Calculate the correct value type for the fallback Mapping. fallback.args[1] = join.join_type_list(list(info.typeddict_type.items.values())) # We can't calculate the complete fallback type until after semantic # analysis, since otherwise MROs might be incomplete. Postpone a callback # function that patches the fallback. self.patches.append(patch) return info
def build_typeddict_typeinfo( self, name: str, items: List[str], types: List[Type], required_keys: Set[str] ) -> TypeInfo: fallback = ( self.named_type_or_none("typing.Mapping", [self.str_type(), self.object_type()]) or self.object_type() ) def patch() -> None: # Calculate the correct value type for the fallback Mapping. fallback.args[1] = join.join_type_list(types) # We can't calculate the complete fallback type until after semantic # analysis, since otherwise MROs might be incomplete. Postpone a callback # function that patches the fallback. self.patches.append(patch) info = self.basic_new_typeinfo(name, fallback) info.typeddict_type = TypedDictType( OrderedDict(zip(items, types)), required_keys, fallback ) return info
https://github.com/python/mypy/issues/3836
mypy --show-traceback Deduction.py Deduction.py:102: error: The return type of "__init__" must be None Deduction.py:103: error: INTERNAL ERROR -- please report a bug at https://github.com/python/mypy/issues version: 0.521-858f7512cf3b4e39c0f4e8de5a13eee0e1e138fb-dirty Traceback (most recent call last): File "/usr/local/Cellar/mypy/0.521/libexec/bin/mypy", line 11, in <module> load_entry_point('mypy===0.521-858f7512cf3b4e39c0f4e8de5a13eee0e1e138fb-dirty', 'console_scripts', 'mypy')() File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/__main__.py", line 7, in console_entry main(None) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/main.py", line 50, in main res = type_check_only(sources, bin_dir, options) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/main.py", line 97, in type_check_only options=options) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 196, in build graph = dispatch(sources, manager) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 1801, in dispatch process_graph(graph, manager) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 2044, in process_graph process_stale_scc(graph, scc, manager) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 2147, in process_stale_scc graph[id].type_check_first_pass() File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 1716, in type_check_first_pass self.type_checker.check_first_pass() File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 185, in check_first_pass self.accept(d) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 754, in accept return visitor.visit_class_def(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1109, in visit_class_def self.accept(defn.defs) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 815, in accept return visitor.visit_block(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1202, in visit_block self.accept(s) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 565, in accept return visitor.visit_func_def(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 519, in visit_func_def self.check_func_item(defn, name=defn.name()) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 578, in check_func_item self.check_func_def(defn, typ, name) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 738, in check_func_def self.accept(item.body) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 815, in accept return visitor.visit_block(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1202, in visit_block self.accept(s) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 974, in accept return visitor.visit_if_stmt(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1977, in visit_if_stmt if_map, else_map = self.find_isinstance_check(e) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 2559, in find_isinstance_check return find_isinstance_check(n, self.type_map) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 2810, in find_isinstance_check return conditional_type_map(expr, vartype, type) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 2613, in conditional_type_map and is_proper_subtype(current_type, proposed_type)): File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 569, in is_proper_subtype return left.accept(ProperSubtypeVisitor(right)) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/types.py", line 1114, in accept return visitor.visit_union_type(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 693, in visit_union_type return all([is_proper_subtype(item, self.right) for item in left.items]) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 693, in <listcomp> return all([is_proper_subtype(item, self.right) for item in left.items]) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 569, in is_proper_subtype return left.accept(ProperSubtypeVisitor(right)) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/types.py", line 900, in accept return visitor.visit_tuple_type(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 671, in visit_tuple_type if not is_proper_subtype(l, r): File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 569, in is_proper_subtype return left.accept(ProperSubtypeVisitor(right)) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/types.py", line 435, in accept return visitor.visit_instance(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 605, in visit_instance for base in left.type.mro: TypeError: 'NoneType' object is not iterable Deduction.py:103: note: use --pdb to drop into pdb
TypeError
def patch() -> None: # Calculate the correct value type for the fallback Mapping. fallback.args[1] = join.join_type_list(list(info.typeddict_type.items.values()))
def patch() -> None: # Calculate the correct value type for the fallback Mapping. fallback.args[1] = join.join_type_list(types)
https://github.com/python/mypy/issues/3836
mypy --show-traceback Deduction.py Deduction.py:102: error: The return type of "__init__" must be None Deduction.py:103: error: INTERNAL ERROR -- please report a bug at https://github.com/python/mypy/issues version: 0.521-858f7512cf3b4e39c0f4e8de5a13eee0e1e138fb-dirty Traceback (most recent call last): File "/usr/local/Cellar/mypy/0.521/libexec/bin/mypy", line 11, in <module> load_entry_point('mypy===0.521-858f7512cf3b4e39c0f4e8de5a13eee0e1e138fb-dirty', 'console_scripts', 'mypy')() File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/__main__.py", line 7, in console_entry main(None) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/main.py", line 50, in main res = type_check_only(sources, bin_dir, options) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/main.py", line 97, in type_check_only options=options) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 196, in build graph = dispatch(sources, manager) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 1801, in dispatch process_graph(graph, manager) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 2044, in process_graph process_stale_scc(graph, scc, manager) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 2147, in process_stale_scc graph[id].type_check_first_pass() File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 1716, in type_check_first_pass self.type_checker.check_first_pass() File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 185, in check_first_pass self.accept(d) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 754, in accept return visitor.visit_class_def(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1109, in visit_class_def self.accept(defn.defs) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 815, in accept return visitor.visit_block(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1202, in visit_block self.accept(s) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 565, in accept return visitor.visit_func_def(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 519, in visit_func_def self.check_func_item(defn, name=defn.name()) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 578, in check_func_item self.check_func_def(defn, typ, name) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 738, in check_func_def self.accept(item.body) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 815, in accept return visitor.visit_block(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1202, in visit_block self.accept(s) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 974, in accept return visitor.visit_if_stmt(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1977, in visit_if_stmt if_map, else_map = self.find_isinstance_check(e) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 2559, in find_isinstance_check return find_isinstance_check(n, self.type_map) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 2810, in find_isinstance_check return conditional_type_map(expr, vartype, type) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 2613, in conditional_type_map and is_proper_subtype(current_type, proposed_type)): File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 569, in is_proper_subtype return left.accept(ProperSubtypeVisitor(right)) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/types.py", line 1114, in accept return visitor.visit_union_type(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 693, in visit_union_type return all([is_proper_subtype(item, self.right) for item in left.items]) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 693, in <listcomp> return all([is_proper_subtype(item, self.right) for item in left.items]) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 569, in is_proper_subtype return left.accept(ProperSubtypeVisitor(right)) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/types.py", line 900, in accept return visitor.visit_tuple_type(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 671, in visit_tuple_type if not is_proper_subtype(l, r): File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 569, in is_proper_subtype return left.accept(ProperSubtypeVisitor(right)) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/types.py", line 435, in accept return visitor.visit_instance(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 605, in visit_instance for base in left.type.mro: TypeError: 'NoneType' object is not iterable Deduction.py:103: note: use --pdb to drop into pdb
TypeError
def __init__( self, modules: Dict[str, MypyFile], errors: Errors, sem: SemanticAnalyzer ) -> None: self.modules = modules self.errors = errors self.sem = sem
def __init__(self, modules: Dict[str, MypyFile], errors: Errors) -> None: self.modules = modules self.errors = errors
https://github.com/python/mypy/issues/3836
mypy --show-traceback Deduction.py Deduction.py:102: error: The return type of "__init__" must be None Deduction.py:103: error: INTERNAL ERROR -- please report a bug at https://github.com/python/mypy/issues version: 0.521-858f7512cf3b4e39c0f4e8de5a13eee0e1e138fb-dirty Traceback (most recent call last): File "/usr/local/Cellar/mypy/0.521/libexec/bin/mypy", line 11, in <module> load_entry_point('mypy===0.521-858f7512cf3b4e39c0f4e8de5a13eee0e1e138fb-dirty', 'console_scripts', 'mypy')() File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/__main__.py", line 7, in console_entry main(None) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/main.py", line 50, in main res = type_check_only(sources, bin_dir, options) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/main.py", line 97, in type_check_only options=options) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 196, in build graph = dispatch(sources, manager) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 1801, in dispatch process_graph(graph, manager) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 2044, in process_graph process_stale_scc(graph, scc, manager) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 2147, in process_stale_scc graph[id].type_check_first_pass() File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 1716, in type_check_first_pass self.type_checker.check_first_pass() File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 185, in check_first_pass self.accept(d) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 754, in accept return visitor.visit_class_def(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1109, in visit_class_def self.accept(defn.defs) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 815, in accept return visitor.visit_block(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1202, in visit_block self.accept(s) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 565, in accept return visitor.visit_func_def(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 519, in visit_func_def self.check_func_item(defn, name=defn.name()) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 578, in check_func_item self.check_func_def(defn, typ, name) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 738, in check_func_def self.accept(item.body) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 815, in accept return visitor.visit_block(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1202, in visit_block self.accept(s) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 974, in accept return visitor.visit_if_stmt(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1977, in visit_if_stmt if_map, else_map = self.find_isinstance_check(e) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 2559, in find_isinstance_check return find_isinstance_check(n, self.type_map) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 2810, in find_isinstance_check return conditional_type_map(expr, vartype, type) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 2613, in conditional_type_map and is_proper_subtype(current_type, proposed_type)): File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 569, in is_proper_subtype return left.accept(ProperSubtypeVisitor(right)) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/types.py", line 1114, in accept return visitor.visit_union_type(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 693, in visit_union_type return all([is_proper_subtype(item, self.right) for item in left.items]) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 693, in <listcomp> return all([is_proper_subtype(item, self.right) for item in left.items]) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 569, in is_proper_subtype return left.accept(ProperSubtypeVisitor(right)) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/types.py", line 900, in accept return visitor.visit_tuple_type(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 671, in visit_tuple_type if not is_proper_subtype(l, r): File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 569, in is_proper_subtype return left.accept(ProperSubtypeVisitor(right)) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/types.py", line 435, in accept return visitor.visit_instance(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 605, in visit_instance for base in left.type.mro: TypeError: 'NoneType' object is not iterable Deduction.py:103: note: use --pdb to drop into pdb
TypeError
def visit_file( self, file_node: MypyFile, fnam: str, options: Options, patches: List[Callable[[], None]], ) -> None: self.errors.set_file(fnam, file_node.fullname()) self.options = options self.sem.options = options self.patches = patches self.is_typeshed_file = self.errors.is_typeshed_file(fnam) self.sem.globals = file_node.names with experiments.strict_optional_set(options.strict_optional): self.accept(file_node)
def visit_file(self, file_node: MypyFile, fnam: str, options: Options) -> None: self.errors.set_file(fnam, file_node.fullname()) self.options = options self.is_typeshed_file = self.errors.is_typeshed_file(fnam) with experiments.strict_optional_set(options.strict_optional): self.accept(file_node)
https://github.com/python/mypy/issues/3836
mypy --show-traceback Deduction.py Deduction.py:102: error: The return type of "__init__" must be None Deduction.py:103: error: INTERNAL ERROR -- please report a bug at https://github.com/python/mypy/issues version: 0.521-858f7512cf3b4e39c0f4e8de5a13eee0e1e138fb-dirty Traceback (most recent call last): File "/usr/local/Cellar/mypy/0.521/libexec/bin/mypy", line 11, in <module> load_entry_point('mypy===0.521-858f7512cf3b4e39c0f4e8de5a13eee0e1e138fb-dirty', 'console_scripts', 'mypy')() File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/__main__.py", line 7, in console_entry main(None) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/main.py", line 50, in main res = type_check_only(sources, bin_dir, options) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/main.py", line 97, in type_check_only options=options) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 196, in build graph = dispatch(sources, manager) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 1801, in dispatch process_graph(graph, manager) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 2044, in process_graph process_stale_scc(graph, scc, manager) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 2147, in process_stale_scc graph[id].type_check_first_pass() File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 1716, in type_check_first_pass self.type_checker.check_first_pass() File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 185, in check_first_pass self.accept(d) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 754, in accept return visitor.visit_class_def(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1109, in visit_class_def self.accept(defn.defs) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 815, in accept return visitor.visit_block(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1202, in visit_block self.accept(s) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 565, in accept return visitor.visit_func_def(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 519, in visit_func_def self.check_func_item(defn, name=defn.name()) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 578, in check_func_item self.check_func_def(defn, typ, name) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 738, in check_func_def self.accept(item.body) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 815, in accept return visitor.visit_block(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1202, in visit_block self.accept(s) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 974, in accept return visitor.visit_if_stmt(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1977, in visit_if_stmt if_map, else_map = self.find_isinstance_check(e) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 2559, in find_isinstance_check return find_isinstance_check(n, self.type_map) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 2810, in find_isinstance_check return conditional_type_map(expr, vartype, type) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 2613, in conditional_type_map and is_proper_subtype(current_type, proposed_type)): File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 569, in is_proper_subtype return left.accept(ProperSubtypeVisitor(right)) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/types.py", line 1114, in accept return visitor.visit_union_type(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 693, in visit_union_type return all([is_proper_subtype(item, self.right) for item in left.items]) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 693, in <listcomp> return all([is_proper_subtype(item, self.right) for item in left.items]) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 569, in is_proper_subtype return left.accept(ProperSubtypeVisitor(right)) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/types.py", line 900, in accept return visitor.visit_tuple_type(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 671, in visit_tuple_type if not is_proper_subtype(l, r): File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 569, in is_proper_subtype return left.accept(ProperSubtypeVisitor(right)) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/types.py", line 435, in accept return visitor.visit_instance(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 605, in visit_instance for base in left.type.mro: TypeError: 'NoneType' object is not iterable Deduction.py:103: note: use --pdb to drop into pdb
TypeError
def visit_func_def(self, fdef: FuncDef) -> None: self.errors.push_function(fdef.name()) self.analyze(fdef.type, fdef) super().visit_func_def(fdef) self.errors.pop_function()
def visit_func_def(self, fdef: FuncDef) -> None: self.errors.push_function(fdef.name()) self.analyze(fdef.type) super().visit_func_def(fdef) self.errors.pop_function()
https://github.com/python/mypy/issues/3836
mypy --show-traceback Deduction.py Deduction.py:102: error: The return type of "__init__" must be None Deduction.py:103: error: INTERNAL ERROR -- please report a bug at https://github.com/python/mypy/issues version: 0.521-858f7512cf3b4e39c0f4e8de5a13eee0e1e138fb-dirty Traceback (most recent call last): File "/usr/local/Cellar/mypy/0.521/libexec/bin/mypy", line 11, in <module> load_entry_point('mypy===0.521-858f7512cf3b4e39c0f4e8de5a13eee0e1e138fb-dirty', 'console_scripts', 'mypy')() File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/__main__.py", line 7, in console_entry main(None) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/main.py", line 50, in main res = type_check_only(sources, bin_dir, options) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/main.py", line 97, in type_check_only options=options) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 196, in build graph = dispatch(sources, manager) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 1801, in dispatch process_graph(graph, manager) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 2044, in process_graph process_stale_scc(graph, scc, manager) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 2147, in process_stale_scc graph[id].type_check_first_pass() File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 1716, in type_check_first_pass self.type_checker.check_first_pass() File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 185, in check_first_pass self.accept(d) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 754, in accept return visitor.visit_class_def(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1109, in visit_class_def self.accept(defn.defs) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 815, in accept return visitor.visit_block(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1202, in visit_block self.accept(s) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 565, in accept return visitor.visit_func_def(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 519, in visit_func_def self.check_func_item(defn, name=defn.name()) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 578, in check_func_item self.check_func_def(defn, typ, name) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 738, in check_func_def self.accept(item.body) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 815, in accept return visitor.visit_block(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1202, in visit_block self.accept(s) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 974, in accept return visitor.visit_if_stmt(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1977, in visit_if_stmt if_map, else_map = self.find_isinstance_check(e) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 2559, in find_isinstance_check return find_isinstance_check(n, self.type_map) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 2810, in find_isinstance_check return conditional_type_map(expr, vartype, type) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 2613, in conditional_type_map and is_proper_subtype(current_type, proposed_type)): File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 569, in is_proper_subtype return left.accept(ProperSubtypeVisitor(right)) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/types.py", line 1114, in accept return visitor.visit_union_type(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 693, in visit_union_type return all([is_proper_subtype(item, self.right) for item in left.items]) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 693, in <listcomp> return all([is_proper_subtype(item, self.right) for item in left.items]) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 569, in is_proper_subtype return left.accept(ProperSubtypeVisitor(right)) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/types.py", line 900, in accept return visitor.visit_tuple_type(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 671, in visit_tuple_type if not is_proper_subtype(l, r): File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 569, in is_proper_subtype return left.accept(ProperSubtypeVisitor(right)) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/types.py", line 435, in accept return visitor.visit_instance(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 605, in visit_instance for base in left.type.mro: TypeError: 'NoneType' object is not iterable Deduction.py:103: note: use --pdb to drop into pdb
TypeError
def visit_class_def(self, tdef: ClassDef) -> None: # NamedTuple base classes are validated in check_namedtuple_classdef; we don't have to # check them again here. if not tdef.info.is_named_tuple: types = list(tdef.info.bases) # type: List[Type] for tvar in tdef.type_vars: if tvar.upper_bound: types.append(tvar.upper_bound) if tvar.values: types.extend(tvar.values) self.analyze_types(types, tdef.info) for type in tdef.info.bases: if tdef.info.is_protocol: if not isinstance(type, Instance) or not type.type.is_protocol: if type.type.fullname() != "builtins.object": self.fail("All bases of a protocol must be protocols", tdef) # Recompute MRO now that we have analyzed all modules, to pick # up superclasses of bases imported from other modules in an # import loop. (Only do so if we succeeded the first time.) if tdef.info.mro: tdef.info.mro = [] # Force recomputation calculate_class_mro(tdef, self.fail_blocker) if tdef.info.is_protocol: add_protocol_members(tdef.info) if tdef.analyzed is not None: # Also check synthetic types associated with this ClassDef. # Currently these are TypedDict, and NamedTuple. if isinstance(tdef.analyzed, TypedDictExpr): self.analyze(tdef.analyzed.info.typeddict_type, tdef.analyzed, warn=True) elif isinstance(tdef.analyzed, NamedTupleExpr): self.analyze(tdef.analyzed.info.tuple_type, tdef.analyzed, warn=True) for name in tdef.analyzed.info.names: sym = tdef.analyzed.info.names[name] if isinstance(sym.node, (FuncDef, Decorator)): self.accept(sym.node) if isinstance(sym.node, Var): self.analyze(sym.node.type, sym.node) super().visit_class_def(tdef)
def visit_class_def(self, tdef: ClassDef) -> None: # NamedTuple base classes are validated in check_namedtuple_classdef; we don't have to # check them again here. if not tdef.info.is_named_tuple: for type in tdef.info.bases: self.analyze(type) if tdef.info.is_protocol: if not isinstance(type, Instance) or not type.type.is_protocol: if type.type.fullname() != "builtins.object": self.fail("All bases of a protocol must be protocols", tdef) # Recompute MRO now that we have analyzed all modules, to pick # up superclasses of bases imported from other modules in an # import loop. (Only do so if we succeeded the first time.) if tdef.info.mro: tdef.info.mro = [] # Force recomputation calculate_class_mro(tdef, self.fail_blocker) if tdef.info.is_protocol: add_protocol_members(tdef.info) if tdef.analyzed is not None: if isinstance(tdef.analyzed, TypedDictExpr): self.analyze(tdef.analyzed.info.typeddict_type) elif isinstance(tdef.analyzed, NamedTupleExpr): self.analyze(tdef.analyzed.info.tuple_type) super().visit_class_def(tdef)
https://github.com/python/mypy/issues/3836
mypy --show-traceback Deduction.py Deduction.py:102: error: The return type of "__init__" must be None Deduction.py:103: error: INTERNAL ERROR -- please report a bug at https://github.com/python/mypy/issues version: 0.521-858f7512cf3b4e39c0f4e8de5a13eee0e1e138fb-dirty Traceback (most recent call last): File "/usr/local/Cellar/mypy/0.521/libexec/bin/mypy", line 11, in <module> load_entry_point('mypy===0.521-858f7512cf3b4e39c0f4e8de5a13eee0e1e138fb-dirty', 'console_scripts', 'mypy')() File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/__main__.py", line 7, in console_entry main(None) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/main.py", line 50, in main res = type_check_only(sources, bin_dir, options) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/main.py", line 97, in type_check_only options=options) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 196, in build graph = dispatch(sources, manager) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 1801, in dispatch process_graph(graph, manager) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 2044, in process_graph process_stale_scc(graph, scc, manager) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 2147, in process_stale_scc graph[id].type_check_first_pass() File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 1716, in type_check_first_pass self.type_checker.check_first_pass() File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 185, in check_first_pass self.accept(d) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 754, in accept return visitor.visit_class_def(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1109, in visit_class_def self.accept(defn.defs) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 815, in accept return visitor.visit_block(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1202, in visit_block self.accept(s) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 565, in accept return visitor.visit_func_def(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 519, in visit_func_def self.check_func_item(defn, name=defn.name()) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 578, in check_func_item self.check_func_def(defn, typ, name) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 738, in check_func_def self.accept(item.body) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 815, in accept return visitor.visit_block(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1202, in visit_block self.accept(s) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 974, in accept return visitor.visit_if_stmt(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1977, in visit_if_stmt if_map, else_map = self.find_isinstance_check(e) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 2559, in find_isinstance_check return find_isinstance_check(n, self.type_map) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 2810, in find_isinstance_check return conditional_type_map(expr, vartype, type) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 2613, in conditional_type_map and is_proper_subtype(current_type, proposed_type)): File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 569, in is_proper_subtype return left.accept(ProperSubtypeVisitor(right)) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/types.py", line 1114, in accept return visitor.visit_union_type(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 693, in visit_union_type return all([is_proper_subtype(item, self.right) for item in left.items]) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 693, in <listcomp> return all([is_proper_subtype(item, self.right) for item in left.items]) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 569, in is_proper_subtype return left.accept(ProperSubtypeVisitor(right)) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/types.py", line 900, in accept return visitor.visit_tuple_type(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 671, in visit_tuple_type if not is_proper_subtype(l, r): File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 569, in is_proper_subtype return left.accept(ProperSubtypeVisitor(right)) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/types.py", line 435, in accept return visitor.visit_instance(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 605, in visit_instance for base in left.type.mro: TypeError: 'NoneType' object is not iterable Deduction.py:103: note: use --pdb to drop into pdb
TypeError
def visit_assignment_stmt(self, s: AssignmentStmt) -> None: """Traverse the assignment statement. This includes the actual assignment and synthetic types resulted from this assignment (if any). Currently this includes NewType, TypedDict, NamedTuple, and TypeVar. """ self.analyze(s.type, s) if isinstance(s.rvalue, IndexExpr) and isinstance(s.rvalue.analyzed, TypeAliasExpr): self.analyze(s.rvalue.analyzed.type, s.rvalue.analyzed, warn=True) if isinstance(s.rvalue, CallExpr): analyzed = s.rvalue.analyzed if isinstance(analyzed, NewTypeExpr): self.analyze(analyzed.old_type, analyzed) if analyzed.info and analyzed.info.mro: analyzed.info.mro = [] # Force recomputation calculate_class_mro(analyzed.info.defn, self.fail_blocker) if isinstance(analyzed, TypeVarExpr): types = [] if analyzed.upper_bound: types.append(analyzed.upper_bound) if analyzed.values: types.extend(analyzed.values) self.analyze_types(types, analyzed) if isinstance(analyzed, TypedDictExpr): self.analyze(analyzed.info.typeddict_type, analyzed, warn=True) if isinstance(analyzed, NamedTupleExpr): self.analyze(analyzed.info.tuple_type, analyzed, warn=True) for name in analyzed.info.names: sym = analyzed.info.names[name] if isinstance(sym.node, (FuncDef, Decorator)): self.accept(sym.node) if isinstance(sym.node, Var): self.analyze(sym.node.type, sym.node) # We need to pay additional attention to assignments that define a type alias. # The resulting type is also stored in the 'type_override' attribute of # the corresponding SymbolTableNode. if isinstance(s.lvalues[0], RefExpr) and isinstance(s.lvalues[0].node, Var): self.analyze(s.lvalues[0].node.type, s.lvalues[0].node) if isinstance(s.lvalues[0], NameExpr): node = self.sem.lookup(s.lvalues[0].name, s, suppress_errors=True) if node: self.analyze(node.type_override, node) super().visit_assignment_stmt(s)
def visit_assignment_stmt(self, s: AssignmentStmt) -> None: self.analyze(s.type) if isinstance(s.rvalue, IndexExpr) and isinstance(s.rvalue.analyzed, TypeAliasExpr): self.analyze(s.rvalue.analyzed.type) if isinstance(s.rvalue, CallExpr): if isinstance(s.rvalue.analyzed, NewTypeExpr): self.analyze(s.rvalue.analyzed.old_type) if isinstance(s.rvalue.analyzed, TypedDictExpr): self.analyze(s.rvalue.analyzed.info.typeddict_type) if isinstance(s.rvalue.analyzed, NamedTupleExpr): self.analyze(s.rvalue.analyzed.info.tuple_type) super().visit_assignment_stmt(s)
https://github.com/python/mypy/issues/3836
mypy --show-traceback Deduction.py Deduction.py:102: error: The return type of "__init__" must be None Deduction.py:103: error: INTERNAL ERROR -- please report a bug at https://github.com/python/mypy/issues version: 0.521-858f7512cf3b4e39c0f4e8de5a13eee0e1e138fb-dirty Traceback (most recent call last): File "/usr/local/Cellar/mypy/0.521/libexec/bin/mypy", line 11, in <module> load_entry_point('mypy===0.521-858f7512cf3b4e39c0f4e8de5a13eee0e1e138fb-dirty', 'console_scripts', 'mypy')() File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/__main__.py", line 7, in console_entry main(None) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/main.py", line 50, in main res = type_check_only(sources, bin_dir, options) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/main.py", line 97, in type_check_only options=options) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 196, in build graph = dispatch(sources, manager) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 1801, in dispatch process_graph(graph, manager) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 2044, in process_graph process_stale_scc(graph, scc, manager) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 2147, in process_stale_scc graph[id].type_check_first_pass() File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 1716, in type_check_first_pass self.type_checker.check_first_pass() File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 185, in check_first_pass self.accept(d) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 754, in accept return visitor.visit_class_def(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1109, in visit_class_def self.accept(defn.defs) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 815, in accept return visitor.visit_block(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1202, in visit_block self.accept(s) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 565, in accept return visitor.visit_func_def(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 519, in visit_func_def self.check_func_item(defn, name=defn.name()) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 578, in check_func_item self.check_func_def(defn, typ, name) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 738, in check_func_def self.accept(item.body) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 815, in accept return visitor.visit_block(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1202, in visit_block self.accept(s) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 974, in accept return visitor.visit_if_stmt(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1977, in visit_if_stmt if_map, else_map = self.find_isinstance_check(e) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 2559, in find_isinstance_check return find_isinstance_check(n, self.type_map) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 2810, in find_isinstance_check return conditional_type_map(expr, vartype, type) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 2613, in conditional_type_map and is_proper_subtype(current_type, proposed_type)): File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 569, in is_proper_subtype return left.accept(ProperSubtypeVisitor(right)) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/types.py", line 1114, in accept return visitor.visit_union_type(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 693, in visit_union_type return all([is_proper_subtype(item, self.right) for item in left.items]) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 693, in <listcomp> return all([is_proper_subtype(item, self.right) for item in left.items]) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 569, in is_proper_subtype return left.accept(ProperSubtypeVisitor(right)) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/types.py", line 900, in accept return visitor.visit_tuple_type(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 671, in visit_tuple_type if not is_proper_subtype(l, r): File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 569, in is_proper_subtype return left.accept(ProperSubtypeVisitor(right)) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/types.py", line 435, in accept return visitor.visit_instance(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 605, in visit_instance for base in left.type.mro: TypeError: 'NoneType' object is not iterable Deduction.py:103: note: use --pdb to drop into pdb
TypeError
def visit_cast_expr(self, e: CastExpr) -> None: self.analyze(e.type, e) super().visit_cast_expr(e)
def visit_cast_expr(self, e: CastExpr) -> None: self.analyze(e.type) super().visit_cast_expr(e)
https://github.com/python/mypy/issues/3836
mypy --show-traceback Deduction.py Deduction.py:102: error: The return type of "__init__" must be None Deduction.py:103: error: INTERNAL ERROR -- please report a bug at https://github.com/python/mypy/issues version: 0.521-858f7512cf3b4e39c0f4e8de5a13eee0e1e138fb-dirty Traceback (most recent call last): File "/usr/local/Cellar/mypy/0.521/libexec/bin/mypy", line 11, in <module> load_entry_point('mypy===0.521-858f7512cf3b4e39c0f4e8de5a13eee0e1e138fb-dirty', 'console_scripts', 'mypy')() File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/__main__.py", line 7, in console_entry main(None) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/main.py", line 50, in main res = type_check_only(sources, bin_dir, options) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/main.py", line 97, in type_check_only options=options) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 196, in build graph = dispatch(sources, manager) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 1801, in dispatch process_graph(graph, manager) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 2044, in process_graph process_stale_scc(graph, scc, manager) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 2147, in process_stale_scc graph[id].type_check_first_pass() File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 1716, in type_check_first_pass self.type_checker.check_first_pass() File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 185, in check_first_pass self.accept(d) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 754, in accept return visitor.visit_class_def(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1109, in visit_class_def self.accept(defn.defs) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 815, in accept return visitor.visit_block(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1202, in visit_block self.accept(s) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 565, in accept return visitor.visit_func_def(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 519, in visit_func_def self.check_func_item(defn, name=defn.name()) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 578, in check_func_item self.check_func_def(defn, typ, name) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 738, in check_func_def self.accept(item.body) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 815, in accept return visitor.visit_block(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1202, in visit_block self.accept(s) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 974, in accept return visitor.visit_if_stmt(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1977, in visit_if_stmt if_map, else_map = self.find_isinstance_check(e) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 2559, in find_isinstance_check return find_isinstance_check(n, self.type_map) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 2810, in find_isinstance_check return conditional_type_map(expr, vartype, type) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 2613, in conditional_type_map and is_proper_subtype(current_type, proposed_type)): File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 569, in is_proper_subtype return left.accept(ProperSubtypeVisitor(right)) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/types.py", line 1114, in accept return visitor.visit_union_type(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 693, in visit_union_type return all([is_proper_subtype(item, self.right) for item in left.items]) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 693, in <listcomp> return all([is_proper_subtype(item, self.right) for item in left.items]) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 569, in is_proper_subtype return left.accept(ProperSubtypeVisitor(right)) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/types.py", line 900, in accept return visitor.visit_tuple_type(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 671, in visit_tuple_type if not is_proper_subtype(l, r): File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 569, in is_proper_subtype return left.accept(ProperSubtypeVisitor(right)) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/types.py", line 435, in accept return visitor.visit_instance(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 605, in visit_instance for base in left.type.mro: TypeError: 'NoneType' object is not iterable Deduction.py:103: note: use --pdb to drop into pdb
TypeError
def visit_type_application(self, e: TypeApplication) -> None: for type in e.types: self.analyze(type, e) super().visit_type_application(e)
def visit_type_application(self, e: TypeApplication) -> None: for type in e.types: self.analyze(type) super().visit_type_application(e)
https://github.com/python/mypy/issues/3836
mypy --show-traceback Deduction.py Deduction.py:102: error: The return type of "__init__" must be None Deduction.py:103: error: INTERNAL ERROR -- please report a bug at https://github.com/python/mypy/issues version: 0.521-858f7512cf3b4e39c0f4e8de5a13eee0e1e138fb-dirty Traceback (most recent call last): File "/usr/local/Cellar/mypy/0.521/libexec/bin/mypy", line 11, in <module> load_entry_point('mypy===0.521-858f7512cf3b4e39c0f4e8de5a13eee0e1e138fb-dirty', 'console_scripts', 'mypy')() File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/__main__.py", line 7, in console_entry main(None) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/main.py", line 50, in main res = type_check_only(sources, bin_dir, options) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/main.py", line 97, in type_check_only options=options) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 196, in build graph = dispatch(sources, manager) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 1801, in dispatch process_graph(graph, manager) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 2044, in process_graph process_stale_scc(graph, scc, manager) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 2147, in process_stale_scc graph[id].type_check_first_pass() File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 1716, in type_check_first_pass self.type_checker.check_first_pass() File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 185, in check_first_pass self.accept(d) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 754, in accept return visitor.visit_class_def(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1109, in visit_class_def self.accept(defn.defs) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 815, in accept return visitor.visit_block(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1202, in visit_block self.accept(s) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 565, in accept return visitor.visit_func_def(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 519, in visit_func_def self.check_func_item(defn, name=defn.name()) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 578, in check_func_item self.check_func_def(defn, typ, name) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 738, in check_func_def self.accept(item.body) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 815, in accept return visitor.visit_block(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1202, in visit_block self.accept(s) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 974, in accept return visitor.visit_if_stmt(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1977, in visit_if_stmt if_map, else_map = self.find_isinstance_check(e) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 2559, in find_isinstance_check return find_isinstance_check(n, self.type_map) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 2810, in find_isinstance_check return conditional_type_map(expr, vartype, type) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 2613, in conditional_type_map and is_proper_subtype(current_type, proposed_type)): File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 569, in is_proper_subtype return left.accept(ProperSubtypeVisitor(right)) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/types.py", line 1114, in accept return visitor.visit_union_type(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 693, in visit_union_type return all([is_proper_subtype(item, self.right) for item in left.items]) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 693, in <listcomp> return all([is_proper_subtype(item, self.right) for item in left.items]) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 569, in is_proper_subtype return left.accept(ProperSubtypeVisitor(right)) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/types.py", line 900, in accept return visitor.visit_tuple_type(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 671, in visit_tuple_type if not is_proper_subtype(l, r): File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 569, in is_proper_subtype return left.accept(ProperSubtypeVisitor(right)) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/types.py", line 435, in accept return visitor.visit_instance(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 605, in visit_instance for base in left.type.mro: TypeError: 'NoneType' object is not iterable Deduction.py:103: note: use --pdb to drop into pdb
TypeError
def analyze( self, type: Optional[Type], node: Union[Node, SymbolTableNode], warn: bool = False ) -> None: # Recursive type warnings are only emitted on type definition 'node's, marked by 'warn' # Flags appeared during analysis of 'type' are collected in this dict. indicator = {} # type: Dict[str, bool] if type: analyzer = self.make_type_analyzer(indicator) type.accept(analyzer) self.check_for_omitted_generics(type) if indicator.get("forward") or indicator.get("synthetic"): def patch() -> None: self.perform_transform( node, lambda tp: tp.accept( ForwardReferenceResolver(self.fail, node, warn) ), ) self.patches.append(patch)
def analyze(self, type: Optional[Type]) -> None: if type: analyzer = TypeAnalyserPass3(self.fail, self.options, self.is_typeshed_file) type.accept(analyzer) self.check_for_omitted_generics(type)
https://github.com/python/mypy/issues/3836
mypy --show-traceback Deduction.py Deduction.py:102: error: The return type of "__init__" must be None Deduction.py:103: error: INTERNAL ERROR -- please report a bug at https://github.com/python/mypy/issues version: 0.521-858f7512cf3b4e39c0f4e8de5a13eee0e1e138fb-dirty Traceback (most recent call last): File "/usr/local/Cellar/mypy/0.521/libexec/bin/mypy", line 11, in <module> load_entry_point('mypy===0.521-858f7512cf3b4e39c0f4e8de5a13eee0e1e138fb-dirty', 'console_scripts', 'mypy')() File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/__main__.py", line 7, in console_entry main(None) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/main.py", line 50, in main res = type_check_only(sources, bin_dir, options) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/main.py", line 97, in type_check_only options=options) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 196, in build graph = dispatch(sources, manager) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 1801, in dispatch process_graph(graph, manager) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 2044, in process_graph process_stale_scc(graph, scc, manager) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 2147, in process_stale_scc graph[id].type_check_first_pass() File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 1716, in type_check_first_pass self.type_checker.check_first_pass() File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 185, in check_first_pass self.accept(d) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 754, in accept return visitor.visit_class_def(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1109, in visit_class_def self.accept(defn.defs) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 815, in accept return visitor.visit_block(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1202, in visit_block self.accept(s) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 565, in accept return visitor.visit_func_def(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 519, in visit_func_def self.check_func_item(defn, name=defn.name()) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 578, in check_func_item self.check_func_def(defn, typ, name) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 738, in check_func_def self.accept(item.body) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 815, in accept return visitor.visit_block(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1202, in visit_block self.accept(s) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 974, in accept return visitor.visit_if_stmt(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1977, in visit_if_stmt if_map, else_map = self.find_isinstance_check(e) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 2559, in find_isinstance_check return find_isinstance_check(n, self.type_map) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 2810, in find_isinstance_check return conditional_type_map(expr, vartype, type) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 2613, in conditional_type_map and is_proper_subtype(current_type, proposed_type)): File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 569, in is_proper_subtype return left.accept(ProperSubtypeVisitor(right)) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/types.py", line 1114, in accept return visitor.visit_union_type(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 693, in visit_union_type return all([is_proper_subtype(item, self.right) for item in left.items]) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 693, in <listcomp> return all([is_proper_subtype(item, self.right) for item in left.items]) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 569, in is_proper_subtype return left.accept(ProperSubtypeVisitor(right)) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/types.py", line 900, in accept return visitor.visit_tuple_type(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 671, in visit_tuple_type if not is_proper_subtype(l, r): File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 569, in is_proper_subtype return left.accept(ProperSubtypeVisitor(right)) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/types.py", line 435, in accept return visitor.visit_instance(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 605, in visit_instance for base in left.type.mro: TypeError: 'NoneType' object is not iterable Deduction.py:103: note: use --pdb to drop into pdb
TypeError
def analyze_types(self, types: List[Type], node: Node) -> None: # Similar to above but for nodes with multiple types. indicator = {} # type: Dict[str, bool] for type in types: analyzer = self.make_type_analyzer(indicator) type.accept(analyzer) self.check_for_omitted_generics(type) if indicator.get("forward") or indicator.get("synthetic"): def patch() -> None: self.perform_transform( node, lambda tp: tp.accept( ForwardReferenceResolver(self.fail, node, warn=False) ), ) self.patches.append(patch)
def analyze_types(self, items: List[Expression]) -> List[Type]: result = [] # type: List[Type] for node in items: try: result.append(self.anal_type(expr_to_unanalyzed_type(node))) except TypeTranslationError: self.fail("Type expected", node) result.append(AnyType(TypeOfAny.from_error)) return result
https://github.com/python/mypy/issues/3836
mypy --show-traceback Deduction.py Deduction.py:102: error: The return type of "__init__" must be None Deduction.py:103: error: INTERNAL ERROR -- please report a bug at https://github.com/python/mypy/issues version: 0.521-858f7512cf3b4e39c0f4e8de5a13eee0e1e138fb-dirty Traceback (most recent call last): File "/usr/local/Cellar/mypy/0.521/libexec/bin/mypy", line 11, in <module> load_entry_point('mypy===0.521-858f7512cf3b4e39c0f4e8de5a13eee0e1e138fb-dirty', 'console_scripts', 'mypy')() File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/__main__.py", line 7, in console_entry main(None) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/main.py", line 50, in main res = type_check_only(sources, bin_dir, options) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/main.py", line 97, in type_check_only options=options) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 196, in build graph = dispatch(sources, manager) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 1801, in dispatch process_graph(graph, manager) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 2044, in process_graph process_stale_scc(graph, scc, manager) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 2147, in process_stale_scc graph[id].type_check_first_pass() File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 1716, in type_check_first_pass self.type_checker.check_first_pass() File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 185, in check_first_pass self.accept(d) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 754, in accept return visitor.visit_class_def(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1109, in visit_class_def self.accept(defn.defs) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 815, in accept return visitor.visit_block(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1202, in visit_block self.accept(s) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 565, in accept return visitor.visit_func_def(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 519, in visit_func_def self.check_func_item(defn, name=defn.name()) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 578, in check_func_item self.check_func_def(defn, typ, name) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 738, in check_func_def self.accept(item.body) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 815, in accept return visitor.visit_block(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1202, in visit_block self.accept(s) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 974, in accept return visitor.visit_if_stmt(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1977, in visit_if_stmt if_map, else_map = self.find_isinstance_check(e) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 2559, in find_isinstance_check return find_isinstance_check(n, self.type_map) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 2810, in find_isinstance_check return conditional_type_map(expr, vartype, type) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 2613, in conditional_type_map and is_proper_subtype(current_type, proposed_type)): File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 569, in is_proper_subtype return left.accept(ProperSubtypeVisitor(right)) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/types.py", line 1114, in accept return visitor.visit_union_type(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 693, in visit_union_type return all([is_proper_subtype(item, self.right) for item in left.items]) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 693, in <listcomp> return all([is_proper_subtype(item, self.right) for item in left.items]) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 569, in is_proper_subtype return left.accept(ProperSubtypeVisitor(right)) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/types.py", line 900, in accept return visitor.visit_tuple_type(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 671, in visit_tuple_type if not is_proper_subtype(l, r): File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 569, in is_proper_subtype return left.accept(ProperSubtypeVisitor(right)) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/types.py", line 435, in accept return visitor.visit_instance(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 605, in visit_instance for base in left.type.mro: TypeError: 'NoneType' object is not iterable Deduction.py:103: note: use --pdb to drop into pdb
TypeError
def visit_for_stmt(self, s: ForStmt) -> None: self.analyze(s.index_type, s) super().visit_for_stmt(s)
def visit_for_stmt(self, s: ForStmt) -> None: if self.sem.is_module_scope(): self.analyze_lvalue(s.index, explicit_type=s.index_type is not None) s.body.accept(self) if s.else_body: s.else_body.accept(self)
https://github.com/python/mypy/issues/3836
mypy --show-traceback Deduction.py Deduction.py:102: error: The return type of "__init__" must be None Deduction.py:103: error: INTERNAL ERROR -- please report a bug at https://github.com/python/mypy/issues version: 0.521-858f7512cf3b4e39c0f4e8de5a13eee0e1e138fb-dirty Traceback (most recent call last): File "/usr/local/Cellar/mypy/0.521/libexec/bin/mypy", line 11, in <module> load_entry_point('mypy===0.521-858f7512cf3b4e39c0f4e8de5a13eee0e1e138fb-dirty', 'console_scripts', 'mypy')() File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/__main__.py", line 7, in console_entry main(None) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/main.py", line 50, in main res = type_check_only(sources, bin_dir, options) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/main.py", line 97, in type_check_only options=options) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 196, in build graph = dispatch(sources, manager) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 1801, in dispatch process_graph(graph, manager) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 2044, in process_graph process_stale_scc(graph, scc, manager) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 2147, in process_stale_scc graph[id].type_check_first_pass() File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 1716, in type_check_first_pass self.type_checker.check_first_pass() File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 185, in check_first_pass self.accept(d) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 754, in accept return visitor.visit_class_def(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1109, in visit_class_def self.accept(defn.defs) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 815, in accept return visitor.visit_block(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1202, in visit_block self.accept(s) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 565, in accept return visitor.visit_func_def(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 519, in visit_func_def self.check_func_item(defn, name=defn.name()) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 578, in check_func_item self.check_func_def(defn, typ, name) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 738, in check_func_def self.accept(item.body) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 815, in accept return visitor.visit_block(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1202, in visit_block self.accept(s) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 974, in accept return visitor.visit_if_stmt(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1977, in visit_if_stmt if_map, else_map = self.find_isinstance_check(e) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 2559, in find_isinstance_check return find_isinstance_check(n, self.type_map) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 2810, in find_isinstance_check return conditional_type_map(expr, vartype, type) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 2613, in conditional_type_map and is_proper_subtype(current_type, proposed_type)): File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 569, in is_proper_subtype return left.accept(ProperSubtypeVisitor(right)) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/types.py", line 1114, in accept return visitor.visit_union_type(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 693, in visit_union_type return all([is_proper_subtype(item, self.right) for item in left.items]) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 693, in <listcomp> return all([is_proper_subtype(item, self.right) for item in left.items]) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 569, in is_proper_subtype return left.accept(ProperSubtypeVisitor(right)) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/types.py", line 900, in accept return visitor.visit_tuple_type(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 671, in visit_tuple_type if not is_proper_subtype(l, r): File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 569, in is_proper_subtype return left.accept(ProperSubtypeVisitor(right)) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/types.py", line 435, in accept return visitor.visit_instance(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 605, in visit_instance for base in left.type.mro: TypeError: 'NoneType' object is not iterable Deduction.py:103: note: use --pdb to drop into pdb
TypeError
def visit_with_stmt(self, s: WithStmt) -> None: self.analyze(s.target_type, s) super().visit_with_stmt(s)
def visit_with_stmt(self, s: WithStmt) -> None: if self.sem.is_module_scope(): for n in s.target: if n: self.analyze_lvalue(n, explicit_type=s.target_type is not None) s.body.accept(self)
https://github.com/python/mypy/issues/3836
mypy --show-traceback Deduction.py Deduction.py:102: error: The return type of "__init__" must be None Deduction.py:103: error: INTERNAL ERROR -- please report a bug at https://github.com/python/mypy/issues version: 0.521-858f7512cf3b4e39c0f4e8de5a13eee0e1e138fb-dirty Traceback (most recent call last): File "/usr/local/Cellar/mypy/0.521/libexec/bin/mypy", line 11, in <module> load_entry_point('mypy===0.521-858f7512cf3b4e39c0f4e8de5a13eee0e1e138fb-dirty', 'console_scripts', 'mypy')() File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/__main__.py", line 7, in console_entry main(None) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/main.py", line 50, in main res = type_check_only(sources, bin_dir, options) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/main.py", line 97, in type_check_only options=options) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 196, in build graph = dispatch(sources, manager) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 1801, in dispatch process_graph(graph, manager) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 2044, in process_graph process_stale_scc(graph, scc, manager) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 2147, in process_stale_scc graph[id].type_check_first_pass() File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 1716, in type_check_first_pass self.type_checker.check_first_pass() File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 185, in check_first_pass self.accept(d) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 754, in accept return visitor.visit_class_def(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1109, in visit_class_def self.accept(defn.defs) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 815, in accept return visitor.visit_block(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1202, in visit_block self.accept(s) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 565, in accept return visitor.visit_func_def(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 519, in visit_func_def self.check_func_item(defn, name=defn.name()) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 578, in check_func_item self.check_func_def(defn, typ, name) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 738, in check_func_def self.accept(item.body) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 815, in accept return visitor.visit_block(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1202, in visit_block self.accept(s) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 974, in accept return visitor.visit_if_stmt(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1977, in visit_if_stmt if_map, else_map = self.find_isinstance_check(e) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 2559, in find_isinstance_check return find_isinstance_check(n, self.type_map) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 2810, in find_isinstance_check return conditional_type_map(expr, vartype, type) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 2613, in conditional_type_map and is_proper_subtype(current_type, proposed_type)): File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 569, in is_proper_subtype return left.accept(ProperSubtypeVisitor(right)) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/types.py", line 1114, in accept return visitor.visit_union_type(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 693, in visit_union_type return all([is_proper_subtype(item, self.right) for item in left.items]) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 693, in <listcomp> return all([is_proper_subtype(item, self.right) for item in left.items]) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 569, in is_proper_subtype return left.accept(ProperSubtypeVisitor(right)) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/types.py", line 900, in accept return visitor.visit_tuple_type(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 671, in visit_tuple_type if not is_proper_subtype(l, r): File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 569, in is_proper_subtype return left.accept(ProperSubtypeVisitor(right)) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/types.py", line 435, in accept return visitor.visit_instance(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 605, in visit_instance for base in left.type.mro: TypeError: 'NoneType' object is not iterable Deduction.py:103: note: use --pdb to drop into pdb
TypeError
def analyze_type_alias( node: Expression, lookup_func: Callable[[str, Context], SymbolTableNode], lookup_fqn_func: Callable[[str], SymbolTableNode], tvar_scope: TypeVarScope, fail_func: Callable[[str, Context], None], note_func: Callable[[str, Context], None], plugin: Plugin, options: Options, is_typeshed_stub: bool, allow_unnormalized: bool = False, in_dynamic_func: bool = False, global_scope: bool = True, ) -> Optional[Type]: """Return type if node is valid as a type alias rvalue. Return None otherwise. 'node' must have been semantically analyzed. """ # Quickly return None if the expression doesn't look like a type. Note # that we don't support straight string literals as type aliases # (only string literals within index expressions). if isinstance(node, RefExpr): # Note that this misses the case where someone tried to use a # class-referenced type variable as a type alias. It's easier to catch # that one in checkmember.py if node.kind == TVAR: fail_func( 'Type variable "{}" is invalid as target for type alias'.format( node.fullname ), node, ) return None if not ( isinstance(node.node, TypeInfo) or node.fullname == "typing.Any" or node.kind == TYPE_ALIAS ): return None elif isinstance(node, IndexExpr): base = node.base if isinstance(base, RefExpr): if not ( isinstance(base.node, TypeInfo) or base.fullname in type_constructors or base.kind == TYPE_ALIAS ): return None # Enums can't be generic, and without this check we may incorrectly interpret indexing # an Enum class as creating a type alias. if isinstance(base.node, TypeInfo) and base.node.is_enum: return None else: return None elif isinstance(node, CallExpr): if ( isinstance(node.callee, NameExpr) and len(node.args) == 1 and isinstance(node.args[0], NameExpr) ): call = lookup_func(node.callee.name, node.callee) arg = lookup_func(node.args[0].name, node.args[0]) if ( call is not None and call.node and call.node.fullname() == "builtins.type" and arg is not None and arg.node and arg.node.fullname() == "builtins.None" ): return NoneTyp() return None return None else: return None # It's a type alias (though it may be an invalid one). try: type = expr_to_unanalyzed_type(node) except TypeTranslationError: fail_func("Invalid type alias", node) return None analyzer = TypeAnalyser( lookup_func, lookup_fqn_func, tvar_scope, fail_func, note_func, plugin, options, is_typeshed_stub, aliasing=True, allow_unnormalized=allow_unnormalized, ) analyzer.in_dynamic_func = in_dynamic_func analyzer.global_scope = global_scope return type.accept(analyzer)
def analyze_type_alias( node: Expression, lookup_func: Callable[[str, Context], SymbolTableNode], lookup_fqn_func: Callable[[str], SymbolTableNode], tvar_scope: TypeVarScope, fail_func: Callable[[str, Context], None], plugin: Plugin, options: Options, is_typeshed_stub: bool, allow_unnormalized: bool = False, ) -> Optional[Type]: """Return type if node is valid as a type alias rvalue. Return None otherwise. 'node' must have been semantically analyzed. """ # Quickly return None if the expression doesn't look like a type. Note # that we don't support straight string literals as type aliases # (only string literals within index expressions). if isinstance(node, RefExpr): # Note that this misses the case where someone tried to use a # class-referenced type variable as a type alias. It's easier to catch # that one in checkmember.py if node.kind == TVAR: fail_func( 'Type variable "{}" is invalid as target for type alias'.format( node.fullname ), node, ) return None if not ( isinstance(node.node, TypeInfo) or node.fullname == "typing.Any" or node.kind == TYPE_ALIAS ): return None elif isinstance(node, IndexExpr): base = node.base if isinstance(base, RefExpr): if not ( isinstance(base.node, TypeInfo) or base.fullname in type_constructors or base.kind == TYPE_ALIAS ): return None # Enums can't be generic, and without this check we may incorrectly interpret indexing # an Enum class as creating a type alias. if isinstance(base.node, TypeInfo) and base.node.is_enum: return None else: return None elif isinstance(node, CallExpr): if ( isinstance(node.callee, NameExpr) and len(node.args) == 1 and isinstance(node.args[0], NameExpr) ): call = lookup_func(node.callee.name, node.callee) arg = lookup_func(node.args[0].name, node.args[0]) if ( call is not None and call.node and call.node.fullname() == "builtins.type" and arg is not None and arg.node and arg.node.fullname() == "builtins.None" ): return NoneTyp() return None return None else: return None # It's a type alias (though it may be an invalid one). try: type = expr_to_unanalyzed_type(node) except TypeTranslationError: fail_func("Invalid type alias", node) return None analyzer = TypeAnalyser( lookup_func, lookup_fqn_func, tvar_scope, fail_func, plugin, options, is_typeshed_stub, aliasing=True, allow_unnormalized=allow_unnormalized, ) return type.accept(analyzer)
https://github.com/python/mypy/issues/3836
mypy --show-traceback Deduction.py Deduction.py:102: error: The return type of "__init__" must be None Deduction.py:103: error: INTERNAL ERROR -- please report a bug at https://github.com/python/mypy/issues version: 0.521-858f7512cf3b4e39c0f4e8de5a13eee0e1e138fb-dirty Traceback (most recent call last): File "/usr/local/Cellar/mypy/0.521/libexec/bin/mypy", line 11, in <module> load_entry_point('mypy===0.521-858f7512cf3b4e39c0f4e8de5a13eee0e1e138fb-dirty', 'console_scripts', 'mypy')() File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/__main__.py", line 7, in console_entry main(None) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/main.py", line 50, in main res = type_check_only(sources, bin_dir, options) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/main.py", line 97, in type_check_only options=options) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 196, in build graph = dispatch(sources, manager) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 1801, in dispatch process_graph(graph, manager) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 2044, in process_graph process_stale_scc(graph, scc, manager) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 2147, in process_stale_scc graph[id].type_check_first_pass() File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 1716, in type_check_first_pass self.type_checker.check_first_pass() File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 185, in check_first_pass self.accept(d) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 754, in accept return visitor.visit_class_def(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1109, in visit_class_def self.accept(defn.defs) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 815, in accept return visitor.visit_block(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1202, in visit_block self.accept(s) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 565, in accept return visitor.visit_func_def(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 519, in visit_func_def self.check_func_item(defn, name=defn.name()) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 578, in check_func_item self.check_func_def(defn, typ, name) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 738, in check_func_def self.accept(item.body) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 815, in accept return visitor.visit_block(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1202, in visit_block self.accept(s) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 974, in accept return visitor.visit_if_stmt(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1977, in visit_if_stmt if_map, else_map = self.find_isinstance_check(e) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 2559, in find_isinstance_check return find_isinstance_check(n, self.type_map) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 2810, in find_isinstance_check return conditional_type_map(expr, vartype, type) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 2613, in conditional_type_map and is_proper_subtype(current_type, proposed_type)): File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 569, in is_proper_subtype return left.accept(ProperSubtypeVisitor(right)) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/types.py", line 1114, in accept return visitor.visit_union_type(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 693, in visit_union_type return all([is_proper_subtype(item, self.right) for item in left.items]) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 693, in <listcomp> return all([is_proper_subtype(item, self.right) for item in left.items]) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 569, in is_proper_subtype return left.accept(ProperSubtypeVisitor(right)) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/types.py", line 900, in accept return visitor.visit_tuple_type(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 671, in visit_tuple_type if not is_proper_subtype(l, r): File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 569, in is_proper_subtype return left.accept(ProperSubtypeVisitor(right)) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/types.py", line 435, in accept return visitor.visit_instance(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 605, in visit_instance for base in left.type.mro: TypeError: 'NoneType' object is not iterable Deduction.py:103: note: use --pdb to drop into pdb
TypeError
def __init__( self, lookup_func: Callable[[str, Context], SymbolTableNode], lookup_fqn_func: Callable[[str], SymbolTableNode], tvar_scope: Optional[TypeVarScope], fail_func: Callable[[str, Context], None], note_func: Callable[[str, Context], None], plugin: Plugin, options: Options, is_typeshed_stub: bool, *, aliasing: bool = False, allow_tuple_literal: bool = False, allow_unnormalized: bool = False, third_pass: bool = False, ) -> None: self.lookup = lookup_func self.lookup_fqn_func = lookup_fqn_func self.fail_func = fail_func self.note_func = note_func self.tvar_scope = tvar_scope self.aliasing = aliasing self.allow_tuple_literal = allow_tuple_literal # Positive if we are analyzing arguments of another (outer) type self.nesting_level = 0 self.allow_unnormalized = allow_unnormalized self.plugin = plugin self.options = options self.is_typeshed_stub = is_typeshed_stub self.third_pass = third_pass
def __init__( self, lookup_func: Callable[[str, Context], SymbolTableNode], lookup_fqn_func: Callable[[str], SymbolTableNode], tvar_scope: TypeVarScope, fail_func: Callable[[str, Context], None], plugin: Plugin, options: Options, is_typeshed_stub: bool, *, aliasing: bool = False, allow_tuple_literal: bool = False, allow_unnormalized: bool = False, ) -> None: self.lookup = lookup_func self.lookup_fqn_func = lookup_fqn_func self.fail_func = fail_func self.tvar_scope = tvar_scope self.aliasing = aliasing self.allow_tuple_literal = allow_tuple_literal # Positive if we are analyzing arguments of another (outer) type self.nesting_level = 0 self.allow_unnormalized = allow_unnormalized self.plugin = plugin self.options = options self.is_typeshed_stub = is_typeshed_stub
https://github.com/python/mypy/issues/3836
mypy --show-traceback Deduction.py Deduction.py:102: error: The return type of "__init__" must be None Deduction.py:103: error: INTERNAL ERROR -- please report a bug at https://github.com/python/mypy/issues version: 0.521-858f7512cf3b4e39c0f4e8de5a13eee0e1e138fb-dirty Traceback (most recent call last): File "/usr/local/Cellar/mypy/0.521/libexec/bin/mypy", line 11, in <module> load_entry_point('mypy===0.521-858f7512cf3b4e39c0f4e8de5a13eee0e1e138fb-dirty', 'console_scripts', 'mypy')() File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/__main__.py", line 7, in console_entry main(None) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/main.py", line 50, in main res = type_check_only(sources, bin_dir, options) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/main.py", line 97, in type_check_only options=options) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 196, in build graph = dispatch(sources, manager) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 1801, in dispatch process_graph(graph, manager) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 2044, in process_graph process_stale_scc(graph, scc, manager) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 2147, in process_stale_scc graph[id].type_check_first_pass() File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 1716, in type_check_first_pass self.type_checker.check_first_pass() File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 185, in check_first_pass self.accept(d) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 754, in accept return visitor.visit_class_def(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1109, in visit_class_def self.accept(defn.defs) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 815, in accept return visitor.visit_block(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1202, in visit_block self.accept(s) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 565, in accept return visitor.visit_func_def(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 519, in visit_func_def self.check_func_item(defn, name=defn.name()) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 578, in check_func_item self.check_func_def(defn, typ, name) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 738, in check_func_def self.accept(item.body) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 815, in accept return visitor.visit_block(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1202, in visit_block self.accept(s) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 974, in accept return visitor.visit_if_stmt(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1977, in visit_if_stmt if_map, else_map = self.find_isinstance_check(e) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 2559, in find_isinstance_check return find_isinstance_check(n, self.type_map) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 2810, in find_isinstance_check return conditional_type_map(expr, vartype, type) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 2613, in conditional_type_map and is_proper_subtype(current_type, proposed_type)): File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 569, in is_proper_subtype return left.accept(ProperSubtypeVisitor(right)) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/types.py", line 1114, in accept return visitor.visit_union_type(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 693, in visit_union_type return all([is_proper_subtype(item, self.right) for item in left.items]) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 693, in <listcomp> return all([is_proper_subtype(item, self.right) for item in left.items]) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 569, in is_proper_subtype return left.accept(ProperSubtypeVisitor(right)) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/types.py", line 900, in accept return visitor.visit_tuple_type(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 671, in visit_tuple_type if not is_proper_subtype(l, r): File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 569, in is_proper_subtype return left.accept(ProperSubtypeVisitor(right)) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/types.py", line 435, in accept return visitor.visit_instance(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 605, in visit_instance for base in left.type.mro: TypeError: 'NoneType' object is not iterable Deduction.py:103: note: use --pdb to drop into pdb
TypeError
def visit_unbound_type(self, t: UnboundType) -> Type: if t.optional: t.optional = False # We don't need to worry about double-wrapping Optionals or # wrapping Anys: Union simplification will take care of that. return make_optional_type(self.visit_unbound_type(t)) sym = self.lookup(t.name, t, suppress_errors=self.third_pass) # type: ignore if sym is not None: if sym.node is None: # UNBOUND_IMPORTED can happen if an unknown name was imported. if sym.kind != UNBOUND_IMPORTED: self.fail("Internal error (node is None, kind={})".format(sym.kind), t) return AnyType(TypeOfAny.special_form) fullname = sym.node.fullname() hook = self.plugin.get_type_analyze_hook(fullname) if hook: return hook(AnalyzeTypeContext(t, t, self)) if ( fullname in nongen_builtins and t.args and not sym.normalized and not self.allow_unnormalized ): self.fail(no_subscript_builtin_alias(fullname), t) if self.tvar_scope: tvar_def = self.tvar_scope.get_binding(sym) else: tvar_def = None if sym.kind == TVAR and tvar_def is not None: if len(t.args) > 0: self.fail('Type variable "{}" used with arguments'.format(t.name), t) return TypeVarType(tvar_def, t.line) elif fullname == "builtins.None": return NoneTyp() elif fullname == "typing.Any" or fullname == "builtins.Any": return AnyType(TypeOfAny.explicit) elif fullname == "typing.Tuple": if len(t.args) == 0 and not t.empty_tuple_index: # Bare 'Tuple' is same as 'tuple' if ( "generics" in self.options.disallow_any and not self.is_typeshed_stub ): self.fail(messages.BARE_GENERIC, t) typ = self.named_type("builtins.tuple", line=t.line, column=t.column) typ.from_generic_builtin = True return typ if len(t.args) == 2 and isinstance(t.args[1], EllipsisType): # Tuple[T, ...] (uniform, variable-length tuple) instance = self.named_type( "builtins.tuple", [self.anal_type(t.args[0])] ) instance.line = t.line return instance return self.tuple_type(self.anal_array(t.args)) elif fullname == "typing.Union": items = self.anal_array(t.args) return UnionType.make_union(items) elif fullname == "typing.Optional": if len(t.args) != 1: self.fail("Optional[...] must have exactly one type argument", t) return AnyType(TypeOfAny.from_error) item = self.anal_type(t.args[0]) return make_optional_type(item) elif fullname == "typing.Callable": return self.analyze_callable_type(t) elif fullname == "typing.Type": if len(t.args) == 0: any_type = AnyType( TypeOfAny.from_omitted_generics, line=t.line, column=t.column ) return TypeType(any_type, line=t.line, column=t.column) if len(t.args) != 1: self.fail("Type[...] must have exactly one type argument", t) item = self.anal_type(t.args[0]) return TypeType.make_normalized(item, line=t.line) elif fullname == "typing.ClassVar": if self.nesting_level > 0: self.fail("Invalid type: ClassVar nested inside other type", t) if len(t.args) == 0: return AnyType( TypeOfAny.from_omitted_generics, line=t.line, column=t.column ) if len(t.args) != 1: self.fail("ClassVar[...] must have at most one type argument", t) return AnyType(TypeOfAny.from_error) item = self.anal_type(t.args[0]) if isinstance(item, TypeVarType) or get_type_vars(item): self.fail("Invalid type: ClassVar cannot be generic", t) return AnyType(TypeOfAny.from_error) return item elif fullname in ("mypy_extensions.NoReturn", "typing.NoReturn"): return UninhabitedType(is_noreturn=True) elif sym.kind == TYPE_ALIAS: override = sym.type_override all_vars = sym.alias_tvars assert override is not None an_args = self.anal_array(t.args) if all_vars is not None: exp_len = len(all_vars) else: exp_len = 0 act_len = len(an_args) if exp_len > 0 and act_len == 0: # Interpret bare Alias same as normal generic, i.e., Alias[Any, Any, ...] assert all_vars is not None return set_any_tvars(override, all_vars, t.line, t.column) if exp_len == 0 and act_len == 0: return override if act_len != exp_len: self.fail( "Bad number of arguments for type alias, expected: %s, given: %s" % (exp_len, act_len), t, ) return set_any_tvars( override, all_vars or [], t.line, t.column, implicit=False ) assert all_vars is not None return replace_alias_tvars(override, all_vars, an_args, t.line, t.column) elif not isinstance(sym.node, TypeInfo): name = sym.fullname if name is None: name = sym.node.name() if isinstance(sym.node, Var) and isinstance(sym.node.type, AnyType): # Something with an Any type -- make it an alias for Any in a type # context. This is slightly problematic as it allows using the type 'Any' # as a base class -- however, this will fail soon at runtime so the problem # is pretty minor. return AnyType(TypeOfAny.from_unimported_type) # Allow unbound type variables when defining an alias if not ( self.aliasing and sym.kind == TVAR and (not self.tvar_scope or self.tvar_scope.get_binding(sym) is None) ): if ( not self.third_pass and not self.in_dynamic_func and not ( isinstance(sym.node, (FuncDef, Decorator)) or isinstance(sym.node, Var) and sym.node.is_ready ) and not (sym.kind == TVAR and tvar_def is None) ): if t.args and not self.global_scope: self.fail( 'Unsupported forward reference to "{}"'.format(t.name), t ) return AnyType(TypeOfAny.from_error) return ForwardRef(t) self.fail('Invalid type "{}"'.format(name), t) if self.third_pass and sym.kind == TVAR: self.note_func( "Forward references to type variables are prohibited", t ) return t info = sym.node # type: TypeInfo if len(t.args) > 0 and info.fullname() == "builtins.tuple": fallback = Instance(info, [AnyType(TypeOfAny.special_form)], t.line) return TupleType(self.anal_array(t.args), fallback, t.line) else: # Analyze arguments and construct Instance type. The # number of type arguments and their values are # checked only later, since we do not always know the # valid count at this point. Thus we may construct an # Instance with an invalid number of type arguments. instance = Instance(info, self.anal_array(t.args), t.line, t.column) instance.from_generic_builtin = sym.normalized tup = info.tuple_type if tup is not None: # The class has a Tuple[...] base class so it will be # represented as a tuple type. if t.args: self.fail("Generic tuple types not supported", t) return AnyType(TypeOfAny.from_error) return tup.copy_modified( items=self.anal_array(tup.items), fallback=instance ) td = info.typeddict_type if td is not None: # The class has a TypedDict[...] base class so it will be # represented as a typeddict type. if t.args: self.fail("Generic TypedDict types not supported", t) return AnyType(TypeOfAny.from_error) # Create a named TypedDictType return td.copy_modified( item_types=self.anal_array(list(td.items.values())), fallback=instance, ) return instance else: if self.third_pass: self.fail('Invalid type "{}"'.format(t.name), t) return AnyType(TypeOfAny.from_error) return AnyType(TypeOfAny.special_form)
def visit_unbound_type(self, t: UnboundType) -> Type: if t.optional: t.optional = False # We don't need to worry about double-wrapping Optionals or # wrapping Anys: Union simplification will take care of that. return make_optional_type(self.visit_unbound_type(t)) sym = self.lookup(t.name, t) if sym is not None: if sym.node is None: # UNBOUND_IMPORTED can happen if an unknown name was imported. if sym.kind != UNBOUND_IMPORTED: self.fail("Internal error (node is None, kind={})".format(sym.kind), t) return AnyType(TypeOfAny.special_form) fullname = sym.node.fullname() hook = self.plugin.get_type_analyze_hook(fullname) if hook: return hook(AnalyzeTypeContext(t, t, self)) if ( fullname in nongen_builtins and t.args and not sym.normalized and not self.allow_unnormalized ): self.fail(no_subscript_builtin_alias(fullname), t) tvar_def = self.tvar_scope.get_binding(sym) if sym.kind == TVAR and tvar_def is not None: if len(t.args) > 0: self.fail('Type variable "{}" used with arguments'.format(t.name), t) return TypeVarType(tvar_def, t.line) elif fullname == "builtins.None": return NoneTyp() elif fullname == "typing.Any" or fullname == "builtins.Any": return AnyType(TypeOfAny.explicit) elif fullname == "typing.Tuple": if len(t.args) == 0 and not t.empty_tuple_index: # Bare 'Tuple' is same as 'tuple' if ( "generics" in self.options.disallow_any and not self.is_typeshed_stub ): self.fail(messages.BARE_GENERIC, t) typ = self.named_type("builtins.tuple", line=t.line, column=t.column) typ.from_generic_builtin = True return typ if len(t.args) == 2 and isinstance(t.args[1], EllipsisType): # Tuple[T, ...] (uniform, variable-length tuple) instance = self.named_type( "builtins.tuple", [self.anal_type(t.args[0])] ) instance.line = t.line return instance return self.tuple_type(self.anal_array(t.args)) elif fullname == "typing.Union": items = self.anal_array(t.args) return UnionType.make_union(items) elif fullname == "typing.Optional": if len(t.args) != 1: self.fail("Optional[...] must have exactly one type argument", t) return AnyType(TypeOfAny.from_error) item = self.anal_type(t.args[0]) return make_optional_type(item) elif fullname == "typing.Callable": return self.analyze_callable_type(t) elif fullname == "typing.Type": if len(t.args) == 0: any_type = AnyType( TypeOfAny.from_omitted_generics, line=t.line, column=t.column ) return TypeType(any_type, line=t.line, column=t.column) if len(t.args) != 1: self.fail("Type[...] must have exactly one type argument", t) item = self.anal_type(t.args[0]) return TypeType.make_normalized(item, line=t.line) elif fullname == "typing.ClassVar": if self.nesting_level > 0: self.fail("Invalid type: ClassVar nested inside other type", t) if len(t.args) == 0: return AnyType( TypeOfAny.from_omitted_generics, line=t.line, column=t.column ) if len(t.args) != 1: self.fail("ClassVar[...] must have at most one type argument", t) return AnyType(TypeOfAny.from_error) item = self.anal_type(t.args[0]) if isinstance(item, TypeVarType) or get_type_vars(item): self.fail("Invalid type: ClassVar cannot be generic", t) return AnyType(TypeOfAny.from_error) return item elif fullname in ("mypy_extensions.NoReturn", "typing.NoReturn"): return UninhabitedType(is_noreturn=True) elif sym.kind == TYPE_ALIAS: override = sym.type_override all_vars = sym.alias_tvars assert override is not None an_args = self.anal_array(t.args) if all_vars is not None: exp_len = len(all_vars) else: exp_len = 0 act_len = len(an_args) if exp_len > 0 and act_len == 0: # Interpret bare Alias same as normal generic, i.e., Alias[Any, Any, ...] assert all_vars is not None return set_any_tvars(override, all_vars, t.line, t.column) if exp_len == 0 and act_len == 0: return override if act_len != exp_len: self.fail( "Bad number of arguments for type alias, expected: %s, given: %s" % (exp_len, act_len), t, ) return set_any_tvars( override, all_vars or [], t.line, t.column, implicit=False ) assert all_vars is not None return replace_alias_tvars(override, all_vars, an_args, t.line, t.column) elif not isinstance(sym.node, TypeInfo): name = sym.fullname if name is None: name = sym.node.name() if isinstance(sym.node, Var) and isinstance(sym.node.type, AnyType): # Something with an Any type -- make it an alias for Any in a type # context. This is slightly problematic as it allows using the type 'Any' # as a base class -- however, this will fail soon at runtime so the problem # is pretty minor. return AnyType(TypeOfAny.from_unimported_type) # Allow unbound type variables when defining an alias if not ( self.aliasing and sym.kind == TVAR and self.tvar_scope.get_binding(sym) is None ): self.fail('Invalid type "{}"'.format(name), t) return t info = sym.node # type: TypeInfo if len(t.args) > 0 and info.fullname() == "builtins.tuple": fallback = Instance(info, [AnyType(TypeOfAny.special_form)], t.line) return TupleType(self.anal_array(t.args), fallback, t.line) else: # Analyze arguments and construct Instance type. The # number of type arguments and their values are # checked only later, since we do not always know the # valid count at this point. Thus we may construct an # Instance with an invalid number of type arguments. instance = Instance(info, self.anal_array(t.args), t.line, t.column) instance.from_generic_builtin = sym.normalized tup = info.tuple_type if tup is not None: # The class has a Tuple[...] base class so it will be # represented as a tuple type. if t.args: self.fail("Generic tuple types not supported", t) return AnyType(TypeOfAny.from_error) return tup.copy_modified( items=self.anal_array(tup.items), fallback=instance ) td = info.typeddict_type if td is not None: # The class has a TypedDict[...] base class so it will be # represented as a typeddict type. if t.args: self.fail("Generic TypedDict types not supported", t) return AnyType(TypeOfAny.from_error) # Create a named TypedDictType return td.copy_modified( item_types=self.anal_array(list(td.items.values())), fallback=instance, ) return instance else: return AnyType(TypeOfAny.special_form)
https://github.com/python/mypy/issues/3836
mypy --show-traceback Deduction.py Deduction.py:102: error: The return type of "__init__" must be None Deduction.py:103: error: INTERNAL ERROR -- please report a bug at https://github.com/python/mypy/issues version: 0.521-858f7512cf3b4e39c0f4e8de5a13eee0e1e138fb-dirty Traceback (most recent call last): File "/usr/local/Cellar/mypy/0.521/libexec/bin/mypy", line 11, in <module> load_entry_point('mypy===0.521-858f7512cf3b4e39c0f4e8de5a13eee0e1e138fb-dirty', 'console_scripts', 'mypy')() File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/__main__.py", line 7, in console_entry main(None) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/main.py", line 50, in main res = type_check_only(sources, bin_dir, options) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/main.py", line 97, in type_check_only options=options) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 196, in build graph = dispatch(sources, manager) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 1801, in dispatch process_graph(graph, manager) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 2044, in process_graph process_stale_scc(graph, scc, manager) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 2147, in process_stale_scc graph[id].type_check_first_pass() File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 1716, in type_check_first_pass self.type_checker.check_first_pass() File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 185, in check_first_pass self.accept(d) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 754, in accept return visitor.visit_class_def(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1109, in visit_class_def self.accept(defn.defs) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 815, in accept return visitor.visit_block(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1202, in visit_block self.accept(s) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 565, in accept return visitor.visit_func_def(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 519, in visit_func_def self.check_func_item(defn, name=defn.name()) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 578, in check_func_item self.check_func_def(defn, typ, name) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 738, in check_func_def self.accept(item.body) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 815, in accept return visitor.visit_block(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1202, in visit_block self.accept(s) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 974, in accept return visitor.visit_if_stmt(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1977, in visit_if_stmt if_map, else_map = self.find_isinstance_check(e) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 2559, in find_isinstance_check return find_isinstance_check(n, self.type_map) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 2810, in find_isinstance_check return conditional_type_map(expr, vartype, type) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 2613, in conditional_type_map and is_proper_subtype(current_type, proposed_type)): File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 569, in is_proper_subtype return left.accept(ProperSubtypeVisitor(right)) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/types.py", line 1114, in accept return visitor.visit_union_type(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 693, in visit_union_type return all([is_proper_subtype(item, self.right) for item in left.items]) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 693, in <listcomp> return all([is_proper_subtype(item, self.right) for item in left.items]) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 569, in is_proper_subtype return left.accept(ProperSubtypeVisitor(right)) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/types.py", line 900, in accept return visitor.visit_tuple_type(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 671, in visit_tuple_type if not is_proper_subtype(l, r): File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 569, in is_proper_subtype return left.accept(ProperSubtypeVisitor(right)) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/types.py", line 435, in accept return visitor.visit_instance(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 605, in visit_instance for base in left.type.mro: TypeError: 'NoneType' object is not iterable Deduction.py:103: note: use --pdb to drop into pdb
TypeError
def tvar_scope_frame(self) -> Iterator[None]: old_scope = self.tvar_scope if self.tvar_scope: self.tvar_scope = self.tvar_scope.method_frame() else: assert self.third_pass, "Internal error: type variable scope not given" yield self.tvar_scope = old_scope
def tvar_scope_frame(self) -> Iterator[None]: old_scope = self.tvar_scope self.tvar_scope = self.tvar_scope.method_frame() yield self.tvar_scope = old_scope
https://github.com/python/mypy/issues/3836
mypy --show-traceback Deduction.py Deduction.py:102: error: The return type of "__init__" must be None Deduction.py:103: error: INTERNAL ERROR -- please report a bug at https://github.com/python/mypy/issues version: 0.521-858f7512cf3b4e39c0f4e8de5a13eee0e1e138fb-dirty Traceback (most recent call last): File "/usr/local/Cellar/mypy/0.521/libexec/bin/mypy", line 11, in <module> load_entry_point('mypy===0.521-858f7512cf3b4e39c0f4e8de5a13eee0e1e138fb-dirty', 'console_scripts', 'mypy')() File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/__main__.py", line 7, in console_entry main(None) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/main.py", line 50, in main res = type_check_only(sources, bin_dir, options) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/main.py", line 97, in type_check_only options=options) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 196, in build graph = dispatch(sources, manager) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 1801, in dispatch process_graph(graph, manager) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 2044, in process_graph process_stale_scc(graph, scc, manager) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 2147, in process_stale_scc graph[id].type_check_first_pass() File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 1716, in type_check_first_pass self.type_checker.check_first_pass() File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 185, in check_first_pass self.accept(d) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 754, in accept return visitor.visit_class_def(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1109, in visit_class_def self.accept(defn.defs) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 815, in accept return visitor.visit_block(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1202, in visit_block self.accept(s) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 565, in accept return visitor.visit_func_def(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 519, in visit_func_def self.check_func_item(defn, name=defn.name()) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 578, in check_func_item self.check_func_def(defn, typ, name) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 738, in check_func_def self.accept(item.body) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 815, in accept return visitor.visit_block(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1202, in visit_block self.accept(s) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 974, in accept return visitor.visit_if_stmt(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1977, in visit_if_stmt if_map, else_map = self.find_isinstance_check(e) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 2559, in find_isinstance_check return find_isinstance_check(n, self.type_map) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 2810, in find_isinstance_check return conditional_type_map(expr, vartype, type) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 2613, in conditional_type_map and is_proper_subtype(current_type, proposed_type)): File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 569, in is_proper_subtype return left.accept(ProperSubtypeVisitor(right)) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/types.py", line 1114, in accept return visitor.visit_union_type(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 693, in visit_union_type return all([is_proper_subtype(item, self.right) for item in left.items]) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 693, in <listcomp> return all([is_proper_subtype(item, self.right) for item in left.items]) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 569, in is_proper_subtype return left.accept(ProperSubtypeVisitor(right)) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/types.py", line 900, in accept return visitor.visit_tuple_type(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 671, in visit_tuple_type if not is_proper_subtype(l, r): File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 569, in is_proper_subtype return left.accept(ProperSubtypeVisitor(right)) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/types.py", line 435, in accept return visitor.visit_instance(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 605, in visit_instance for base in left.type.mro: TypeError: 'NoneType' object is not iterable Deduction.py:103: note: use --pdb to drop into pdb
TypeError
def infer_type_variables(self, type: CallableType) -> List[Tuple[str, TypeVarExpr]]: """Return list of unique type variables referred to in a callable.""" if not self.tvar_scope: return [] # We are in third pass, nothing new here names = [] # type: List[str] tvars = [] # type: List[TypeVarExpr] for arg in type.arg_types: for name, tvar_expr in arg.accept( TypeVariableQuery(self.lookup, self.tvar_scope) ): if name not in names: names.append(name) tvars.append(tvar_expr) # When finding type variables in the return type of a function, don't # look inside Callable types. Type variables only appearing in # functions in the return type belong to those functions, not the # function we're currently analyzing. for name, tvar_expr in type.ret_type.accept( TypeVariableQuery(self.lookup, self.tvar_scope, include_callables=False) ): if name not in names: names.append(name) tvars.append(tvar_expr) return list(zip(names, tvars))
def infer_type_variables(self, type: CallableType) -> List[Tuple[str, TypeVarExpr]]: """Return list of unique type variables referred to in a callable.""" names = [] # type: List[str] tvars = [] # type: List[TypeVarExpr] for arg in type.arg_types: for name, tvar_expr in arg.accept( TypeVariableQuery(self.lookup, self.tvar_scope) ): if name not in names: names.append(name) tvars.append(tvar_expr) # When finding type variables in the return type of a function, don't # look inside Callable types. Type variables only appearing in # functions in the return type belong to those functions, not the # function we're currently analyzing. for name, tvar_expr in type.ret_type.accept( TypeVariableQuery(self.lookup, self.tvar_scope, include_callables=False) ): if name not in names: names.append(name) tvars.append(tvar_expr) return list(zip(names, tvars))
https://github.com/python/mypy/issues/3836
mypy --show-traceback Deduction.py Deduction.py:102: error: The return type of "__init__" must be None Deduction.py:103: error: INTERNAL ERROR -- please report a bug at https://github.com/python/mypy/issues version: 0.521-858f7512cf3b4e39c0f4e8de5a13eee0e1e138fb-dirty Traceback (most recent call last): File "/usr/local/Cellar/mypy/0.521/libexec/bin/mypy", line 11, in <module> load_entry_point('mypy===0.521-858f7512cf3b4e39c0f4e8de5a13eee0e1e138fb-dirty', 'console_scripts', 'mypy')() File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/__main__.py", line 7, in console_entry main(None) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/main.py", line 50, in main res = type_check_only(sources, bin_dir, options) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/main.py", line 97, in type_check_only options=options) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 196, in build graph = dispatch(sources, manager) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 1801, in dispatch process_graph(graph, manager) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 2044, in process_graph process_stale_scc(graph, scc, manager) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 2147, in process_stale_scc graph[id].type_check_first_pass() File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 1716, in type_check_first_pass self.type_checker.check_first_pass() File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 185, in check_first_pass self.accept(d) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 754, in accept return visitor.visit_class_def(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1109, in visit_class_def self.accept(defn.defs) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 815, in accept return visitor.visit_block(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1202, in visit_block self.accept(s) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 565, in accept return visitor.visit_func_def(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 519, in visit_func_def self.check_func_item(defn, name=defn.name()) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 578, in check_func_item self.check_func_def(defn, typ, name) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 738, in check_func_def self.accept(item.body) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 815, in accept return visitor.visit_block(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1202, in visit_block self.accept(s) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 974, in accept return visitor.visit_if_stmt(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1977, in visit_if_stmt if_map, else_map = self.find_isinstance_check(e) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 2559, in find_isinstance_check return find_isinstance_check(n, self.type_map) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 2810, in find_isinstance_check return conditional_type_map(expr, vartype, type) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 2613, in conditional_type_map and is_proper_subtype(current_type, proposed_type)): File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 569, in is_proper_subtype return left.accept(ProperSubtypeVisitor(right)) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/types.py", line 1114, in accept return visitor.visit_union_type(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 693, in visit_union_type return all([is_proper_subtype(item, self.right) for item in left.items]) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 693, in <listcomp> return all([is_proper_subtype(item, self.right) for item in left.items]) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 569, in is_proper_subtype return left.accept(ProperSubtypeVisitor(right)) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/types.py", line 900, in accept return visitor.visit_tuple_type(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 671, in visit_tuple_type if not is_proper_subtype(l, r): File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 569, in is_proper_subtype return left.accept(ProperSubtypeVisitor(right)) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/types.py", line 435, in accept return visitor.visit_instance(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 605, in visit_instance for base in left.type.mro: TypeError: 'NoneType' object is not iterable Deduction.py:103: note: use --pdb to drop into pdb
TypeError
def bind_function_type_variables( self, fun_type: CallableType, defn: Context ) -> List[TypeVarDef]: """Find the type variables of the function type and bind them in our tvar_scope""" if not self.tvar_scope: return [] # We are in third pass, nothing new here if fun_type.variables: for var in fun_type.variables: var_expr = self.lookup(var.name, var).node assert isinstance(var_expr, TypeVarExpr) self.tvar_scope.bind(var.name, var_expr) return fun_type.variables typevars = self.infer_type_variables(fun_type) # Do not define a new type variable if already defined in scope. typevars = [ (name, tvar) for name, tvar in typevars if not self.is_defined_type_var(name, defn) ] defs = [] # type: List[TypeVarDef] for name, tvar in typevars: if not self.tvar_scope.allow_binding(tvar.fullname()): self.fail( "Type variable '{}' is bound by an outer class".format(name), defn ) self.tvar_scope.bind(name, tvar) binding = self.tvar_scope.get_binding(tvar.fullname()) assert binding is not None defs.append(binding) return defs
def bind_function_type_variables( self, fun_type: CallableType, defn: Context ) -> List[TypeVarDef]: """Find the type variables of the function type and bind them in our tvar_scope""" if fun_type.variables: for var in fun_type.variables: var_expr = self.lookup(var.name, var).node assert isinstance(var_expr, TypeVarExpr) self.tvar_scope.bind(var.name, var_expr) return fun_type.variables typevars = self.infer_type_variables(fun_type) # Do not define a new type variable if already defined in scope. typevars = [ (name, tvar) for name, tvar in typevars if not self.is_defined_type_var(name, defn) ] defs = [] # type: List[TypeVarDef] for name, tvar in typevars: if not self.tvar_scope.allow_binding(tvar.fullname()): self.fail( "Type variable '{}' is bound by an outer class".format(name), defn ) self.tvar_scope.bind(name, tvar) binding = self.tvar_scope.get_binding(tvar.fullname()) assert binding is not None defs.append(binding) return defs
https://github.com/python/mypy/issues/3836
mypy --show-traceback Deduction.py Deduction.py:102: error: The return type of "__init__" must be None Deduction.py:103: error: INTERNAL ERROR -- please report a bug at https://github.com/python/mypy/issues version: 0.521-858f7512cf3b4e39c0f4e8de5a13eee0e1e138fb-dirty Traceback (most recent call last): File "/usr/local/Cellar/mypy/0.521/libexec/bin/mypy", line 11, in <module> load_entry_point('mypy===0.521-858f7512cf3b4e39c0f4e8de5a13eee0e1e138fb-dirty', 'console_scripts', 'mypy')() File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/__main__.py", line 7, in console_entry main(None) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/main.py", line 50, in main res = type_check_only(sources, bin_dir, options) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/main.py", line 97, in type_check_only options=options) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 196, in build graph = dispatch(sources, manager) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 1801, in dispatch process_graph(graph, manager) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 2044, in process_graph process_stale_scc(graph, scc, manager) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 2147, in process_stale_scc graph[id].type_check_first_pass() File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 1716, in type_check_first_pass self.type_checker.check_first_pass() File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 185, in check_first_pass self.accept(d) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 754, in accept return visitor.visit_class_def(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1109, in visit_class_def self.accept(defn.defs) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 815, in accept return visitor.visit_block(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1202, in visit_block self.accept(s) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 565, in accept return visitor.visit_func_def(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 519, in visit_func_def self.check_func_item(defn, name=defn.name()) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 578, in check_func_item self.check_func_def(defn, typ, name) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 738, in check_func_def self.accept(item.body) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 815, in accept return visitor.visit_block(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1202, in visit_block self.accept(s) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 974, in accept return visitor.visit_if_stmt(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1977, in visit_if_stmt if_map, else_map = self.find_isinstance_check(e) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 2559, in find_isinstance_check return find_isinstance_check(n, self.type_map) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 2810, in find_isinstance_check return conditional_type_map(expr, vartype, type) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 2613, in conditional_type_map and is_proper_subtype(current_type, proposed_type)): File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 569, in is_proper_subtype return left.accept(ProperSubtypeVisitor(right)) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/types.py", line 1114, in accept return visitor.visit_union_type(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 693, in visit_union_type return all([is_proper_subtype(item, self.right) for item in left.items]) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 693, in <listcomp> return all([is_proper_subtype(item, self.right) for item in left.items]) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 569, in is_proper_subtype return left.accept(ProperSubtypeVisitor(right)) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/types.py", line 900, in accept return visitor.visit_tuple_type(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 671, in visit_tuple_type if not is_proper_subtype(l, r): File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 569, in is_proper_subtype return left.accept(ProperSubtypeVisitor(right)) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/types.py", line 435, in accept return visitor.visit_instance(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 605, in visit_instance for base in left.type.mro: TypeError: 'NoneType' object is not iterable Deduction.py:103: note: use --pdb to drop into pdb
TypeError
def is_defined_type_var(self, tvar: str, context: Context) -> bool: return ( self.tvar_scope is not None and self.tvar_scope.get_binding(self.lookup(tvar, context)) is not None )
def is_defined_type_var(self, tvar: str, context: Context) -> bool: return self.tvar_scope.get_binding(self.lookup(tvar, context)) is not None
https://github.com/python/mypy/issues/3836
mypy --show-traceback Deduction.py Deduction.py:102: error: The return type of "__init__" must be None Deduction.py:103: error: INTERNAL ERROR -- please report a bug at https://github.com/python/mypy/issues version: 0.521-858f7512cf3b4e39c0f4e8de5a13eee0e1e138fb-dirty Traceback (most recent call last): File "/usr/local/Cellar/mypy/0.521/libexec/bin/mypy", line 11, in <module> load_entry_point('mypy===0.521-858f7512cf3b4e39c0f4e8de5a13eee0e1e138fb-dirty', 'console_scripts', 'mypy')() File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/__main__.py", line 7, in console_entry main(None) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/main.py", line 50, in main res = type_check_only(sources, bin_dir, options) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/main.py", line 97, in type_check_only options=options) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 196, in build graph = dispatch(sources, manager) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 1801, in dispatch process_graph(graph, manager) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 2044, in process_graph process_stale_scc(graph, scc, manager) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 2147, in process_stale_scc graph[id].type_check_first_pass() File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 1716, in type_check_first_pass self.type_checker.check_first_pass() File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 185, in check_first_pass self.accept(d) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 754, in accept return visitor.visit_class_def(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1109, in visit_class_def self.accept(defn.defs) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 815, in accept return visitor.visit_block(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1202, in visit_block self.accept(s) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 565, in accept return visitor.visit_func_def(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 519, in visit_func_def self.check_func_item(defn, name=defn.name()) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 578, in check_func_item self.check_func_def(defn, typ, name) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 738, in check_func_def self.accept(item.body) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 815, in accept return visitor.visit_block(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1202, in visit_block self.accept(s) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 974, in accept return visitor.visit_if_stmt(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1977, in visit_if_stmt if_map, else_map = self.find_isinstance_check(e) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 2559, in find_isinstance_check return find_isinstance_check(n, self.type_map) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 2810, in find_isinstance_check return conditional_type_map(expr, vartype, type) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 2613, in conditional_type_map and is_proper_subtype(current_type, proposed_type)): File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 569, in is_proper_subtype return left.accept(ProperSubtypeVisitor(right)) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/types.py", line 1114, in accept return visitor.visit_union_type(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 693, in visit_union_type return all([is_proper_subtype(item, self.right) for item in left.items]) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 693, in <listcomp> return all([is_proper_subtype(item, self.right) for item in left.items]) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 569, in is_proper_subtype return left.accept(ProperSubtypeVisitor(right)) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/types.py", line 900, in accept return visitor.visit_tuple_type(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 671, in visit_tuple_type if not is_proper_subtype(l, r): File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 569, in is_proper_subtype return left.accept(ProperSubtypeVisitor(right)) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/types.py", line 435, in accept return visitor.visit_instance(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 605, in visit_instance for base in left.type.mro: TypeError: 'NoneType' object is not iterable Deduction.py:103: note: use --pdb to drop into pdb
TypeError
def __init__( self, lookup_func: Callable[[str, Context], SymbolTableNode], lookup_fqn_func: Callable[[str], SymbolTableNode], fail_func: Callable[[str, Context], None], note_func: Callable[[str, Context], None], plugin: Plugin, options: Options, is_typeshed_stub: bool, indicator: Dict[str, bool], ) -> None: self.lookup_func = lookup_func self.lookup_fqn_func = lookup_fqn_func self.fail = fail_func self.note_func = note_func self.options = options self.plugin = plugin self.is_typeshed_stub = is_typeshed_stub self.indicator = indicator
def __init__( self, fail_func: Callable[[str, Context], None], options: Options, is_typeshed_stub: bool, ) -> None: self.fail = fail_func self.options = options self.is_typeshed_stub = is_typeshed_stub
https://github.com/python/mypy/issues/3836
mypy --show-traceback Deduction.py Deduction.py:102: error: The return type of "__init__" must be None Deduction.py:103: error: INTERNAL ERROR -- please report a bug at https://github.com/python/mypy/issues version: 0.521-858f7512cf3b4e39c0f4e8de5a13eee0e1e138fb-dirty Traceback (most recent call last): File "/usr/local/Cellar/mypy/0.521/libexec/bin/mypy", line 11, in <module> load_entry_point('mypy===0.521-858f7512cf3b4e39c0f4e8de5a13eee0e1e138fb-dirty', 'console_scripts', 'mypy')() File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/__main__.py", line 7, in console_entry main(None) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/main.py", line 50, in main res = type_check_only(sources, bin_dir, options) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/main.py", line 97, in type_check_only options=options) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 196, in build graph = dispatch(sources, manager) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 1801, in dispatch process_graph(graph, manager) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 2044, in process_graph process_stale_scc(graph, scc, manager) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 2147, in process_stale_scc graph[id].type_check_first_pass() File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 1716, in type_check_first_pass self.type_checker.check_first_pass() File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 185, in check_first_pass self.accept(d) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 754, in accept return visitor.visit_class_def(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1109, in visit_class_def self.accept(defn.defs) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 815, in accept return visitor.visit_block(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1202, in visit_block self.accept(s) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 565, in accept return visitor.visit_func_def(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 519, in visit_func_def self.check_func_item(defn, name=defn.name()) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 578, in check_func_item self.check_func_def(defn, typ, name) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 738, in check_func_def self.accept(item.body) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 815, in accept return visitor.visit_block(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1202, in visit_block self.accept(s) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 974, in accept return visitor.visit_if_stmt(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1977, in visit_if_stmt if_map, else_map = self.find_isinstance_check(e) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 2559, in find_isinstance_check return find_isinstance_check(n, self.type_map) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 2810, in find_isinstance_check return conditional_type_map(expr, vartype, type) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 2613, in conditional_type_map and is_proper_subtype(current_type, proposed_type)): File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 569, in is_proper_subtype return left.accept(ProperSubtypeVisitor(right)) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/types.py", line 1114, in accept return visitor.visit_union_type(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 693, in visit_union_type return all([is_proper_subtype(item, self.right) for item in left.items]) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 693, in <listcomp> return all([is_proper_subtype(item, self.right) for item in left.items]) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 569, in is_proper_subtype return left.accept(ProperSubtypeVisitor(right)) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/types.py", line 900, in accept return visitor.visit_tuple_type(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 671, in visit_tuple_type if not is_proper_subtype(l, r): File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 569, in is_proper_subtype return left.accept(ProperSubtypeVisitor(right)) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/types.py", line 435, in accept return visitor.visit_instance(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 605, in visit_instance for base in left.type.mro: TypeError: 'NoneType' object is not iterable Deduction.py:103: note: use --pdb to drop into pdb
TypeError
def visit_instance(self, t: Instance) -> None: info = t.type if info.replaced or info.tuple_type: self.indicator["synthetic"] = True # Check type argument count. if len(t.args) != len(info.type_vars): if len(t.args) == 0: from_builtins = ( t.type.fullname() in nongen_builtins and not t.from_generic_builtin ) if ( "generics" in self.options.disallow_any and not self.is_typeshed_stub and from_builtins ): alternative = nongen_builtins[t.type.fullname()] self.fail(messages.IMPLICIT_GENERIC_ANY_BUILTIN.format(alternative), t) # Insert implicit 'Any' type arguments. if from_builtins: # this 'Any' was already reported elsewhere any_type = AnyType(TypeOfAny.special_form, line=t.line, column=t.column) else: any_type = AnyType( TypeOfAny.from_omitted_generics, line=t.line, column=t.column ) t.args = [any_type] * len(info.type_vars) return # Invalid number of type parameters. n = len(info.type_vars) s = "{} type arguments".format(n) if n == 0: s = "no type arguments" elif n == 1: s = "1 type argument" act = str(len(t.args)) if act == "0": act = "none" self.fail('"{}" expects {}, but {} given'.format(info.name(), s, act), t) # Construct the correct number of type arguments, as # otherwise the type checker may crash as it expects # things to be right. t.args = [AnyType(TypeOfAny.from_error) for _ in info.type_vars] t.invalid = True elif info.defn.type_vars: # Check type argument values. # TODO: Calling is_subtype and is_same_types in semantic analysis is a bad idea for (i, arg), tvar in zip(enumerate(t.args), info.defn.type_vars): if tvar.values: if isinstance(arg, TypeVarType): arg_values = arg.values if not arg_values: self.fail( 'Type variable "{}" not valid as type ' 'argument value for "{}"'.format(arg.name, info.name()), t, ) continue else: arg_values = [arg] self.check_type_var_values( info, arg_values, tvar.name, tvar.values, i + 1, t ) # TODO: These hacks will be not necessary when this will be moved to later stage. arg = self.update_type(arg) bound = self.update_type(tvar.upper_bound) if not is_subtype(arg, bound): self.fail( 'Type argument "{}" of "{}" must be a subtype of "{}"'.format( arg, info.name(), bound ), t, ) for arg in t.args: arg.accept(self) if info.is_newtype: for base in info.bases: base.accept(self)
def visit_instance(self, t: Instance) -> None: info = t.type # Check type argument count. if len(t.args) != len(info.type_vars): if len(t.args) == 0: from_builtins = ( t.type.fullname() in nongen_builtins and not t.from_generic_builtin ) if ( "generics" in self.options.disallow_any and not self.is_typeshed_stub and from_builtins ): alternative = nongen_builtins[t.type.fullname()] self.fail(messages.IMPLICIT_GENERIC_ANY_BUILTIN.format(alternative), t) # Insert implicit 'Any' type arguments. if from_builtins: # this 'Any' was already reported elsewhere any_type = AnyType(TypeOfAny.special_form, line=t.line, column=t.column) else: any_type = AnyType( TypeOfAny.from_omitted_generics, line=t.line, column=t.column ) t.args = [any_type] * len(info.type_vars) return # Invalid number of type parameters. n = len(info.type_vars) s = "{} type arguments".format(n) if n == 0: s = "no type arguments" elif n == 1: s = "1 type argument" act = str(len(t.args)) if act == "0": act = "none" self.fail('"{}" expects {}, but {} given'.format(info.name(), s, act), t) # Construct the correct number of type arguments, as # otherwise the type checker may crash as it expects # things to be right. t.args = [AnyType(TypeOfAny.from_error) for _ in info.type_vars] t.invalid = True elif info.defn.type_vars: # Check type argument values. for (i, arg), tvar in zip(enumerate(t.args), info.defn.type_vars): if tvar.values: if isinstance(arg, TypeVarType): arg_values = arg.values if not arg_values: self.fail( 'Type variable "{}" not valid as type ' 'argument value for "{}"'.format(arg.name, info.name()), t, ) continue else: arg_values = [arg] self.check_type_var_values( info, arg_values, tvar.name, tvar.values, i + 1, t ) if not is_subtype(arg, tvar.upper_bound): self.fail( 'Type argument "{}" of "{}" must be a subtype of "{}"'.format( arg, info.name(), tvar.upper_bound ), t, ) for arg in t.args: arg.accept(self) if info.is_newtype: for base in info.bases: base.accept(self)
https://github.com/python/mypy/issues/3836
mypy --show-traceback Deduction.py Deduction.py:102: error: The return type of "__init__" must be None Deduction.py:103: error: INTERNAL ERROR -- please report a bug at https://github.com/python/mypy/issues version: 0.521-858f7512cf3b4e39c0f4e8de5a13eee0e1e138fb-dirty Traceback (most recent call last): File "/usr/local/Cellar/mypy/0.521/libexec/bin/mypy", line 11, in <module> load_entry_point('mypy===0.521-858f7512cf3b4e39c0f4e8de5a13eee0e1e138fb-dirty', 'console_scripts', 'mypy')() File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/__main__.py", line 7, in console_entry main(None) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/main.py", line 50, in main res = type_check_only(sources, bin_dir, options) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/main.py", line 97, in type_check_only options=options) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 196, in build graph = dispatch(sources, manager) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 1801, in dispatch process_graph(graph, manager) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 2044, in process_graph process_stale_scc(graph, scc, manager) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 2147, in process_stale_scc graph[id].type_check_first_pass() File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 1716, in type_check_first_pass self.type_checker.check_first_pass() File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 185, in check_first_pass self.accept(d) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 754, in accept return visitor.visit_class_def(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1109, in visit_class_def self.accept(defn.defs) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 815, in accept return visitor.visit_block(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1202, in visit_block self.accept(s) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 565, in accept return visitor.visit_func_def(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 519, in visit_func_def self.check_func_item(defn, name=defn.name()) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 578, in check_func_item self.check_func_def(defn, typ, name) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 738, in check_func_def self.accept(item.body) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 815, in accept return visitor.visit_block(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1202, in visit_block self.accept(s) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 974, in accept return visitor.visit_if_stmt(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1977, in visit_if_stmt if_map, else_map = self.find_isinstance_check(e) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 2559, in find_isinstance_check return find_isinstance_check(n, self.type_map) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 2810, in find_isinstance_check return conditional_type_map(expr, vartype, type) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 2613, in conditional_type_map and is_proper_subtype(current_type, proposed_type)): File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 569, in is_proper_subtype return left.accept(ProperSubtypeVisitor(right)) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/types.py", line 1114, in accept return visitor.visit_union_type(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 693, in visit_union_type return all([is_proper_subtype(item, self.right) for item in left.items]) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 693, in <listcomp> return all([is_proper_subtype(item, self.right) for item in left.items]) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 569, in is_proper_subtype return left.accept(ProperSubtypeVisitor(right)) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/types.py", line 900, in accept return visitor.visit_tuple_type(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 671, in visit_tuple_type if not is_proper_subtype(l, r): File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 569, in is_proper_subtype return left.accept(ProperSubtypeVisitor(right)) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/types.py", line 435, in accept return visitor.visit_instance(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 605, in visit_instance for base in left.type.mro: TypeError: 'NoneType' object is not iterable Deduction.py:103: note: use --pdb to drop into pdb
TypeError
def check_type_var_values( self, type: TypeInfo, actuals: List[Type], arg_name: str, valids: List[Type], arg_number: int, context: Context, ) -> None: for actual in actuals: actual = self.update_type(actual) if not isinstance(actual, AnyType) and not any( is_same_type(actual, self.update_type(value)) for value in valids ): if len(actuals) > 1 or not isinstance(actual, Instance): self.fail( 'Invalid type argument value for "{}"'.format(type.name()), context ) else: class_name = '"{}"'.format(type.name()) actual_type_name = '"{}"'.format(actual.type.name()) self.fail( messages.INCOMPATIBLE_TYPEVAR_VALUE.format( arg_name, class_name, actual_type_name ), context, )
def check_type_var_values( self, type: TypeInfo, actuals: List[Type], arg_name: str, valids: List[Type], arg_number: int, context: Context, ) -> None: for actual in actuals: if not isinstance(actual, AnyType) and not any( is_same_type(actual, value) for value in valids ): if len(actuals) > 1 or not isinstance(actual, Instance): self.fail( 'Invalid type argument value for "{}"'.format(type.name()), context ) else: class_name = '"{}"'.format(type.name()) actual_type_name = '"{}"'.format(actual.type.name()) self.fail( messages.INCOMPATIBLE_TYPEVAR_VALUE.format( arg_name, class_name, actual_type_name ), context, )
https://github.com/python/mypy/issues/3836
mypy --show-traceback Deduction.py Deduction.py:102: error: The return type of "__init__" must be None Deduction.py:103: error: INTERNAL ERROR -- please report a bug at https://github.com/python/mypy/issues version: 0.521-858f7512cf3b4e39c0f4e8de5a13eee0e1e138fb-dirty Traceback (most recent call last): File "/usr/local/Cellar/mypy/0.521/libexec/bin/mypy", line 11, in <module> load_entry_point('mypy===0.521-858f7512cf3b4e39c0f4e8de5a13eee0e1e138fb-dirty', 'console_scripts', 'mypy')() File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/__main__.py", line 7, in console_entry main(None) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/main.py", line 50, in main res = type_check_only(sources, bin_dir, options) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/main.py", line 97, in type_check_only options=options) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 196, in build graph = dispatch(sources, manager) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 1801, in dispatch process_graph(graph, manager) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 2044, in process_graph process_stale_scc(graph, scc, manager) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 2147, in process_stale_scc graph[id].type_check_first_pass() File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 1716, in type_check_first_pass self.type_checker.check_first_pass() File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 185, in check_first_pass self.accept(d) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 754, in accept return visitor.visit_class_def(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1109, in visit_class_def self.accept(defn.defs) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 815, in accept return visitor.visit_block(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1202, in visit_block self.accept(s) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 565, in accept return visitor.visit_func_def(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 519, in visit_func_def self.check_func_item(defn, name=defn.name()) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 578, in check_func_item self.check_func_def(defn, typ, name) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 738, in check_func_def self.accept(item.body) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 815, in accept return visitor.visit_block(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1202, in visit_block self.accept(s) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 974, in accept return visitor.visit_if_stmt(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1977, in visit_if_stmt if_map, else_map = self.find_isinstance_check(e) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 2559, in find_isinstance_check return find_isinstance_check(n, self.type_map) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 2810, in find_isinstance_check return conditional_type_map(expr, vartype, type) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 2613, in conditional_type_map and is_proper_subtype(current_type, proposed_type)): File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 569, in is_proper_subtype return left.accept(ProperSubtypeVisitor(right)) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/types.py", line 1114, in accept return visitor.visit_union_type(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 693, in visit_union_type return all([is_proper_subtype(item, self.right) for item in left.items]) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 693, in <listcomp> return all([is_proper_subtype(item, self.right) for item in left.items]) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 569, in is_proper_subtype return left.accept(ProperSubtypeVisitor(right)) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/types.py", line 900, in accept return visitor.visit_tuple_type(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 671, in visit_tuple_type if not is_proper_subtype(l, r): File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 569, in is_proper_subtype return left.accept(ProperSubtypeVisitor(right)) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/types.py", line 435, in accept return visitor.visit_instance(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 605, in visit_instance for base in left.type.mro: TypeError: 'NoneType' object is not iterable Deduction.py:103: note: use --pdb to drop into pdb
TypeError
def visit_type_var(self, t: TypeVarType) -> None: if t.upper_bound: t.upper_bound.accept(self) if t.values: for v in t.values: v.accept(self)
def visit_type_var(self, t: TypeVarType) -> None: pass
https://github.com/python/mypy/issues/3836
mypy --show-traceback Deduction.py Deduction.py:102: error: The return type of "__init__" must be None Deduction.py:103: error: INTERNAL ERROR -- please report a bug at https://github.com/python/mypy/issues version: 0.521-858f7512cf3b4e39c0f4e8de5a13eee0e1e138fb-dirty Traceback (most recent call last): File "/usr/local/Cellar/mypy/0.521/libexec/bin/mypy", line 11, in <module> load_entry_point('mypy===0.521-858f7512cf3b4e39c0f4e8de5a13eee0e1e138fb-dirty', 'console_scripts', 'mypy')() File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/__main__.py", line 7, in console_entry main(None) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/main.py", line 50, in main res = type_check_only(sources, bin_dir, options) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/main.py", line 97, in type_check_only options=options) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 196, in build graph = dispatch(sources, manager) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 1801, in dispatch process_graph(graph, manager) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 2044, in process_graph process_stale_scc(graph, scc, manager) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 2147, in process_stale_scc graph[id].type_check_first_pass() File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 1716, in type_check_first_pass self.type_checker.check_first_pass() File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 185, in check_first_pass self.accept(d) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 754, in accept return visitor.visit_class_def(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1109, in visit_class_def self.accept(defn.defs) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 815, in accept return visitor.visit_block(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1202, in visit_block self.accept(s) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 565, in accept return visitor.visit_func_def(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 519, in visit_func_def self.check_func_item(defn, name=defn.name()) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 578, in check_func_item self.check_func_def(defn, typ, name) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 738, in check_func_def self.accept(item.body) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 815, in accept return visitor.visit_block(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1202, in visit_block self.accept(s) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 974, in accept return visitor.visit_if_stmt(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1977, in visit_if_stmt if_map, else_map = self.find_isinstance_check(e) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 2559, in find_isinstance_check return find_isinstance_check(n, self.type_map) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 2810, in find_isinstance_check return conditional_type_map(expr, vartype, type) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 2613, in conditional_type_map and is_proper_subtype(current_type, proposed_type)): File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 569, in is_proper_subtype return left.accept(ProperSubtypeVisitor(right)) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/types.py", line 1114, in accept return visitor.visit_union_type(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 693, in visit_union_type return all([is_proper_subtype(item, self.right) for item in left.items]) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 693, in <listcomp> return all([is_proper_subtype(item, self.right) for item in left.items]) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 569, in is_proper_subtype return left.accept(ProperSubtypeVisitor(right)) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/types.py", line 900, in accept return visitor.visit_tuple_type(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 671, in visit_tuple_type if not is_proper_subtype(l, r): File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 569, in is_proper_subtype return left.accept(ProperSubtypeVisitor(right)) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/types.py", line 435, in accept return visitor.visit_instance(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 605, in visit_instance for base in left.type.mro: TypeError: 'NoneType' object is not iterable Deduction.py:103: note: use --pdb to drop into pdb
TypeError
def visit_type_type(self, t: TypeType) -> None: t.item.accept(self)
def visit_type_type(self, t: TypeType) -> None: pass
https://github.com/python/mypy/issues/3836
mypy --show-traceback Deduction.py Deduction.py:102: error: The return type of "__init__" must be None Deduction.py:103: error: INTERNAL ERROR -- please report a bug at https://github.com/python/mypy/issues version: 0.521-858f7512cf3b4e39c0f4e8de5a13eee0e1e138fb-dirty Traceback (most recent call last): File "/usr/local/Cellar/mypy/0.521/libexec/bin/mypy", line 11, in <module> load_entry_point('mypy===0.521-858f7512cf3b4e39c0f4e8de5a13eee0e1e138fb-dirty', 'console_scripts', 'mypy')() File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/__main__.py", line 7, in console_entry main(None) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/main.py", line 50, in main res = type_check_only(sources, bin_dir, options) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/main.py", line 97, in type_check_only options=options) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 196, in build graph = dispatch(sources, manager) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 1801, in dispatch process_graph(graph, manager) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 2044, in process_graph process_stale_scc(graph, scc, manager) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 2147, in process_stale_scc graph[id].type_check_first_pass() File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 1716, in type_check_first_pass self.type_checker.check_first_pass() File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 185, in check_first_pass self.accept(d) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 754, in accept return visitor.visit_class_def(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1109, in visit_class_def self.accept(defn.defs) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 815, in accept return visitor.visit_block(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1202, in visit_block self.accept(s) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 565, in accept return visitor.visit_func_def(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 519, in visit_func_def self.check_func_item(defn, name=defn.name()) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 578, in check_func_item self.check_func_def(defn, typ, name) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 738, in check_func_def self.accept(item.body) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 815, in accept return visitor.visit_block(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1202, in visit_block self.accept(s) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 974, in accept return visitor.visit_if_stmt(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1977, in visit_if_stmt if_map, else_map = self.find_isinstance_check(e) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 2559, in find_isinstance_check return find_isinstance_check(n, self.type_map) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 2810, in find_isinstance_check return conditional_type_map(expr, vartype, type) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 2613, in conditional_type_map and is_proper_subtype(current_type, proposed_type)): File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 569, in is_proper_subtype return left.accept(ProperSubtypeVisitor(right)) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/types.py", line 1114, in accept return visitor.visit_union_type(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 693, in visit_union_type return all([is_proper_subtype(item, self.right) for item in left.items]) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 693, in <listcomp> return all([is_proper_subtype(item, self.right) for item in left.items]) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 569, in is_proper_subtype return left.accept(ProperSubtypeVisitor(right)) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/types.py", line 900, in accept return visitor.visit_tuple_type(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 671, in visit_tuple_type if not is_proper_subtype(l, r): File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 569, in is_proper_subtype return left.accept(ProperSubtypeVisitor(right)) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/types.py", line 435, in accept return visitor.visit_instance(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 605, in visit_instance for base in left.type.mro: TypeError: 'NoneType' object is not iterable Deduction.py:103: note: use --pdb to drop into pdb
TypeError
def anal_type(self, tp: UnboundType) -> Type: tpan = TypeAnalyser( self.lookup_func, self.lookup_fqn_func, None, self.fail, self.note_func, self.plugin, self.options, self.is_typeshed_stub, third_pass=True, ) return tp.accept(tpan)
def anal_type(self, t: Type, nested: bool = True) -> Type: if nested: self.nesting_level += 1 try: return t.accept(self) finally: if nested: self.nesting_level -= 1
https://github.com/python/mypy/issues/3836
mypy --show-traceback Deduction.py Deduction.py:102: error: The return type of "__init__" must be None Deduction.py:103: error: INTERNAL ERROR -- please report a bug at https://github.com/python/mypy/issues version: 0.521-858f7512cf3b4e39c0f4e8de5a13eee0e1e138fb-dirty Traceback (most recent call last): File "/usr/local/Cellar/mypy/0.521/libexec/bin/mypy", line 11, in <module> load_entry_point('mypy===0.521-858f7512cf3b4e39c0f4e8de5a13eee0e1e138fb-dirty', 'console_scripts', 'mypy')() File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/__main__.py", line 7, in console_entry main(None) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/main.py", line 50, in main res = type_check_only(sources, bin_dir, options) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/main.py", line 97, in type_check_only options=options) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 196, in build graph = dispatch(sources, manager) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 1801, in dispatch process_graph(graph, manager) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 2044, in process_graph process_stale_scc(graph, scc, manager) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 2147, in process_stale_scc graph[id].type_check_first_pass() File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 1716, in type_check_first_pass self.type_checker.check_first_pass() File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 185, in check_first_pass self.accept(d) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 754, in accept return visitor.visit_class_def(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1109, in visit_class_def self.accept(defn.defs) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 815, in accept return visitor.visit_block(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1202, in visit_block self.accept(s) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 565, in accept return visitor.visit_func_def(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 519, in visit_func_def self.check_func_item(defn, name=defn.name()) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 578, in check_func_item self.check_func_def(defn, typ, name) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 738, in check_func_def self.accept(item.body) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 815, in accept return visitor.visit_block(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1202, in visit_block self.accept(s) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 974, in accept return visitor.visit_if_stmt(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1977, in visit_if_stmt if_map, else_map = self.find_isinstance_check(e) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 2559, in find_isinstance_check return find_isinstance_check(n, self.type_map) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 2810, in find_isinstance_check return conditional_type_map(expr, vartype, type) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 2613, in conditional_type_map and is_proper_subtype(current_type, proposed_type)): File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 569, in is_proper_subtype return left.accept(ProperSubtypeVisitor(right)) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/types.py", line 1114, in accept return visitor.visit_union_type(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 693, in visit_union_type return all([is_proper_subtype(item, self.right) for item in left.items]) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 693, in <listcomp> return all([is_proper_subtype(item, self.right) for item in left.items]) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 569, in is_proper_subtype return left.accept(ProperSubtypeVisitor(right)) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/types.py", line 900, in accept return visitor.visit_tuple_type(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 671, in visit_tuple_type if not is_proper_subtype(l, r): File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 569, in is_proper_subtype return left.accept(ProperSubtypeVisitor(right)) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/types.py", line 435, in accept return visitor.visit_instance(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 605, in visit_instance for base in left.type.mro: TypeError: 'NoneType' object is not iterable Deduction.py:103: note: use --pdb to drop into pdb
TypeError
def accept(self, visitor: "TypeVisitor[T]") -> T: return visitor.visit_forwardref_type(self)
def accept(self, visitor: "TypeVisitor[T]") -> T: return visitor.visit_type_type(self)
https://github.com/python/mypy/issues/3836
mypy --show-traceback Deduction.py Deduction.py:102: error: The return type of "__init__" must be None Deduction.py:103: error: INTERNAL ERROR -- please report a bug at https://github.com/python/mypy/issues version: 0.521-858f7512cf3b4e39c0f4e8de5a13eee0e1e138fb-dirty Traceback (most recent call last): File "/usr/local/Cellar/mypy/0.521/libexec/bin/mypy", line 11, in <module> load_entry_point('mypy===0.521-858f7512cf3b4e39c0f4e8de5a13eee0e1e138fb-dirty', 'console_scripts', 'mypy')() File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/__main__.py", line 7, in console_entry main(None) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/main.py", line 50, in main res = type_check_only(sources, bin_dir, options) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/main.py", line 97, in type_check_only options=options) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 196, in build graph = dispatch(sources, manager) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 1801, in dispatch process_graph(graph, manager) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 2044, in process_graph process_stale_scc(graph, scc, manager) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 2147, in process_stale_scc graph[id].type_check_first_pass() File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 1716, in type_check_first_pass self.type_checker.check_first_pass() File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 185, in check_first_pass self.accept(d) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 754, in accept return visitor.visit_class_def(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1109, in visit_class_def self.accept(defn.defs) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 815, in accept return visitor.visit_block(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1202, in visit_block self.accept(s) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 565, in accept return visitor.visit_func_def(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 519, in visit_func_def self.check_func_item(defn, name=defn.name()) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 578, in check_func_item self.check_func_def(defn, typ, name) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 738, in check_func_def self.accept(item.body) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 815, in accept return visitor.visit_block(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1202, in visit_block self.accept(s) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 974, in accept return visitor.visit_if_stmt(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1977, in visit_if_stmt if_map, else_map = self.find_isinstance_check(e) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 2559, in find_isinstance_check return find_isinstance_check(n, self.type_map) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 2810, in find_isinstance_check return conditional_type_map(expr, vartype, type) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 2613, in conditional_type_map and is_proper_subtype(current_type, proposed_type)): File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 569, in is_proper_subtype return left.accept(ProperSubtypeVisitor(right)) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/types.py", line 1114, in accept return visitor.visit_union_type(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 693, in visit_union_type return all([is_proper_subtype(item, self.right) for item in left.items]) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 693, in <listcomp> return all([is_proper_subtype(item, self.right) for item in left.items]) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 569, in is_proper_subtype return left.accept(ProperSubtypeVisitor(right)) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/types.py", line 900, in accept return visitor.visit_tuple_type(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 671, in visit_tuple_type if not is_proper_subtype(l, r): File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 569, in is_proper_subtype return left.accept(ProperSubtypeVisitor(right)) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/types.py", line 435, in accept return visitor.visit_instance(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 605, in visit_instance for base in left.type.mro: TypeError: 'NoneType' object is not iterable Deduction.py:103: note: use --pdb to drop into pdb
TypeError
def serialize(self): if isinstance(self.link, UnboundType): name = self.link.name if isinstance(self.link, Instance): name = self.link.type.name() else: name = self.link.__class__.__name__ # We should never get here since all forward references should be resolved # and removed during semantic analysis. assert False, "Internal error: Unresolved forward reference to {}".format(name)
def serialize(self) -> JsonDict: return {".class": "TypeType", "item": self.item.serialize()}
https://github.com/python/mypy/issues/3836
mypy --show-traceback Deduction.py Deduction.py:102: error: The return type of "__init__" must be None Deduction.py:103: error: INTERNAL ERROR -- please report a bug at https://github.com/python/mypy/issues version: 0.521-858f7512cf3b4e39c0f4e8de5a13eee0e1e138fb-dirty Traceback (most recent call last): File "/usr/local/Cellar/mypy/0.521/libexec/bin/mypy", line 11, in <module> load_entry_point('mypy===0.521-858f7512cf3b4e39c0f4e8de5a13eee0e1e138fb-dirty', 'console_scripts', 'mypy')() File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/__main__.py", line 7, in console_entry main(None) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/main.py", line 50, in main res = type_check_only(sources, bin_dir, options) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/main.py", line 97, in type_check_only options=options) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 196, in build graph = dispatch(sources, manager) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 1801, in dispatch process_graph(graph, manager) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 2044, in process_graph process_stale_scc(graph, scc, manager) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 2147, in process_stale_scc graph[id].type_check_first_pass() File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/build.py", line 1716, in type_check_first_pass self.type_checker.check_first_pass() File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 185, in check_first_pass self.accept(d) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 754, in accept return visitor.visit_class_def(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1109, in visit_class_def self.accept(defn.defs) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 815, in accept return visitor.visit_block(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1202, in visit_block self.accept(s) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 565, in accept return visitor.visit_func_def(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 519, in visit_func_def self.check_func_item(defn, name=defn.name()) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 578, in check_func_item self.check_func_def(defn, typ, name) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 738, in check_func_def self.accept(item.body) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 815, in accept return visitor.visit_block(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1202, in visit_block self.accept(s) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 273, in accept stmt.accept(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/nodes.py", line 974, in accept return visitor.visit_if_stmt(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 1977, in visit_if_stmt if_map, else_map = self.find_isinstance_check(e) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 2559, in find_isinstance_check return find_isinstance_check(n, self.type_map) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 2810, in find_isinstance_check return conditional_type_map(expr, vartype, type) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/checker.py", line 2613, in conditional_type_map and is_proper_subtype(current_type, proposed_type)): File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 569, in is_proper_subtype return left.accept(ProperSubtypeVisitor(right)) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/types.py", line 1114, in accept return visitor.visit_union_type(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 693, in visit_union_type return all([is_proper_subtype(item, self.right) for item in left.items]) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 693, in <listcomp> return all([is_proper_subtype(item, self.right) for item in left.items]) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 569, in is_proper_subtype return left.accept(ProperSubtypeVisitor(right)) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/types.py", line 900, in accept return visitor.visit_tuple_type(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 671, in visit_tuple_type if not is_proper_subtype(l, r): File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 569, in is_proper_subtype return left.accept(ProperSubtypeVisitor(right)) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/types.py", line 435, in accept return visitor.visit_instance(self) File "/usr/local/Cellar/mypy/0.521/libexec/lib/python3.6/site-packages/mypy/subtypes.py", line 605, in visit_instance for base in left.type.mro: TypeError: 'NoneType' object is not iterable Deduction.py:103: note: use --pdb to drop into pdb
TypeError
def visit_symbol_table(self, symtab: SymbolTable) -> None: # Copy the items because we may mutate symtab. for key, value in list(symtab.items()): cross_ref = value.cross_ref if cross_ref is not None: # Fix up cross-reference. del value.cross_ref if cross_ref in self.modules: value.node = self.modules[cross_ref] else: stnode = lookup_qualified_stnode( self.modules, cross_ref, self.quick_and_dirty ) if stnode is not None: value.node = stnode.node value.type_override = stnode.type_override elif not self.quick_and_dirty: assert stnode is not None, "Could not find cross-ref %s" % ( cross_ref, ) else: # We have a missing crossref in quick mode, need to put something value.node = stale_info() if value.kind == TYPE_ALIAS: value.type_override = Instance(stale_info(), []) else: if isinstance(value.node, TypeInfo): # TypeInfo has no accept(). TODO: Add it? self.visit_type_info(value.node) elif value.node is not None: value.node.accept(self) if value.type_override is not None: value.type_override.accept(self.type_fixer)
def visit_symbol_table(self, symtab: SymbolTable) -> None: # Copy the items because we may mutate symtab. for key, value in list(symtab.items()): cross_ref = value.cross_ref if cross_ref is not None: # Fix up cross-reference. del value.cross_ref if cross_ref in self.modules: value.node = self.modules[cross_ref] else: stnode = lookup_qualified_stnode( self.modules, cross_ref, self.quick_and_dirty ) if stnode is not None: value.node = stnode.node value.type_override = stnode.type_override elif not self.quick_and_dirty: assert stnode is not None, "Could not find cross-ref %s" % ( cross_ref, ) else: # We have a missing crossref in quick mode, need to put something value.node = stale_info() if value.type_override is not None: value.type_override.accept(self.type_fixer) else: if isinstance(value.node, TypeInfo): # TypeInfo has no accept(). TODO: Add it? self.visit_type_info(value.node) elif value.node is not None: value.node.accept(self) if value.type_override is not None: value.type_override.accept(self.type_fixer)
https://github.com/python/mypy/issues/3355
build_number/__init__.py:31: error: Module 'build_number._frozen_version' has no attribute 'DROPBOXEXT_VERSION' build_number/__init__.py:102: error: "DesktopClientBuildNumber" has no attribute "name" Traceback (most recent call last): File "/usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/runpy.py", line 193, in _run_module_as_main "__main__", mod_spec) File "/usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/runpy.py", line 85, in _run_code exec(code, run_globals) File "/Users/---/src/desktop-client/.mypy/venv/lib/python3.6/site-packages/mypy/__main__.py", line 5, in <module> main(None) File "/Users/---/src/desktop-client/.mypy/venv/lib/python3.6/site-packages/mypy/main.py", line 46, in main res = type_check_only(sources, bin_dir, options) File "/Users/---/src/desktop-client/.mypy/venv/lib/python3.6/site-packages/mypy/main.py", line 93, in type_check_only options=options) File "/Users/---/src/desktop-client/.mypy/venv/lib/python3.6/site-packages/mypy/build.py", line 188, in build graph = dispatch(sources, manager) File "/Users/---/src/desktop-client/.mypy/venv/lib/python3.6/site-packages/mypy/build.py", line 1595, in dispatch process_graph(graph, manager) File "/Users/---/src/desktop-client/.mypy/venv/lib/python3.6/site-packages/mypy/build.py", line 1838, in process_graph process_stale_scc(graph, scc, manager) File "/Users/---/src/desktop-client/.mypy/venv/lib/python3.6/site-packages/mypy/build.py", line 1931, in process_stale_scc graph[id].semantic_analysis() File "/Users/---/src/desktop-client/.mypy/venv/lib/python3.6/site-packages/mypy/build.py", line 1495, in semantic_analysis self.manager.semantic_analyzer.visit_file(self.tree, self.xpath, self.options) File "/Users/---/src/desktop-client/.mypy/venv/lib/python3.6/site-packages/mypy/semanal.py", line 257, in visit_file self.accept(d) File "/Users/---/src/desktop-client/.mypy/venv/lib/python3.6/site-packages/mypy/semanal.py", line 3288, in accept node.accept(self) File "/Users/---/src/desktop-client/.mypy/venv/lib/python3.6/site-packages/mypy/nodes.py", line 749, in accept return visitor.visit_class_def(self) File "/Users/---/src/desktop-client/.mypy/venv/lib/python3.6/site-packages/mypy/semanal.py", line 620, in visit_class_def defn.defs.accept(self) File "/Users/---/src/desktop-client/.mypy/venv/lib/python3.6/site-packages/mypy/nodes.py", line 810, in accept return visitor.visit_block(self) File "/Users/---/src/desktop-client/.mypy/venv/lib/python3.6/site-packages/mypy/semanal.py", line 1375, in visit_block self.accept(s) File "/Users/---/src/desktop-client/.mypy/venv/lib/python3.6/site-packages/mypy/semanal.py", line 3288, in accept node.accept(self) File "/Users/---/src/desktop-client/.mypy/venv/lib/python3.6/site-packages/mypy/nodes.py", line 631, in accept return visitor.visit_decorator(self) File "/Users/---/src/desktop-client/.mypy/venv/lib/python3.6/site-packages/mypy/semanal.py", line 2470, in visit_decorator dec.func.accept(self) File "/Users/---/src/desktop-client/.mypy/venv/lib/python3.6/site-packages/mypy/nodes.py", line 564, in accept return visitor.visit_func_def(self) File "/Users/---/src/desktop-client/.mypy/venv/lib/python3.6/site-packages/mypy/semanal.py", line 376, in visit_func_def self.analyze_function(defn) File "/Users/---/src/desktop-client/.mypy/venv/lib/python3.6/site-packages/mypy/semanal.py", line 550, in analyze_function defn.type = self.type_analyzer().visit_callable_type(defn.type, nested=False) File "/Users/---/src/desktop-client/.mypy/venv/lib/python3.6/site-packages/mypy/typeanal.py", line 343, in visit_callable_type ret_type=self.anal_type(t.ret_type, nested=nested), File "/Users/---/src/desktop-client/.mypy/venv/lib/python3.6/site-packages/mypy/typeanal.py", line 521, in anal_type return t.accept(self) File "/Users/---/src/desktop-client/.mypy/venv/lib/python3.6/site-packages/mypy/types.py", line 211, in accept return visitor.visit_unbound_type(self) File "/Users/---/src/desktop-client/.mypy/venv/lib/python3.6/site-packages/mypy/typeanal.py", line 210, in visit_unbound_type assert override is not None AssertionError:
AssertionError
def visit_call_expr(self, e: CallExpr, allow_none_return: bool = False) -> Type: """Type check a call expression.""" if e.analyzed: # It's really a special form that only looks like a call. return self.accept(e.analyzed, self.type_context[-1]) if ( isinstance(e.callee, NameExpr) and isinstance(e.callee.node, TypeInfo) and e.callee.node.typeddict_type is not None ): # Use named fallback for better error messages. typeddict_type = e.callee.node.typeddict_type.copy_modified( fallback=Instance(e.callee.node, []) ) return self.check_typeddict_call( typeddict_type, e.arg_kinds, e.arg_names, e.args, e ) if ( isinstance(e.callee, NameExpr) and e.callee.name in ("isinstance", "issubclass") and len(e.args) == 2 ): for typ in mypy.checker.flatten(e.args[1]): if isinstance(typ, NameExpr): try: node = self.chk.lookup_qualified(typ.name) except KeyError: # Undefined names should already be reported in semantic analysis. node = None if ( isinstance(typ, IndexExpr) and isinstance(typ.analyzed, (TypeApplication, TypeAliasExpr)) # node.kind == TYPE_ALIAS only for aliases like It = Iterable[int]. or isinstance(typ, NameExpr) and node and node.kind == nodes.TYPE_ALIAS ): self.msg.type_arguments_not_allowed(e) self.try_infer_partial_type(e) callee_type = self.accept(e.callee, always_allow_any=True) if ( self.chk.options.disallow_untyped_calls and self.chk.in_checked_function() and isinstance(callee_type, CallableType) and callee_type.implicit ): return self.msg.untyped_function_call(callee_type, e) # Figure out the full name of the callee for plugin loopup. object_type = None if not isinstance(e.callee, RefExpr): fullname = None else: fullname = e.callee.fullname if ( fullname is None and isinstance(e.callee, MemberExpr) and isinstance(callee_type, FunctionLike) ): # For method calls we include the defining class for the method # in the full name (example: 'typing.Mapping.get'). callee_expr_type = self.chk.type_map.get(e.callee.expr) info = None # TODO: Support fallbacks of other kinds of types as well? if isinstance(callee_expr_type, Instance): info = callee_expr_type.type elif isinstance(callee_expr_type, TypedDictType): info = callee_expr_type.fallback.type.get_containing_type_info( e.callee.name ) if info: fullname = "{}.{}".format(info.fullname(), e.callee.name) object_type = callee_expr_type # Apply plugin signature hook that may generate a better signature. signature_hook = self.plugin.get_method_signature_hook(fullname) if signature_hook: callee_type = self.apply_method_signature_hook( e, callee_type, object_type, signature_hook ) ret_type = self.check_call_expr_with_callee_type( callee_type, e, fullname, object_type ) if isinstance(ret_type, UninhabitedType): self.chk.binder.unreachable() if not allow_none_return and isinstance(ret_type, NoneTyp): self.chk.msg.does_not_return_value(callee_type, e) return AnyType(implicit=True) return ret_type
def visit_call_expr(self, e: CallExpr, allow_none_return: bool = False) -> Type: """Type check a call expression.""" if e.analyzed: # It's really a special form that only looks like a call. return self.accept(e.analyzed, self.type_context[-1]) if ( isinstance(e.callee, NameExpr) and isinstance(e.callee.node, TypeInfo) and e.callee.node.typeddict_type is not None ): # Use named fallback for better error messages. typeddict_type = e.callee.node.typeddict_type.copy_modified( fallback=Instance(e.callee.node, []) ) return self.check_typeddict_call( typeddict_type, e.arg_kinds, e.arg_names, e.args, e ) if isinstance(e.callee, NameExpr) and e.callee.name in ("isinstance", "issubclass"): for typ in mypy.checker.flatten(e.args[1]): if isinstance(typ, NameExpr): try: node = self.chk.lookup_qualified(typ.name) except KeyError: # Undefined names should already be reported in semantic analysis. node = None if ( isinstance(typ, IndexExpr) and isinstance(typ.analyzed, (TypeApplication, TypeAliasExpr)) # node.kind == TYPE_ALIAS only for aliases like It = Iterable[int]. or isinstance(typ, NameExpr) and node and node.kind == nodes.TYPE_ALIAS ): self.msg.type_arguments_not_allowed(e) self.try_infer_partial_type(e) callee_type = self.accept(e.callee, always_allow_any=True) if ( self.chk.options.disallow_untyped_calls and self.chk.in_checked_function() and isinstance(callee_type, CallableType) and callee_type.implicit ): return self.msg.untyped_function_call(callee_type, e) # Figure out the full name of the callee for plugin loopup. object_type = None if not isinstance(e.callee, RefExpr): fullname = None else: fullname = e.callee.fullname if ( fullname is None and isinstance(e.callee, MemberExpr) and isinstance(callee_type, FunctionLike) ): # For method calls we include the defining class for the method # in the full name (example: 'typing.Mapping.get'). callee_expr_type = self.chk.type_map.get(e.callee.expr) info = None # TODO: Support fallbacks of other kinds of types as well? if isinstance(callee_expr_type, Instance): info = callee_expr_type.type elif isinstance(callee_expr_type, TypedDictType): info = callee_expr_type.fallback.type.get_containing_type_info( e.callee.name ) if info: fullname = "{}.{}".format(info.fullname(), e.callee.name) object_type = callee_expr_type # Apply plugin signature hook that may generate a better signature. signature_hook = self.plugin.get_method_signature_hook(fullname) if signature_hook: callee_type = self.apply_method_signature_hook( e, callee_type, object_type, signature_hook ) ret_type = self.check_call_expr_with_callee_type( callee_type, e, fullname, object_type ) if isinstance(ret_type, UninhabitedType): self.chk.binder.unreachable() if not allow_none_return and isinstance(ret_type, NoneTyp): self.chk.msg.does_not_return_value(callee_type, e) return AnyType(implicit=True) return ret_type
https://github.com/python/mypy/issues/3650
Traceback (most recent call last): File "/Users/jukka/src/mypy/scripts/mypy", line 6, in <module> main(__file__) File "/Users/jukka/src/mypy/mypy/main.py", line 50, in main res = type_check_only(sources, bin_dir, options) File "/Users/jukka/src/mypy/mypy/main.py", line 97, in type_check_only options=options) File "/Users/jukka/src/mypy/mypy/build.py", line 192, in build graph = dispatch(sources, manager) File "/Users/jukka/src/mypy/mypy/build.py", line 1761, in dispatch process_graph(graph, manager) File "/Users/jukka/src/mypy/mypy/build.py", line 2004, in process_graph process_stale_scc(graph, scc, manager) File "/Users/jukka/src/mypy/mypy/build.py", line 2107, in process_stale_scc graph[id].type_check_first_pass() File "/Users/jukka/src/mypy/mypy/build.py", line 1676, in type_check_first_pass self.type_checker.check_first_pass() File "/Users/jukka/src/mypy/mypy/checker.py", line 185, in check_first_pass self.accept(d) File "/Users/jukka/src/mypy/mypy/checker.py", line 273, in accept stmt.accept(self) File "/Users/jukka/src/mypy/mypy/nodes.py", line 829, in accept return visitor.visit_expression_stmt(self) File "/Users/jukka/src/mypy/mypy/checker.py", line 1880, in visit_expression_stmt self.expr_checker.accept(s.expr, allow_none_return=True, always_allow_any=True) File "/Users/jukka/src/mypy/mypy/checkexpr.py", line 2223, in accept typ = self.visit_call_expr(node, allow_none_return=True) File "/Users/jukka/src/mypy/mypy/checkexpr.py", line 196, in visit_call_expr for typ in mypy.checker.flatten(e.args[1]): IndexError: list index out of range
IndexError
def visit_lambda_expr(self, e: LambdaExpr) -> Type: """Type check lambda expression.""" inferred_type, type_override = self.infer_lambda_type_using_context(e) if not inferred_type: self.chk.return_types.append(AnyType()) # No useful type context. ret_type = self.accept(e.expr(), allow_none_return=True) fallback = self.named_type("builtins.function") self.chk.return_types.pop() return callable_type(e, fallback, ret_type) else: # Type context available. self.chk.return_types.append(inferred_type.ret_type) self.chk.check_func_item(e, type_override=type_override) if e.expr() not in self.chk.type_map: self.accept(e.expr(), allow_none_return=True) ret_type = self.chk.type_map[e.expr()] if isinstance(ret_type, NoneTyp): # For "lambda ...: None", just use type from the context. # Important when the context is Callable[..., None] which # really means Void. See #1425. self.chk.return_types.pop() return inferred_type self.chk.return_types.pop() return replace_callable_return_type(inferred_type, ret_type)
def visit_lambda_expr(self, e: LambdaExpr) -> Type: """Type check lambda expression.""" inferred_type, type_override = self.infer_lambda_type_using_context(e) if not inferred_type: # No useful type context. ret_type = self.accept(e.expr(), allow_none_return=True) fallback = self.named_type("builtins.function") return callable_type(e, fallback, ret_type) else: # Type context available. self.chk.check_func_item(e, type_override=type_override) if e.expr() not in self.chk.type_map: self.accept(e.expr(), allow_none_return=True) ret_type = self.chk.type_map[e.expr()] if isinstance(ret_type, NoneTyp): # For "lambda ...: None", just use type from the context. # Important when the context is Callable[..., None] which # really means Void. See #1425. return inferred_type return replace_callable_return_type(inferred_type, ret_type)
https://github.com/python/mypy/issues/3243
error: INTERNAL ERROR -- please report a bug at https://github.com/python/mypy/issues Traceback (most recent call last): File "/usr/local/bin/mypy", line 6, in <module> main(__file__) File "/usr/local/lib/python3.6/site-packages/mypy/main.py", line 42, in main res = type_check_only(sources, bin_dir, options) File "/usr/local/lib/python3.6/site-packages/mypy/main.py", line 86, in type_check_only options=options) File "/usr/local/lib/python3.6/site-packages/mypy/build.py", line 183, in build dispatch(sources, manager) File "/usr/local/lib/python3.6/site-packages/mypy/build.py", line 1531, in dispatch process_graph(graph, manager) File "/usr/local/lib/python3.6/site-packages/mypy/build.py", line 1768, in process_graph process_stale_scc(graph, scc) File "/usr/local/lib/python3.6/site-packages/mypy/build.py", line 1847, in process_stale_scc graph[id].type_check_first_pass() File "/usr/local/lib/python3.6/site-packages/mypy/build.py", line 1453, in type_check_first_pass self.type_checker.check_first_pass() File "/usr/local/lib/python3.6/site-packages/mypy/checker.py", line 167, in check_first_pass self.accept(d) File "/usr/local/lib/python3.6/site-packages/mypy/checker.py", line 233, in accept stmt.accept(self) File "/usr/local/lib/python3.6/site-packages/mypy/nodes.py", line 792, in accept return visitor.visit_expression_stmt(self) File "/usr/local/lib/python3.6/site-packages/mypy/checker.py", line 1683, in visit_expression_stmt self.expr_checker.accept(s.expr) File "/usr/local/lib/python3.6/site-packages/mypy/checkexpr.py", line 2015, in accept typ = node.accept(self) File "/usr/local/lib/python3.6/site-packages/mypy/nodes.py", line 1507, in accept return visitor.visit_func_expr(self) File "/usr/local/lib/python3.6/site-packages/mypy/checkexpr.py", line 1769, in visit_func_expr ret_type = self.accept(e.expr()) File "/usr/local/lib/python3.6/site-packages/mypy/checkexpr.py", line 2015, in accept typ = node.accept(self) File "/usr/local/lib/python3.6/site-packages/mypy/nodes.py", line 1284, in accept return visitor.visit_yield_expr(self) File "/usr/local/lib/python3.6/site-packages/mypy/checkexpr.py", line 2088, in visit_yield_expr return_type = self.chk.return_types[-1] IndexError: list index out of range
IndexError
def on_finish(self) -> None: total_any = sum(num_any for num_any, _ in self.counts.values()) total_expr = sum(total for _, total in self.counts.values()) total_coverage = 100.0 if total_expr > 0: total_coverage = (float(total_expr - total_any) / float(total_expr)) * 100 any_column_name = "Anys" total_column_name = "Exprs" file_column_name = "Name" coverage_column_name = "Coverage" # find the longest filename all files name_width = max([len(file) for file in self.counts] + [len(file_column_name)]) # totals are the largest numbers in their column - no need to look at others min_column_distance = 3 # minimum distance between numbers in two columns any_width = max(len(str(total_any)) + min_column_distance, len(any_column_name)) exprs_width = max( len(str(total_expr)) + min_column_distance, len(total_column_name) ) coverage_width = len(coverage_column_name) + min_column_distance header = ( "{:{name_width}} {:>{any_width}} {:>{total_width}} {:>{coverage_width}}".format( file_column_name, any_column_name, total_column_name, coverage_column_name, name_width=name_width, any_width=any_width, total_width=exprs_width, coverage_width=coverage_width, ) ) with open(os.path.join(self.output_dir, "any-exprs.txt"), "w") as f: f.write(header + "\n") separator = "-" * len(header) + "\n" f.write(separator) coverage_width -= 1 # subtract one for '%' for file in sorted(self.counts): (num_any, num_total) = self.counts[file] coverage = (float(num_total - num_any) / float(num_total)) * 100 f.write( "{:{name_width}} {:{any_width}} {:{total_width}} " "{:>{coverage_width}.2f}%\n".format( file, num_any, num_total, coverage, name_width=name_width, any_width=any_width, total_width=exprs_width, coverage_width=coverage_width, ) ) f.write(separator) f.write( "{:{name_width}} {:{any_width}} {:{total_width}} {:>{coverage_width}.2f}%\n".format( "Total", total_any, total_expr, total_coverage, name_width=name_width, any_width=any_width, total_width=exprs_width, coverage_width=coverage_width, ) )
def on_finish(self) -> None: total_any = sum(num_any for num_any, _ in self.counts.values()) total_expr = sum(total for _, total in self.counts.values()) total_coverage = (float(total_expr - total_any) / float(total_expr)) * 100 any_column_name = "Anys" total_column_name = "Exprs" file_column_name = "Name" coverage_column_name = "Coverage" # find the longest filename all files name_width = max([len(file) for file in self.counts] + [len(file_column_name)]) # totals are the largest numbers in their column - no need to look at others min_column_distance = 3 # minimum distance between numbers in two columns any_width = max(len(str(total_any)) + min_column_distance, len(any_column_name)) exprs_width = max( len(str(total_expr)) + min_column_distance, len(total_column_name) ) coverage_width = len(coverage_column_name) + min_column_distance header = ( "{:{name_width}} {:>{any_width}} {:>{total_width}} {:>{coverage_width}}".format( file_column_name, any_column_name, total_column_name, coverage_column_name, name_width=name_width, any_width=any_width, total_width=exprs_width, coverage_width=coverage_width, ) ) with open(os.path.join(self.output_dir, "any-exprs.txt"), "w") as f: f.write(header + "\n") separator = "-" * len(header) + "\n" f.write(separator) coverage_width -= 1 # subtract one for '%' for file in sorted(self.counts): (num_any, num_total) = self.counts[file] coverage = (float(num_total - num_any) / float(num_total)) * 100 f.write( "{:{name_width}} {:{any_width}} {:{total_width}} " "{:>{coverage_width}.2f}%\n".format( file, num_any, num_total, coverage, name_width=name_width, any_width=any_width, total_width=exprs_width, coverage_width=coverage_width, ) ) f.write(separator) f.write( "{:{name_width}} {:{any_width}} {:{total_width}} {:>{coverage_width}.2f}%\n".format( "Total", total_any, total_expr, total_coverage, name_width=name_width, any_width=any_width, total_width=exprs_width, coverage_width=coverage_width, ) )
https://github.com/python/mypy/issues/3522
(v36) guido-mbp:mypy guido$ mypy --any-exprs-report=out -c 'pass' Traceback (most recent call last): File "/Users/guido/v36/bin/mypy", line 6, in <module> exec(compile(open(__file__).read(), __file__, 'exec')) File "/Users/guido/src/mypy/scripts/mypy", line 6, in <module> main(__file__) File "/Users/guido/src/mypy/mypy/main.py", line 50, in main res = type_check_only(sources, bin_dir, options) File "/Users/guido/src/mypy/mypy/main.py", line 97, in type_check_only options=options) File "/Users/guido/src/mypy/mypy/build.py", line 198, in build reports.finish() File "/Users/guido/src/mypy/mypy/report.py", line 66, in finish reporter.on_finish() File "/Users/guido/src/mypy/mypy/report.py", line 167, in on_finish total_coverage = (float(total_expr - total_any) / float(total_expr)) * 100 ZeroDivisionError: float division by zero
ZeroDivisionError
def analyze_property_with_multi_part_definition(self, defn: OverloadedFuncDef) -> None: """Analyze a property defined using multiple methods (e.g., using @x.setter). Assume that the first method (@property) has already been analyzed. """ defn.is_property = True items = defn.items first_item = cast(Decorator, defn.items[0]) for item in items[1:]: if isinstance(item, Decorator) and len(item.decorators) == 1: node = item.decorators[0] if isinstance(node, MemberExpr): if node.name == "setter": # The first item represents the entire property. first_item.var.is_settable_property = True # Get abstractness from the original definition. item.func.is_abstract = first_item.func.is_abstract else: self.fail("Decorated property not supported", item) if isinstance(item, Decorator): item.func.accept(self)
def analyze_property_with_multi_part_definition(self, defn: OverloadedFuncDef) -> None: """Analyze a property defined using multiple methods (e.g., using @x.setter). Assume that the first method (@property) has already been analyzed. """ defn.is_property = True items = defn.items first_item = cast(Decorator, defn.items[0]) for item in items[1:]: if isinstance(item, Decorator) and len(item.decorators) == 1: node = item.decorators[0] if isinstance(node, MemberExpr): if node.name == "setter": # The first item represents the entire property. first_item.var.is_settable_property = True # Get abstractness from the original definition. item.func.is_abstract = first_item.func.is_abstract item.func.accept(self) else: self.fail("Decorated property not supported", item)
https://github.com/python/mypy/issues/3491
Traceback (most recent call last): File ".../bin/mypy", line 6, in <module> main(__file__) File ".../lib/python3.5/site-packages/mypy/main.py", line 46, in main res = type_check_only(sources, bin_dir, options) File ".../lib/python3.5/site-packages/mypy/main.py", line 93, in type_check_only options=options) File ".../lib/python3.5/site-packages/mypy/build.py", line 188, in build graph = dispatch(sources, manager) File ".../lib/python3.5/site-packages/mypy/build.py", line 1595, in dispatch process_graph(graph, manager) File ".../lib/python3.5/site-packages/mypy/build.py", line 1838, in process_graph process_stale_scc(graph, scc, manager) File ".../lib/python3.5/site-packages/mypy/build.py", line 1946, in process_stale_scc graph[id].write_cache() File ".../lib/python3.5/site-packages/mypy/build.py", line 1576, in write_cache self.manager) File ".../lib/python3.5/site-packages/mypy/build.py", line 875, in write_cache data = tree.serialize() File ".../lib/python3.5/site-packages/mypy/nodes.py", line 284, in serialize 'names': self.names.serialize(self._fullname), File ".../lib/python3.5/site-packages/mypy/nodes.py", line 2377, in serialize data[key] = value.serialize(fullname, key) File ".../lib/python3.5/site-packages/mypy/nodes.py", line 2325, in serialize data['node'] = self.node.serialize() File ".../lib/python3.5/site-packages/mypy/nodes.py", line 2176, in serialize 'names': self.names.serialize(self.fullname()), File ".../lib/python3.5/site-packages/mypy/nodes.py", line 2377, in serialize data[key] = value.serialize(fullname, key) File ".../lib/python3.5/site-packages/mypy/nodes.py", line 2325, in serialize data['node'] = self.node.serialize() File ".../lib/python3.5/site-packages/mypy/nodes.py", line 414, in serialize 'items': [i.serialize() for i in self.items], File ".../lib/python3.5/site-packages/mypy/nodes.py", line 414, in <listcomp> 'items': [i.serialize() for i in self.items], File ".../lib/python3.5/site-packages/mypy/nodes.py", line 636, in serialize 'func': self.func.serialize(), File ".../lib/python3.5/site-packages/mypy/nodes.py", line 579, in serialize 'type': None if self.type is None else self.type.serialize(), File ".../lib/python3.5/site-packages/mypy/types.py", line 766, in serialize 'fallback': self.fallback.serialize(), AttributeError: 'NoneType' object has no attribute 'serialize'
AttributeError
def check_no_global( self, n: str, ctx: Context, is_overloaded_func: bool = False ) -> None: if n in self.globals: prev_is_overloaded = isinstance(self.globals[n], OverloadedFuncDef) if is_overloaded_func and prev_is_overloaded: self.fail("Nonconsecutive overload {} found".format(n), ctx) elif prev_is_overloaded: self.fail("Definition of '{}' missing 'overload'".format(n), ctx) else: self.name_already_defined(n, ctx)
def check_no_global( self, n: str, ctx: Context, is_overloaded_func: bool = False ) -> None: if n in self.globals: prev_is_overloaded = isinstance(self.globals[n], OverloadedFuncDef) if is_overloaded_func and prev_is_overloaded: self.fail("Nonconsecutive overload {} found".format(n), ctx) elif prev_is_overloaded: self.fail("Definition of '{}' missing 'overload'".format(n), ctx) else: self.name_already_defined(n, ctx, self.globals[n])
https://github.com/python/mypy/issues/3415
api/integrations/perforce/git_p4.py: error: INTERNAL ERROR -- please report a bug at https://github.com/python/mypy/issues version: 0.520-dev-13b75737bb41d62ae4e7714704dcda3b446fa9f4 Traceback (most recent call last): File "/mnt/code/venvs/mypy_venv/bin/mypy", line 6, in <module> main(__file__) File "/mnt/code/venvs/mypy_venv/lib/python3.5/site-packages/mypy/main.py", line 46, in main res = type_check_only(sources, bin_dir, options) File "/mnt/code/venvs/mypy_venv/lib/python3.5/site-packages/mypy/main.py", line 93, in type_check_only options=options) File "/mnt/code/venvs/mypy_venv/lib/python3.5/site-packages/mypy/build.py", line 188, in build graph = dispatch(sources, manager) File "/mnt/code/venvs/mypy_venv/lib/python3.5/site-packages/mypy/build.py", line 1587, in dispatch graph = load_graph(sources, manager) File "/mnt/code/venvs/mypy_venv/lib/python3.5/site-packages/mypy/build.py", line 1670, in load_graph root_source=True) File "/mnt/code/venvs/mypy_venv/lib/python3.5/site-packages/mypy/build.py", line 1259, in __init__ self.parse_file() File "/mnt/code/venvs/mypy_venv/lib/python3.5/site-packages/mypy/build.py", line 1442, in parse_file first.visit_file(self.tree, self.xpath, self.id, self.options) File "/usr/lib/python3.5/contextlib.py", line 77, in __exit__ self.gen.throw(type, value, traceback) File "/mnt/code/venvs/mypy_venv/lib/python3.5/site-packages/mypy/build.py", line 1347, in wrap_context yield File "/mnt/code/venvs/mypy_venv/lib/python3.5/site-packages/mypy/build.py", line 1442, in parse_file first.visit_file(self.tree, self.xpath, self.id, self.options) File "/mnt/code/venvs/mypy_venv/lib/python3.5/site-packages/mypy/semanal.py", line 3423, in visit_file d.accept(self) File "/mnt/code/venvs/mypy_venv/lib/python3.5/site-packages/mypy/nodes.py", line 1007, in accept return visitor.visit_try_stmt(self) File "/mnt/code/venvs/mypy_venv/lib/python3.5/site-packages/mypy/semanal.py", line 3614, in visit_try_stmt self.sem.analyze_try_stmt(s, self, add_global=self.sem.is_module_scope()) File "/mnt/code/venvs/mypy_venv/lib/python3.5/site-packages/mypy/semanal.py", line 2632, in analyze_try_stmt handler.accept(visitor) File "/mnt/code/venvs/mypy_venv/lib/python3.5/site-packages/mypy/nodes.py", line 811, in accept return visitor.visit_block(self) File "/mnt/code/venvs/mypy_venv/lib/python3.5/site-packages/mypy/semanal.py", line 3458, in visit_block node.accept(self) File "/mnt/code/venvs/mypy_venv/lib/python3.5/site-packages/mypy/nodes.py", line 750, in accept return visitor.visit_class_def(self) File "/mnt/code/venvs/mypy_venv/lib/python3.5/site-packages/mypy/semanal.py", line 3526, in visit_class_def self.sem.check_no_global(cdef.name, cdef) File "/mnt/code/venvs/mypy_venv/lib/python3.5/site-packages/mypy/semanal.py", line 3318, in check_no_global self.name_already_defined(n, ctx, self.globals[n]) File "/mnt/code/venvs/mypy_venv/lib/python3.5/site-packages/mypy/semanal.py", line 3330, in name_already_defined extra_msg = ' on line {}'.format(original_ctx.node.get_line()) AttributeError: 'NoneType' object has no attribute 'get_line' api/integrations/perforce/git_p4.py: note: use --pdb to drop into pdb
AttributeError
def name_already_defined(self, name: str, ctx: Context) -> None: self.fail("Name '{}' already defined".format(name), ctx)
def name_already_defined( self, name: str, ctx: Context, original_ctx: Optional[SymbolTableNode] = None ) -> None: if original_ctx: extra_msg = " on line {}".format(original_ctx.node.get_line()) else: extra_msg = "" self.fail("Name '{}' already defined{}".format(name, extra_msg), ctx)
https://github.com/python/mypy/issues/3415
api/integrations/perforce/git_p4.py: error: INTERNAL ERROR -- please report a bug at https://github.com/python/mypy/issues version: 0.520-dev-13b75737bb41d62ae4e7714704dcda3b446fa9f4 Traceback (most recent call last): File "/mnt/code/venvs/mypy_venv/bin/mypy", line 6, in <module> main(__file__) File "/mnt/code/venvs/mypy_venv/lib/python3.5/site-packages/mypy/main.py", line 46, in main res = type_check_only(sources, bin_dir, options) File "/mnt/code/venvs/mypy_venv/lib/python3.5/site-packages/mypy/main.py", line 93, in type_check_only options=options) File "/mnt/code/venvs/mypy_venv/lib/python3.5/site-packages/mypy/build.py", line 188, in build graph = dispatch(sources, manager) File "/mnt/code/venvs/mypy_venv/lib/python3.5/site-packages/mypy/build.py", line 1587, in dispatch graph = load_graph(sources, manager) File "/mnt/code/venvs/mypy_venv/lib/python3.5/site-packages/mypy/build.py", line 1670, in load_graph root_source=True) File "/mnt/code/venvs/mypy_venv/lib/python3.5/site-packages/mypy/build.py", line 1259, in __init__ self.parse_file() File "/mnt/code/venvs/mypy_venv/lib/python3.5/site-packages/mypy/build.py", line 1442, in parse_file first.visit_file(self.tree, self.xpath, self.id, self.options) File "/usr/lib/python3.5/contextlib.py", line 77, in __exit__ self.gen.throw(type, value, traceback) File "/mnt/code/venvs/mypy_venv/lib/python3.5/site-packages/mypy/build.py", line 1347, in wrap_context yield File "/mnt/code/venvs/mypy_venv/lib/python3.5/site-packages/mypy/build.py", line 1442, in parse_file first.visit_file(self.tree, self.xpath, self.id, self.options) File "/mnt/code/venvs/mypy_venv/lib/python3.5/site-packages/mypy/semanal.py", line 3423, in visit_file d.accept(self) File "/mnt/code/venvs/mypy_venv/lib/python3.5/site-packages/mypy/nodes.py", line 1007, in accept return visitor.visit_try_stmt(self) File "/mnt/code/venvs/mypy_venv/lib/python3.5/site-packages/mypy/semanal.py", line 3614, in visit_try_stmt self.sem.analyze_try_stmt(s, self, add_global=self.sem.is_module_scope()) File "/mnt/code/venvs/mypy_venv/lib/python3.5/site-packages/mypy/semanal.py", line 2632, in analyze_try_stmt handler.accept(visitor) File "/mnt/code/venvs/mypy_venv/lib/python3.5/site-packages/mypy/nodes.py", line 811, in accept return visitor.visit_block(self) File "/mnt/code/venvs/mypy_venv/lib/python3.5/site-packages/mypy/semanal.py", line 3458, in visit_block node.accept(self) File "/mnt/code/venvs/mypy_venv/lib/python3.5/site-packages/mypy/nodes.py", line 750, in accept return visitor.visit_class_def(self) File "/mnt/code/venvs/mypy_venv/lib/python3.5/site-packages/mypy/semanal.py", line 3526, in visit_class_def self.sem.check_no_global(cdef.name, cdef) File "/mnt/code/venvs/mypy_venv/lib/python3.5/site-packages/mypy/semanal.py", line 3318, in check_no_global self.name_already_defined(n, ctx, self.globals[n]) File "/mnt/code/venvs/mypy_venv/lib/python3.5/site-packages/mypy/semanal.py", line 3330, in name_already_defined extra_msg = ' on line {}'.format(original_ctx.node.get_line()) AttributeError: 'NoneType' object has no attribute 'get_line' api/integrations/perforce/git_p4.py: note: use --pdb to drop into pdb
AttributeError
def unexpected_keyword_argument( self, callee: CallableType, name: str, context: Context ) -> None: msg = 'Unexpected keyword argument "{}"'.format(name) if callee.name: msg += " for {}".format(callee.name) self.fail(msg, context) module = find_defining_module(self.modules, callee) if module: self.note( "{} defined here".format(callee.name), callee.definition, file=module.path, origin=context, )
def unexpected_keyword_argument( self, callee: CallableType, name: str, context: Context ) -> None: msg = 'Unexpected keyword argument "{}"'.format(name) if callee.name: msg += " for {}".format(callee.name) self.fail(msg, context) if callee.definition: fullname = callee.definition.fullname() if fullname is not None and "." in fullname: module_name = fullname.rsplit(".", 1)[0] path = self.modules[module_name].path self.note( "{} defined here".format(callee.name), callee.definition, file=path, origin=context, )
https://github.com/python/mypy/issues/3362
(e2e) Adam@Adams-MacBook-Pro ~/Desktop> mypy example.py --show-traceback example.py:2: error: Unexpected keyword argument "example" for "Popen" example.py:2: error: INTERNAL ERROR -- please report a bug at https://github.com/python/mypy/issues version: 0.511 Traceback (most recent call last): File "/Users/Adam/.virtualenvs/e2e/bin/mypy", line 6, in <module> main(__file__) File "/Users/Adam/.virtualenvs/e2e/lib/python3.6/site-packages/mypy/main.py", line 46, in main res = type_check_only(sources, bin_dir, options) File "/Users/Adam/.virtualenvs/e2e/lib/python3.6/site-packages/mypy/main.py", line 93, in type_check_only options=options) File "/Users/Adam/.virtualenvs/e2e/lib/python3.6/site-packages/mypy/build.py", line 188, in build graph = dispatch(sources, manager) File "/Users/Adam/.virtualenvs/e2e/lib/python3.6/site-packages/mypy/build.py", line 1595, in dispatch process_graph(graph, manager) File "/Users/Adam/.virtualenvs/e2e/lib/python3.6/site-packages/mypy/build.py", line 1838, in process_graph process_stale_scc(graph, scc, manager) File "/Users/Adam/.virtualenvs/e2e/lib/python3.6/site-packages/mypy/build.py", line 1937, in process_stale_scc graph[id].type_check_first_pass() File "/Users/Adam/.virtualenvs/e2e/lib/python3.6/site-packages/mypy/build.py", line 1510, in type_check_first_pass self.type_checker.check_first_pass() File "/Users/Adam/.virtualenvs/e2e/lib/python3.6/site-packages/mypy/checker.py", line 177, in check_first_pass self.accept(d) File "/Users/Adam/.virtualenvs/e2e/lib/python3.6/site-packages/mypy/checker.py", line 264, in accept stmt.accept(self) File "/Users/Adam/.virtualenvs/e2e/lib/python3.6/site-packages/mypy/nodes.py", line 825, in accept return visitor.visit_expression_stmt(self) File "/Users/Adam/.virtualenvs/e2e/lib/python3.6/site-packages/mypy/checker.py", line 1823, in visit_expression_stmt self.expr_checker.accept(s.expr, allow_none_return=True) File "/Users/Adam/.virtualenvs/e2e/lib/python3.6/site-packages/mypy/checkexpr.py", line 2054, in accept typ = self.visit_call_expr(node, allow_none_return=True) File "/Users/Adam/.virtualenvs/e2e/lib/python3.6/site-packages/mypy/checkexpr.py", line 201, in visit_call_expr ret_type = self.check_call_expr_with_callee_type(callee_type, e) File "/Users/Adam/.virtualenvs/e2e/lib/python3.6/site-packages/mypy/checkexpr.py", line 341, in check_call_expr_with_callee_type e.arg_names, callable_node=e.callee)[0] File "/Users/Adam/.virtualenvs/e2e/lib/python3.6/site-packages/mypy/checkexpr.py", line 396, in check_call arg_names, formal_to_actual, context, self.msg) File "/Users/Adam/.virtualenvs/e2e/lib/python3.6/site-packages/mypy/checkexpr.py", line 759, in check_argument_count callee, actual_names[i], context) File "/Users/Adam/.virtualenvs/e2e/lib/python3.6/site-packages/mypy/messages.py", line 619, in unexpected_keyword_argument path = self.modules[module_name].path KeyError: 'subprocess.Popen' example.py:2: note: use --pdb to drop into pdb
KeyError
def visit_func_def(self, defn: FuncDef) -> None: phase_info = self.postpone_nested_functions_stack[-1] if phase_info != FUNCTION_SECOND_PHASE: self.function_stack.append(defn) # First phase of analysis for function. self.errors.push_function(defn.name()) if not defn._fullname: defn._fullname = self.qualified_name(defn.name()) if defn.type: assert isinstance(defn.type, CallableType) self.update_function_type_variables(defn.type, defn) self.errors.pop_function() self.function_stack.pop() defn.is_conditional = self.block_depth[-1] > 0 # TODO(jukka): Figure out how to share the various cases. It doesn't # make sense to have (almost) duplicate code (here and elsewhere) for # 3 cases: module-level, class-level and local names. Maybe implement # a common stack of namespaces. As the 3 kinds of namespaces have # different semantics, this wouldn't always work, but it might still # be a win. if self.is_class_scope(): # Method definition defn.info = self.type if not defn.is_decorated and not defn.is_overload: if ( defn.name() in self.type.names and self.type.names[defn.name()].node != defn ): # Redefinition. Conditional redefinition is okay. n = self.type.names[defn.name()].node if not self.set_original_def(n, defn): self.name_already_defined(defn.name(), defn) self.type.names[defn.name()] = SymbolTableNode(MDEF, defn) self.prepare_method_signature(defn) elif self.is_func_scope(): # Nested function if not defn.is_decorated and not defn.is_overload: if defn.name() in self.locals[-1]: # Redefinition. Conditional redefinition is okay. n = self.locals[-1][defn.name()].node if not self.set_original_def(n, defn): self.name_already_defined(defn.name(), defn) else: self.add_local(defn, defn) else: # Top-level function if not defn.is_decorated and not defn.is_overload: symbol = self.globals.get(defn.name()) if isinstance(symbol.node, FuncDef) and symbol.node != defn: # This is redefinition. Conditional redefinition is okay. if not self.set_original_def(symbol.node, defn): # Report error. self.check_no_global(defn.name(), defn, True) if phase_info == FUNCTION_FIRST_PHASE_POSTPONE_SECOND: # Postpone this function (for the second phase). self.postponed_functions_stack[-1].append(defn) return if phase_info != FUNCTION_FIRST_PHASE_POSTPONE_SECOND: # Second phase of analysis for function. self.errors.push_function(defn.name()) self.analyze_function(defn) if defn.is_coroutine and isinstance(defn.type, CallableType): if defn.is_async_generator: # Async generator types are handled elsewhere pass else: # A coroutine defined as `async def foo(...) -> T: ...` # has external return type `Awaitable[T]`. defn.type = defn.type.copy_modified( ret_type=self.named_type_or_none( "typing.Awaitable", [defn.type.ret_type] ) ) self.errors.pop_function()
def visit_func_def(self, defn: FuncDef) -> None: phase_info = self.postpone_nested_functions_stack[-1] if phase_info != FUNCTION_SECOND_PHASE: self.function_stack.append(defn) # First phase of analysis for function. self.errors.push_function(defn.name()) if defn.type: assert isinstance(defn.type, CallableType) self.update_function_type_variables(defn.type, defn) self.errors.pop_function() self.function_stack.pop() defn.is_conditional = self.block_depth[-1] > 0 # TODO(jukka): Figure out how to share the various cases. It doesn't # make sense to have (almost) duplicate code (here and elsewhere) for # 3 cases: module-level, class-level and local names. Maybe implement # a common stack of namespaces. As the 3 kinds of namespaces have # different semantics, this wouldn't always work, but it might still # be a win. if self.is_class_scope(): # Method definition defn.info = self.type if not defn.is_decorated and not defn.is_overload: if ( defn.name() in self.type.names and self.type.names[defn.name()].node != defn ): # Redefinition. Conditional redefinition is okay. n = self.type.names[defn.name()].node if not self.set_original_def(n, defn): self.name_already_defined(defn.name(), defn) self.type.names[defn.name()] = SymbolTableNode(MDEF, defn) self.prepare_method_signature(defn) elif self.is_func_scope(): # Nested function if not defn.is_decorated and not defn.is_overload: if defn.name() in self.locals[-1]: # Redefinition. Conditional redefinition is okay. n = self.locals[-1][defn.name()].node if not self.set_original_def(n, defn): self.name_already_defined(defn.name(), defn) else: self.add_local(defn, defn) else: # Top-level function if not defn.is_decorated and not defn.is_overload: symbol = self.globals.get(defn.name()) if isinstance(symbol.node, FuncDef) and symbol.node != defn: # This is redefinition. Conditional redefinition is okay. if not self.set_original_def(symbol.node, defn): # Report error. self.check_no_global(defn.name(), defn, True) if phase_info == FUNCTION_FIRST_PHASE_POSTPONE_SECOND: # Postpone this function (for the second phase). self.postponed_functions_stack[-1].append(defn) return if phase_info != FUNCTION_FIRST_PHASE_POSTPONE_SECOND: # Second phase of analysis for function. self.errors.push_function(defn.name()) self.analyze_function(defn) if defn.is_coroutine and isinstance(defn.type, CallableType): if defn.is_async_generator: # Async generator types are handled elsewhere pass else: # A coroutine defined as `async def foo(...) -> T: ...` # has external return type `Awaitable[T]`. defn.type = defn.type.copy_modified( ret_type=self.named_type_or_none( "typing.Awaitable", [defn.type.ret_type] ) ) self.errors.pop_function()
https://github.com/python/mypy/issues/3362
(e2e) Adam@Adams-MacBook-Pro ~/Desktop> mypy example.py --show-traceback example.py:2: error: Unexpected keyword argument "example" for "Popen" example.py:2: error: INTERNAL ERROR -- please report a bug at https://github.com/python/mypy/issues version: 0.511 Traceback (most recent call last): File "/Users/Adam/.virtualenvs/e2e/bin/mypy", line 6, in <module> main(__file__) File "/Users/Adam/.virtualenvs/e2e/lib/python3.6/site-packages/mypy/main.py", line 46, in main res = type_check_only(sources, bin_dir, options) File "/Users/Adam/.virtualenvs/e2e/lib/python3.6/site-packages/mypy/main.py", line 93, in type_check_only options=options) File "/Users/Adam/.virtualenvs/e2e/lib/python3.6/site-packages/mypy/build.py", line 188, in build graph = dispatch(sources, manager) File "/Users/Adam/.virtualenvs/e2e/lib/python3.6/site-packages/mypy/build.py", line 1595, in dispatch process_graph(graph, manager) File "/Users/Adam/.virtualenvs/e2e/lib/python3.6/site-packages/mypy/build.py", line 1838, in process_graph process_stale_scc(graph, scc, manager) File "/Users/Adam/.virtualenvs/e2e/lib/python3.6/site-packages/mypy/build.py", line 1937, in process_stale_scc graph[id].type_check_first_pass() File "/Users/Adam/.virtualenvs/e2e/lib/python3.6/site-packages/mypy/build.py", line 1510, in type_check_first_pass self.type_checker.check_first_pass() File "/Users/Adam/.virtualenvs/e2e/lib/python3.6/site-packages/mypy/checker.py", line 177, in check_first_pass self.accept(d) File "/Users/Adam/.virtualenvs/e2e/lib/python3.6/site-packages/mypy/checker.py", line 264, in accept stmt.accept(self) File "/Users/Adam/.virtualenvs/e2e/lib/python3.6/site-packages/mypy/nodes.py", line 825, in accept return visitor.visit_expression_stmt(self) File "/Users/Adam/.virtualenvs/e2e/lib/python3.6/site-packages/mypy/checker.py", line 1823, in visit_expression_stmt self.expr_checker.accept(s.expr, allow_none_return=True) File "/Users/Adam/.virtualenvs/e2e/lib/python3.6/site-packages/mypy/checkexpr.py", line 2054, in accept typ = self.visit_call_expr(node, allow_none_return=True) File "/Users/Adam/.virtualenvs/e2e/lib/python3.6/site-packages/mypy/checkexpr.py", line 201, in visit_call_expr ret_type = self.check_call_expr_with_callee_type(callee_type, e) File "/Users/Adam/.virtualenvs/e2e/lib/python3.6/site-packages/mypy/checkexpr.py", line 341, in check_call_expr_with_callee_type e.arg_names, callable_node=e.callee)[0] File "/Users/Adam/.virtualenvs/e2e/lib/python3.6/site-packages/mypy/checkexpr.py", line 396, in check_call arg_names, formal_to_actual, context, self.msg) File "/Users/Adam/.virtualenvs/e2e/lib/python3.6/site-packages/mypy/checkexpr.py", line 759, in check_argument_count callee, actual_names[i], context) File "/Users/Adam/.virtualenvs/e2e/lib/python3.6/site-packages/mypy/messages.py", line 619, in unexpected_keyword_argument path = self.modules[module_name].path KeyError: 'subprocess.Popen' example.py:2: note: use --pdb to drop into pdb
KeyError
def visit_symbol_table(self, symtab: SymbolTable) -> None: # Copy the items because we may mutate symtab. for key, value in list(symtab.items()): cross_ref = value.cross_ref if cross_ref is not None: # Fix up cross-reference. del value.cross_ref if cross_ref in self.modules: value.node = self.modules[cross_ref] else: stnode = lookup_qualified_stnode( self.modules, cross_ref, self.quick_and_dirty ) if stnode is not None: value.node = stnode.node value.type_override = stnode.type_override elif not self.quick_and_dirty: assert stnode is not None, "Could not find cross-ref %s" % ( cross_ref, ) else: # We have a missing crossref in quick mode, need to put something value.node = stale_info() if value.type_override is not None: value.type_override.accept(self.type_fixer) else: if isinstance(value.node, TypeInfo): # TypeInfo has no accept(). TODO: Add it? self.visit_type_info(value.node) elif value.node is not None: value.node.accept(self) if value.type_override is not None: value.type_override.accept(self.type_fixer)
def visit_symbol_table(self, symtab: SymbolTable) -> None: # Copy the items because we may mutate symtab. for key, value in list(symtab.items()): cross_ref = value.cross_ref if cross_ref is not None: # Fix up cross-reference. del value.cross_ref if cross_ref in self.modules: value.node = self.modules[cross_ref] else: stnode = lookup_qualified_stnode( self.modules, cross_ref, self.quick_and_dirty ) if stnode is not None: value.node = stnode.node value.type_override = stnode.type_override elif not self.quick_and_dirty: assert stnode is not None, "Could not find cross-ref %s" % ( cross_ref, ) else: if isinstance(value.node, TypeInfo): # TypeInfo has no accept(). TODO: Add it? self.visit_type_info(value.node) elif value.node is not None: value.node.accept(self) if value.type_override is not None: value.type_override.accept(self.type_fixer)
https://github.com/python/mypy/issues/3278
$ mypy --quick --show-traceback a.py /Users/jukka/src/mypy/b.py:3: error: INTERNAL ERROR -- please report a bug at https://github.com/python/mypy/issues version: 0.510-dev-c856a53fe06c0ad9193d86ab35fb86693940f273-dirty Traceback (most recent call last): File "/Users/jukka/src/mypy/scripts/mypy", line 6, in <module> main(__file__) File "/Users/jukka/src/mypy/mypy/main.py", line 46, in main res = type_check_only(sources, bin_dir, options) File "/Users/jukka/src/mypy/mypy/main.py", line 93, in type_check_only options=options) File "/Users/jukka/src/mypy/mypy/build.py", line 188, in build graph = dispatch(sources, manager) File "/Users/jukka/src/mypy/mypy/build.py", line 1570, in dispatch process_graph(graph, manager) File "/Users/jukka/src/mypy/mypy/build.py", line 1813, in process_graph process_stale_scc(graph, scc, manager) File "/Users/jukka/src/mypy/mypy/build.py", line 1912, in process_stale_scc graph[id].type_check_first_pass() File "/Users/jukka/src/mypy/mypy/build.py", line 1485, in type_check_first_pass self.type_checker.check_first_pass() File "/Users/jukka/src/mypy/mypy/checker.py", line 177, in check_first_pass self.accept(d) File "/Users/jukka/src/mypy/mypy/checker.py", line 262, in accept stmt.accept(self) File "/Users/jukka/src/mypy/mypy/nodes.py", line 823, in accept return visitor.visit_expression_stmt(self) File "/Users/jukka/src/mypy/mypy/checker.py", line 1817, in visit_expression_stmt self.expr_checker.accept(s.expr, allow_none_return=True) File "/Users/jukka/src/mypy/mypy/checkexpr.py", line 2056, in accept typ = node.accept(self) File "/Users/jukka/src/mypy/mypy/nodes.py", line 1254, in accept return visitor.visit_member_expr(self) File "/Users/jukka/src/mypy/mypy/checkexpr.py", line 1010, in visit_member_expr result = self.analyze_ordinary_member_access(e, False) File "/Users/jukka/src/mypy/mypy/checkexpr.py", line 1025, in analyze_ordinary_member_access original_type=original_type, chk=self.chk) File "/Users/jukka/src/mypy/mypy/checkmember.py", line 74, in analyze_member_access method = info.get_method(name) AttributeError: 'NoneType' object has no attribute 'get_method' /Users/jukka/src/mypy/b.py:3: note: use --pdb to drop into pdb
AttributeError
def visit_instance(self, inst: Instance) -> None: # TODO: Combine Instances that are exactly the same? type_ref = inst.type_ref if type_ref is None: return # We've already been here. del inst.type_ref node = lookup_qualified(self.modules, type_ref, self.quick_and_dirty) if isinstance(node, TypeInfo): inst.type = node # TODO: Is this needed or redundant? # Also fix up the bases, just in case. for base in inst.type.bases: if base.type is NOT_READY: base.accept(self) else: # Looks like a missing TypeInfo in quick mode, put something there assert self.quick_and_dirty, "Should never get here in normal mode" inst.type = stale_info() for a in inst.args: a.accept(self)
def visit_instance(self, inst: Instance) -> None: # TODO: Combine Instances that are exactly the same? type_ref = inst.type_ref if type_ref is None: return # We've already been here. del inst.type_ref node = lookup_qualified(self.modules, type_ref, self.quick_and_dirty) if isinstance(node, TypeInfo): inst.type = node # TODO: Is this needed or redundant? # Also fix up the bases, just in case. for base in inst.type.bases: if base.type is NOT_READY: base.accept(self) for a in inst.args: a.accept(self)
https://github.com/python/mypy/issues/3278
$ mypy --quick --show-traceback a.py /Users/jukka/src/mypy/b.py:3: error: INTERNAL ERROR -- please report a bug at https://github.com/python/mypy/issues version: 0.510-dev-c856a53fe06c0ad9193d86ab35fb86693940f273-dirty Traceback (most recent call last): File "/Users/jukka/src/mypy/scripts/mypy", line 6, in <module> main(__file__) File "/Users/jukka/src/mypy/mypy/main.py", line 46, in main res = type_check_only(sources, bin_dir, options) File "/Users/jukka/src/mypy/mypy/main.py", line 93, in type_check_only options=options) File "/Users/jukka/src/mypy/mypy/build.py", line 188, in build graph = dispatch(sources, manager) File "/Users/jukka/src/mypy/mypy/build.py", line 1570, in dispatch process_graph(graph, manager) File "/Users/jukka/src/mypy/mypy/build.py", line 1813, in process_graph process_stale_scc(graph, scc, manager) File "/Users/jukka/src/mypy/mypy/build.py", line 1912, in process_stale_scc graph[id].type_check_first_pass() File "/Users/jukka/src/mypy/mypy/build.py", line 1485, in type_check_first_pass self.type_checker.check_first_pass() File "/Users/jukka/src/mypy/mypy/checker.py", line 177, in check_first_pass self.accept(d) File "/Users/jukka/src/mypy/mypy/checker.py", line 262, in accept stmt.accept(self) File "/Users/jukka/src/mypy/mypy/nodes.py", line 823, in accept return visitor.visit_expression_stmt(self) File "/Users/jukka/src/mypy/mypy/checker.py", line 1817, in visit_expression_stmt self.expr_checker.accept(s.expr, allow_none_return=True) File "/Users/jukka/src/mypy/mypy/checkexpr.py", line 2056, in accept typ = node.accept(self) File "/Users/jukka/src/mypy/mypy/nodes.py", line 1254, in accept return visitor.visit_member_expr(self) File "/Users/jukka/src/mypy/mypy/checkexpr.py", line 1010, in visit_member_expr result = self.analyze_ordinary_member_access(e, False) File "/Users/jukka/src/mypy/mypy/checkexpr.py", line 1025, in analyze_ordinary_member_access original_type=original_type, chk=self.chk) File "/Users/jukka/src/mypy/mypy/checkmember.py", line 74, in analyze_member_access method = info.get_method(name) AttributeError: 'NoneType' object has no attribute 'get_method' /Users/jukka/src/mypy/b.py:3: note: use --pdb to drop into pdb
AttributeError
def lookup_qualified_stnode( modules: Dict[str, MypyFile], name: str, quick_and_dirty: bool ) -> Optional[SymbolTableNode]: head = name rest = [] while True: if "." not in head: if not quick_and_dirty: assert "." in head, "Cannot find %s" % (name,) return None head, tail = head.rsplit(".", 1) rest.append(tail) mod = modules.get(head) if mod is not None: break names = mod.names while True: if not rest: if not quick_and_dirty: assert rest, "Cannot find %s" % (name,) return None key = rest.pop() if key not in names: if not quick_and_dirty: assert key in names, "Cannot find %s for %s" % (key, name) return None stnode = names[key] if not rest: return stnode node = stnode.node assert isinstance(node, TypeInfo) names = node.names
def lookup_qualified_stnode( modules: Dict[str, MypyFile], name: str, quick_and_dirty: bool ) -> Optional[SymbolTableNode]: head = name rest = [] while True: if "." not in head: if not quick_and_dirty: assert "." in head, "Cannot find %s" % (name,) return None head, tail = head.rsplit(".", 1) rest.append(tail) mod = modules.get(head) if mod is not None: break names = mod.names while True: if not rest: if not quick_and_dirty: assert rest, "Cannot find %s" % (name,) return None key = rest.pop() if key not in names: return None elif not quick_and_dirty: assert key in names, "Cannot find %s for %s" % (key, name) stnode = names[key] if not rest: return stnode node = stnode.node assert isinstance(node, TypeInfo) names = node.names
https://github.com/python/mypy/issues/3278
$ mypy --quick --show-traceback a.py /Users/jukka/src/mypy/b.py:3: error: INTERNAL ERROR -- please report a bug at https://github.com/python/mypy/issues version: 0.510-dev-c856a53fe06c0ad9193d86ab35fb86693940f273-dirty Traceback (most recent call last): File "/Users/jukka/src/mypy/scripts/mypy", line 6, in <module> main(__file__) File "/Users/jukka/src/mypy/mypy/main.py", line 46, in main res = type_check_only(sources, bin_dir, options) File "/Users/jukka/src/mypy/mypy/main.py", line 93, in type_check_only options=options) File "/Users/jukka/src/mypy/mypy/build.py", line 188, in build graph = dispatch(sources, manager) File "/Users/jukka/src/mypy/mypy/build.py", line 1570, in dispatch process_graph(graph, manager) File "/Users/jukka/src/mypy/mypy/build.py", line 1813, in process_graph process_stale_scc(graph, scc, manager) File "/Users/jukka/src/mypy/mypy/build.py", line 1912, in process_stale_scc graph[id].type_check_first_pass() File "/Users/jukka/src/mypy/mypy/build.py", line 1485, in type_check_first_pass self.type_checker.check_first_pass() File "/Users/jukka/src/mypy/mypy/checker.py", line 177, in check_first_pass self.accept(d) File "/Users/jukka/src/mypy/mypy/checker.py", line 262, in accept stmt.accept(self) File "/Users/jukka/src/mypy/mypy/nodes.py", line 823, in accept return visitor.visit_expression_stmt(self) File "/Users/jukka/src/mypy/mypy/checker.py", line 1817, in visit_expression_stmt self.expr_checker.accept(s.expr, allow_none_return=True) File "/Users/jukka/src/mypy/mypy/checkexpr.py", line 2056, in accept typ = node.accept(self) File "/Users/jukka/src/mypy/mypy/nodes.py", line 1254, in accept return visitor.visit_member_expr(self) File "/Users/jukka/src/mypy/mypy/checkexpr.py", line 1010, in visit_member_expr result = self.analyze_ordinary_member_access(e, False) File "/Users/jukka/src/mypy/mypy/checkexpr.py", line 1025, in analyze_ordinary_member_access original_type=original_type, chk=self.chk) File "/Users/jukka/src/mypy/mypy/checkmember.py", line 74, in analyze_member_access method = info.get_method(name) AttributeError: 'NoneType' object has no attribute 'get_method' /Users/jukka/src/mypy/b.py:3: note: use --pdb to drop into pdb
AttributeError
def __init__( self, typ: mypy.nodes.TypeInfo, args: List[Type], line: int = -1, column: int = -1, erased: bool = False, ) -> None: assert typ is NOT_READY or typ.fullname() not in ["builtins.Any", "typing.Any"] self.type = typ self.args = args self.erased = erased super().__init__(line, column)
def __init__( self, typ: mypy.nodes.TypeInfo, args: List[Type], line: int = -1, column: int = -1, erased: bool = False, ) -> None: assert typ is None or typ.fullname() not in ["builtins.Any", "typing.Any"] self.type = typ self.args = args self.erased = erased super().__init__(line, column)
https://github.com/python/mypy/issues/3278
$ mypy --quick --show-traceback a.py /Users/jukka/src/mypy/b.py:3: error: INTERNAL ERROR -- please report a bug at https://github.com/python/mypy/issues version: 0.510-dev-c856a53fe06c0ad9193d86ab35fb86693940f273-dirty Traceback (most recent call last): File "/Users/jukka/src/mypy/scripts/mypy", line 6, in <module> main(__file__) File "/Users/jukka/src/mypy/mypy/main.py", line 46, in main res = type_check_only(sources, bin_dir, options) File "/Users/jukka/src/mypy/mypy/main.py", line 93, in type_check_only options=options) File "/Users/jukka/src/mypy/mypy/build.py", line 188, in build graph = dispatch(sources, manager) File "/Users/jukka/src/mypy/mypy/build.py", line 1570, in dispatch process_graph(graph, manager) File "/Users/jukka/src/mypy/mypy/build.py", line 1813, in process_graph process_stale_scc(graph, scc, manager) File "/Users/jukka/src/mypy/mypy/build.py", line 1912, in process_stale_scc graph[id].type_check_first_pass() File "/Users/jukka/src/mypy/mypy/build.py", line 1485, in type_check_first_pass self.type_checker.check_first_pass() File "/Users/jukka/src/mypy/mypy/checker.py", line 177, in check_first_pass self.accept(d) File "/Users/jukka/src/mypy/mypy/checker.py", line 262, in accept stmt.accept(self) File "/Users/jukka/src/mypy/mypy/nodes.py", line 823, in accept return visitor.visit_expression_stmt(self) File "/Users/jukka/src/mypy/mypy/checker.py", line 1817, in visit_expression_stmt self.expr_checker.accept(s.expr, allow_none_return=True) File "/Users/jukka/src/mypy/mypy/checkexpr.py", line 2056, in accept typ = node.accept(self) File "/Users/jukka/src/mypy/mypy/nodes.py", line 1254, in accept return visitor.visit_member_expr(self) File "/Users/jukka/src/mypy/mypy/checkexpr.py", line 1010, in visit_member_expr result = self.analyze_ordinary_member_access(e, False) File "/Users/jukka/src/mypy/mypy/checkexpr.py", line 1025, in analyze_ordinary_member_access original_type=original_type, chk=self.chk) File "/Users/jukka/src/mypy/mypy/checkmember.py", line 74, in analyze_member_access method = info.get_method(name) AttributeError: 'NoneType' object has no attribute 'get_method' /Users/jukka/src/mypy/b.py:3: note: use --pdb to drop into pdb
AttributeError
def __init__(self, items: List["OverloadPart"]) -> None: assert len(items) > 0 self.items = items self.impl = None self.set_line(items[0].line)
def __init__(self, items: List["OverloadPart"]) -> None: self.items = items self.impl = None self.set_line(items[0].line)
https://github.com/python/mypy/issues/3333
# mypy --show-traceback test.py test.py:26: error: Name 'do_chain' already defined test.py:22: error: INTERNAL ERROR -- please report a bug at https://github.com/python/mypy/issues version: 0.510 Traceback (most recent call last): File "mypys", line 6, in <module> main(__file__) File "/tmp/mypy-0.510/mypy/main.py", line 46, in main res = type_check_only(sources, bin_dir, options) File "/tmp/mypy-0.510/mypy/main.py", line 93, in type_check_only options=options) File "/tmp/mypy-0.510/mypy/build.py", line 188, in build graph = dispatch(sources, manager) File "/tmp/mypy-0.510/mypy/build.py", line 1595, in dispatch process_graph(graph, manager) File "/tmp/mypy-0.510/mypy/build.py", line 1838, in process_graph process_stale_scc(graph, scc, manager) File "/tmp/mypy-0.510/mypy/build.py", line 1931, in process_stale_scc graph[id].semantic_analysis() File "/tmp/mypy-0.510/mypy/build.py", line 1495, in semantic_analysis self.manager.semantic_analyzer.visit_file(self.tree, self.xpath, self.options) File "/tmp/mypy-0.510/mypy/semanal.py", line 257, in visit_file self.accept(d) File "/tmp/mypy-0.510/mypy/semanal.py", line 3288, in accept node.accept(self) File "/tmp/mypy-0.510/mypy/nodes.py", line 749, in accept return visitor.visit_class_def(self) File "/tmp/mypy-0.510/mypy/semanal.py", line 620, in visit_class_def defn.defs.accept(self) File "/tmp/mypy-0.510/mypy/nodes.py", line 810, in accept return visitor.visit_block(self) File "/tmp/mypy-0.510/mypy/semanal.py", line 1375, in visit_block self.accept(s) File "/tmp/mypy-0.510/mypy/semanal.py", line 3288, in accept node.accept(self) File "/tmp/mypy-0.510/mypy/nodes.py", line 409, in accept return visitor.visit_overloaded_func_def(self) File "/tmp/mypy-0.510/mypy/semanal.py", line 516, in visit_overloaded_func_def typ=defn.type) File "/tmp/mypy-0.510/mypy/nodes.py", line 406, in name return self.items[0].name() IndexError: list index out of range test.py:22: note: use --pdb to drop into pdb
IndexError
def visit_overloaded_func_def(self, defn: OverloadedFuncDef) -> None: # OverloadedFuncDef refers to any legitimate situation where you have # more than one declaration for the same function in a row. This occurs # with a @property with a setter or a deleter, and for a classic # @overload. # Decide whether to analyze this as a property or an overload. If an # overload, and we're outside a stub, find the impl and set it. Remove # the impl from the item list, it's special. types = [] # type: List[CallableType] non_overload_indexes = [] # See if the first item is a property (and not an overload) first_item = defn.items[0] first_item.is_overload = True first_item.accept(self) if isinstance(first_item, Decorator) and first_item.func.is_property: first_item.func.is_overload = True self.analyze_property_with_multi_part_definition(defn) typ = function_type(first_item.func, self.builtin_type("builtins.function")) assert isinstance(typ, CallableType) types = [typ] else: for i, item in enumerate(defn.items): if i != 0: # The first item was already visited item.is_overload = True item.accept(self) # TODO support decorated overloaded functions properly if isinstance(item, Decorator): callable = function_type( item.func, self.builtin_type("builtins.function") ) assert isinstance(callable, CallableType) if not any( refers_to_fullname(dec, "typing.overload") for dec in item.decorators ): if i == len(defn.items) - 1 and not self.is_stub_file: # Last item outside a stub is impl defn.impl = item else: # Oops it wasn't an overload after all. A clear error # will vary based on where in the list it is, record # that. non_overload_indexes.append(i) else: item.func.is_overload = True types.append(callable) elif isinstance(item, FuncDef): if i == len(defn.items) - 1 and not self.is_stub_file: defn.impl = item else: non_overload_indexes.append(i) if non_overload_indexes: if types: # Some of them were overloads, but not all. for idx in non_overload_indexes: if self.is_stub_file: self.fail( "An implementation for an overloaded function " "is not allowed in a stub file", defn.items[idx], ) else: self.fail( "The implementation for an overloaded function " "must come last", defn.items[idx], ) else: for idx in non_overload_indexes[1:]: self.name_already_defined(defn.name(), defn.items[idx]) if defn.impl: self.name_already_defined(defn.name(), defn.impl) # Remove the non-overloads for idx in reversed(non_overload_indexes): del defn.items[idx] # If we found an implementation, remove it from the overloads to # consider. if defn.impl is not None: assert defn.impl is defn.items[-1] defn.items = defn.items[:-1] elif not self.is_stub_file and not non_overload_indexes: self.fail( "An overloaded function outside a stub file must have an implementation", defn, ) if types: defn.type = Overloaded(types) defn.type.line = defn.line if not defn.items: # It was not any kind of overload def after all. We've visited the # redfinitions already. return if self.is_class_scope(): self.type.names[defn.name()] = SymbolTableNode(MDEF, defn, typ=defn.type) defn.info = self.type elif self.is_func_scope(): self.add_local(defn, defn)
def visit_overloaded_func_def(self, defn: OverloadedFuncDef) -> None: # OverloadedFuncDef refers to any legitimate situation where you have # more than one declaration for the same function in a row. This occurs # with a @property with a setter or a deleter, and for a classic # @overload. # Decide whether to analyze this as a property or an overload. If an # overload, and we're outside a stub, find the impl and set it. Remove # the impl from the item list, it's special. types = [] # type: List[CallableType] non_overload_indexes = [] # See if the first item is a property (and not an overload) first_item = defn.items[0] first_item.is_overload = True first_item.accept(self) if isinstance(first_item, Decorator) and first_item.func.is_property: first_item.func.is_overload = True self.analyze_property_with_multi_part_definition(defn) typ = function_type(first_item.func, self.builtin_type("builtins.function")) assert isinstance(typ, CallableType) types = [typ] else: for i, item in enumerate(defn.items): if i != 0: # The first item was already visited item.is_overload = True item.accept(self) # TODO support decorated overloaded functions properly if isinstance(item, Decorator): callable = function_type( item.func, self.builtin_type("builtins.function") ) assert isinstance(callable, CallableType) if not any( refers_to_fullname(dec, "typing.overload") for dec in item.decorators ): if i == len(defn.items) - 1 and not self.is_stub_file: # Last item outside a stub is impl defn.impl = item else: # Oops it wasn't an overload after all. A clear error # will vary based on where in the list it is, record # that. non_overload_indexes.append(i) else: item.func.is_overload = True types.append(callable) elif isinstance(item, FuncDef): if i == len(defn.items) - 1 and not self.is_stub_file: defn.impl = item else: non_overload_indexes.append(i) if non_overload_indexes: if types: # Some of them were overloads, but not all. for idx in non_overload_indexes: if self.is_stub_file: self.fail( "An implementation for an overloaded function " "is not allowed in a stub file", defn.items[idx], ) else: self.fail( "The implementation for an overloaded function " "must come last", defn.items[idx], ) else: for idx in non_overload_indexes[1:]: self.name_already_defined(defn.name(), defn.items[idx]) if defn.impl: self.name_already_defined(defn.name(), defn.impl) # Remove the non-overloads for idx in reversed(non_overload_indexes): del defn.items[idx] # If we found an implementation, remove it from the overloads to # consider. if defn.impl is not None: assert defn.impl is defn.items[-1] defn.items = defn.items[:-1] elif not self.is_stub_file and not non_overload_indexes: self.fail( "An overloaded function outside a stub file must have an implementation", defn, ) if types: defn.type = Overloaded(types) defn.type.line = defn.line if self.is_class_scope(): self.type.names[defn.name()] = SymbolTableNode(MDEF, defn, typ=defn.type) defn.info = self.type elif self.is_func_scope(): self.add_local(defn, defn)
https://github.com/python/mypy/issues/3333
# mypy --show-traceback test.py test.py:26: error: Name 'do_chain' already defined test.py:22: error: INTERNAL ERROR -- please report a bug at https://github.com/python/mypy/issues version: 0.510 Traceback (most recent call last): File "mypys", line 6, in <module> main(__file__) File "/tmp/mypy-0.510/mypy/main.py", line 46, in main res = type_check_only(sources, bin_dir, options) File "/tmp/mypy-0.510/mypy/main.py", line 93, in type_check_only options=options) File "/tmp/mypy-0.510/mypy/build.py", line 188, in build graph = dispatch(sources, manager) File "/tmp/mypy-0.510/mypy/build.py", line 1595, in dispatch process_graph(graph, manager) File "/tmp/mypy-0.510/mypy/build.py", line 1838, in process_graph process_stale_scc(graph, scc, manager) File "/tmp/mypy-0.510/mypy/build.py", line 1931, in process_stale_scc graph[id].semantic_analysis() File "/tmp/mypy-0.510/mypy/build.py", line 1495, in semantic_analysis self.manager.semantic_analyzer.visit_file(self.tree, self.xpath, self.options) File "/tmp/mypy-0.510/mypy/semanal.py", line 257, in visit_file self.accept(d) File "/tmp/mypy-0.510/mypy/semanal.py", line 3288, in accept node.accept(self) File "/tmp/mypy-0.510/mypy/nodes.py", line 749, in accept return visitor.visit_class_def(self) File "/tmp/mypy-0.510/mypy/semanal.py", line 620, in visit_class_def defn.defs.accept(self) File "/tmp/mypy-0.510/mypy/nodes.py", line 810, in accept return visitor.visit_block(self) File "/tmp/mypy-0.510/mypy/semanal.py", line 1375, in visit_block self.accept(s) File "/tmp/mypy-0.510/mypy/semanal.py", line 3288, in accept node.accept(self) File "/tmp/mypy-0.510/mypy/nodes.py", line 409, in accept return visitor.visit_overloaded_func_def(self) File "/tmp/mypy-0.510/mypy/semanal.py", line 516, in visit_overloaded_func_def typ=defn.type) File "/tmp/mypy-0.510/mypy/nodes.py", line 406, in name return self.items[0].name() IndexError: list index out of range test.py:22: note: use --pdb to drop into pdb
IndexError
def analyze_namedtuple_classdef(self, defn: ClassDef) -> bool: # special case for NamedTuple for base_expr in defn.base_type_exprs: if isinstance(base_expr, RefExpr): base_expr.accept(self) if base_expr.fullname == "typing.NamedTuple": node = self.lookup(defn.name, defn) if node is not None: node.kind = ( GDEF # TODO in process_namedtuple_definition also applies here ) items, types, default_items = self.check_namedtuple_classdef(defn) node.node = self.build_namedtuple_typeinfo( defn.name, items, types, default_items ) # We only really need the assignments in the body to be type checked later; # attempting to type check methods may lead to crashes because NamedTuples # do not have a fully functional TypeInfo. # TODO remove this hack and add full support for NamedTuple methods defn.defs.body = [ stmt for stmt in defn.defs.body if isinstance(stmt, AssignmentStmt) ] return True return False
def analyze_namedtuple_classdef(self, defn: ClassDef) -> bool: # special case for NamedTuple for base_expr in defn.base_type_exprs: if isinstance(base_expr, RefExpr): base_expr.accept(self) if base_expr.fullname == "typing.NamedTuple": node = self.lookup(defn.name, defn) if node is not None: node.kind = ( GDEF # TODO in process_namedtuple_definition also applies here ) items, types, default_items = self.check_namedtuple_classdef(defn) node.node = self.build_namedtuple_typeinfo( defn.name, items, types, default_items ) return True return False
https://github.com/python/mypy/issues/3317
Traceback (most recent call last): File "/Users/daenyth/Curata/observer/.tox/mypy/bin/mypy", line 6, in <module> main(__file__) File "/Users/daenyth/Curata/observer/.tox/mypy/lib/python3.6/site-packages/mypy/main.py", line 46, in main res = type_check_only(sources, bin_dir, options) File "/Users/daenyth/Curata/observer/.tox/mypy/lib/python3.6/site-packages/mypy/main.py", line 93, in type_check_only options=options) File "/Users/daenyth/Curata/observer/.tox/mypy/lib/python3.6/site-packages/mypy/build.py", line 188, in build graph = dispatch(sources, manager) File "/Users/daenyth/Curata/observer/.tox/mypy/lib/python3.6/site-packages/mypy/build.py", line 1595, in dispatch process_graph(graph, manager) File "/Users/daenyth/Curata/observer/.tox/mypy/lib/python3.6/site-packages/mypy/build.py", line 1838, in process_graph process_stale_scc(graph, scc, manager) File "/Users/daenyth/Curata/observer/.tox/mypy/lib/python3.6/site-packages/mypy/build.py", line 1937, in process_stale_scc graph[id].type_check_first_pass() File "/Users/daenyth/Curata/observer/.tox/mypy/lib/python3.6/site-packages/mypy/build.py", line 1510, in type_check_first_pass self.type_checker.check_first_pass() File "/Users/daenyth/Curata/observer/.tox/mypy/lib/python3.6/site-packages/mypy/checker.py", line 177, in check_first_pass self.accept(d) File "/Users/daenyth/Curata/observer/.tox/mypy/lib/python3.6/site-packages/mypy/checker.py", line 264, in accept stmt.accept(self) File "/Users/daenyth/Curata/observer/.tox/mypy/lib/python3.6/site-packages/mypy/nodes.py", line 749, in accept return visitor.visit_class_def(self) File "/Users/daenyth/Curata/observer/.tox/mypy/lib/python3.6/site-packages/mypy/checker.py", line 1080, in visit_class_def self.accept(defn.defs) File "/Users/daenyth/Curata/observer/.tox/mypy/lib/python3.6/site-packages/mypy/checker.py", line 264, in accept stmt.accept(self) File "/Users/daenyth/Curata/observer/.tox/mypy/lib/python3.6/site-packages/mypy/nodes.py", line 810, in accept return visitor.visit_block(self) File "/Users/daenyth/Curata/observer/.tox/mypy/lib/python3.6/site-packages/mypy/checker.py", line 1173, in visit_block self.accept(s) File "/Users/daenyth/Curata/observer/.tox/mypy/lib/python3.6/site-packages/mypy/checker.py", line 264, in accept stmt.accept(self) File "/Users/daenyth/Curata/observer/.tox/mypy/lib/python3.6/site-packages/mypy/nodes.py", line 631, in accept return visitor.visit_decorator(self) File "/Users/daenyth/Curata/observer/.tox/mypy/lib/python3.6/site-packages/mypy/checker.py", line 2213, in visit_decorator e.func.accept(self) File "/Users/daenyth/Curata/observer/.tox/mypy/lib/python3.6/site-packages/mypy/nodes.py", line 564, in accept return visitor.visit_func_def(self) File "/Users/daenyth/Curata/observer/.tox/mypy/lib/python3.6/site-packages/mypy/checker.py", line 513, in visit_func_def self.check_method_override(defn) File "/Users/daenyth/Curata/observer/.tox/mypy/lib/python3.6/site-packages/mypy/checker.py", line 945, in check_method_override for base in defn.info.mro[1:]: TypeError: 'NoneType' object is not subscriptable
TypeError
def build_namedtuple_typeinfo( self, name: str, items: List[str], types: List[Type], default_items: Dict[str, Expression], ) -> TypeInfo: strtype = self.str_type() basetuple_type = self.named_type("__builtins__.tuple", [AnyType()]) dictype = ( self.named_type_or_none("builtins.dict", [strtype, AnyType()]) or self.object_type() ) # Actual signature should return OrderedDict[str, Union[types]] ordereddictype = ( self.named_type_or_none("builtins.dict", [strtype, AnyType()]) or self.object_type() ) # 'builtins.tuple' has only one type parameter. # # TODO: The corresponding type argument in the fallback instance should be a join of # all item types, but we can't do joins during this pass of semantic analysis # and we are using Any as a workaround. fallback = self.named_type("__builtins__.tuple", [AnyType()]) # Note: actual signature should accept an invariant version of Iterable[UnionType[types]]. # but it can't be expressed. 'new' and 'len' should be callable types. iterable_type = self.named_type_or_none("typing.Iterable", [AnyType()]) function_type = self.named_type("__builtins__.function") info = self.basic_new_typeinfo(name, fallback) info.is_named_tuple = True info.tuple_type = TupleType(types, fallback) def add_field( var: Var, is_initialized_in_class: bool = False, is_property: bool = False ) -> None: var.info = info var.is_initialized_in_class = is_initialized_in_class var.is_property = is_property info.names[var.name()] = SymbolTableNode(MDEF, var) vars = [Var(item, typ) for item, typ in zip(items, types)] for var in vars: add_field(var, is_property=True) tuple_of_strings = TupleType([strtype for _ in items], basetuple_type) add_field(Var("_fields", tuple_of_strings), is_initialized_in_class=True) add_field(Var("_field_types", dictype), is_initialized_in_class=True) add_field(Var("_field_defaults", dictype), is_initialized_in_class=True) add_field(Var("_source", strtype), is_initialized_in_class=True) tvd = TypeVarDef("NT", 1, [], info.tuple_type) selftype = TypeVarType(tvd) def add_method( funcname: str, ret: Type, args: List[Argument], name: str = None, is_classmethod: bool = False, ) -> None: if is_classmethod: first = [Argument(Var("cls"), TypeType(selftype), None, ARG_POS)] else: first = [Argument(Var("self"), selftype, None, ARG_POS)] args = first + args types = [arg.type_annotation for arg in args] items = [arg.variable.name() for arg in args] arg_kinds = [arg.kind for arg in args] signature = CallableType( types, arg_kinds, items, ret, function_type, name=name or info.name() + "." + funcname, ) signature.variables = [tvd] func = FuncDef(funcname, args, Block([]), typ=signature) func.info = info func.is_class = is_classmethod if is_classmethod: v = Var(funcname, signature) v.is_classmethod = True v.info = info dec = Decorator(func, [NameExpr("classmethod")], v) info.names[funcname] = SymbolTableNode(MDEF, dec) else: info.names[funcname] = SymbolTableNode(MDEF, func) add_method( "_replace", ret=selftype, args=[Argument(var, var.type, EllipsisExpr(), ARG_NAMED_OPT) for var in vars], ) def make_init_arg(var: Var) -> Argument: default = default_items.get(var.name(), None) kind = ARG_POS if default is None else ARG_OPT return Argument(var, var.type, default, kind) add_method( "__init__", ret=NoneTyp(), name=info.name(), args=[make_init_arg(var) for var in vars], ) add_method("_asdict", args=[], ret=ordereddictype) add_method( "_make", ret=selftype, is_classmethod=True, args=[ Argument(Var("iterable", iterable_type), iterable_type, None, ARG_POS), Argument(Var("new"), AnyType(), EllipsisExpr(), ARG_NAMED_OPT), Argument(Var("len"), AnyType(), EllipsisExpr(), ARG_NAMED_OPT), ], ) return info
def build_namedtuple_typeinfo( self, name: str, items: List[str], types: List[Type], default_items: Dict[str, Expression], ) -> TypeInfo: strtype = self.str_type() basetuple_type = self.named_type("__builtins__.tuple", [AnyType()]) dictype = ( self.named_type_or_none("builtins.dict", [strtype, AnyType()]) or self.object_type() ) # Actual signature should return OrderedDict[str, Union[types]] ordereddictype = ( self.named_type_or_none("builtins.dict", [strtype, AnyType()]) or self.object_type() ) # 'builtins.tuple' has only one type parameter, the corresponding type argument # in the fallback instance is a join of all item types. fallback = self.named_type("__builtins__.tuple", [join.join_type_list(types)]) # Note: actual signature should accept an invariant version of Iterable[UnionType[types]]. # but it can't be expressed. 'new' and 'len' should be callable types. iterable_type = self.named_type_or_none("typing.Iterable", [AnyType()]) function_type = self.named_type("__builtins__.function") info = self.basic_new_typeinfo(name, fallback) info.is_named_tuple = True info.tuple_type = TupleType(types, fallback) def add_field( var: Var, is_initialized_in_class: bool = False, is_property: bool = False ) -> None: var.info = info var.is_initialized_in_class = is_initialized_in_class var.is_property = is_property info.names[var.name()] = SymbolTableNode(MDEF, var) vars = [Var(item, typ) for item, typ in zip(items, types)] for var in vars: add_field(var, is_property=True) tuple_of_strings = TupleType([strtype for _ in items], basetuple_type) add_field(Var("_fields", tuple_of_strings), is_initialized_in_class=True) add_field(Var("_field_types", dictype), is_initialized_in_class=True) add_field(Var("_field_defaults", dictype), is_initialized_in_class=True) add_field(Var("_source", strtype), is_initialized_in_class=True) tvd = TypeVarDef("NT", 1, [], info.tuple_type) selftype = TypeVarType(tvd) def add_method( funcname: str, ret: Type, args: List[Argument], name: str = None, is_classmethod: bool = False, ) -> None: if is_classmethod: first = [Argument(Var("cls"), TypeType(selftype), None, ARG_POS)] else: first = [Argument(Var("self"), selftype, None, ARG_POS)] args = first + args types = [arg.type_annotation for arg in args] items = [arg.variable.name() for arg in args] arg_kinds = [arg.kind for arg in args] signature = CallableType( types, arg_kinds, items, ret, function_type, name=name or info.name() + "." + funcname, ) signature.variables = [tvd] func = FuncDef(funcname, args, Block([]), typ=signature) func.info = info func.is_class = is_classmethod if is_classmethod: v = Var(funcname, signature) v.is_classmethod = True v.info = info dec = Decorator(func, [NameExpr("classmethod")], v) info.names[funcname] = SymbolTableNode(MDEF, dec) else: info.names[funcname] = SymbolTableNode(MDEF, func) add_method( "_replace", ret=selftype, args=[Argument(var, var.type, EllipsisExpr(), ARG_NAMED_OPT) for var in vars], ) def make_init_arg(var: Var) -> Argument: default = default_items.get(var.name(), None) kind = ARG_POS if default is None else ARG_OPT return Argument(var, var.type, default, kind) add_method( "__init__", ret=NoneTyp(), name=info.name(), args=[make_init_arg(var) for var in vars], ) add_method("_asdict", args=[], ret=ordereddictype) add_method( "_make", ret=selftype, is_classmethod=True, args=[ Argument(Var("iterable", iterable_type), iterable_type, None, ARG_POS), Argument(Var("new"), AnyType(), EllipsisExpr(), ARG_NAMED_OPT), Argument(Var("len"), AnyType(), EllipsisExpr(), ARG_NAMED_OPT), ], ) return info
https://github.com/python/mypy/issues/3315
(venv) jelle@devjelle:~/mypy$ cat testnt.py from typing import NamedTuple class A(NamedTuple): b: 'B' x: int class B: pass (venv) jelle@devjelle:~/mypy$ python -m mypy --show-traceback testnt.py testnt.py:3: error: INTERNAL ERROR -- please report a bug at https://github.com/python/mypy/issues version: 0.510-dev-09e7b124b82dae1207d9eac6805b64a98290015c Traceback (most recent call last): File "/home/jelle/ans/venv64/lib/python3.6/runpy.py", line 193, in _run_module_as_main "__main__", mod_spec) File "/home/jelle/ans/venv64/lib/python3.6/runpy.py", line 85, in _run_code exec(code, run_globals) File "/home/jelle/mypy/venv/lib/python3.6/site-packages/mypy/__main__.py", line 5, in <module> main(None) File "/home/jelle/mypy/venv/lib/python3.6/site-packages/mypy/main.py", line 46, in main res = type_check_only(sources, bin_dir, options) File "/home/jelle/mypy/venv/lib/python3.6/site-packages/mypy/main.py", line 93, in type_check_only options=options) File "/home/jelle/mypy/venv/lib/python3.6/site-packages/mypy/build.py", line 188, in build graph = dispatch(sources, manager) File "/home/jelle/mypy/venv/lib/python3.6/site-packages/mypy/build.py", line 1595, in dispatch process_graph(graph, manager) File "/home/jelle/mypy/venv/lib/python3.6/site-packages/mypy/build.py", line 1838, in process_graph process_stale_scc(graph, scc, manager) File "/home/jelle/mypy/venv/lib/python3.6/site-packages/mypy/build.py", line 1931, in process_stale_scc graph[id].semantic_analysis() File "/home/jelle/mypy/venv/lib/python3.6/site-packages/mypy/build.py", line 1495, in semantic_analysis self.manager.semantic_analyzer.visit_file(self.tree, self.xpath, self.options) File "/home/jelle/mypy/venv/lib/python3.6/site-packages/mypy/semanal.py", line 257, in visit_file self.accept(d) File "/home/jelle/mypy/venv/lib/python3.6/site-packages/mypy/semanal.py", line 3279, in accept node.accept(self) File "/home/jelle/mypy/venv/lib/python3.6/site-packages/mypy/nodes.py", line 749, in accept return visitor.visit_class_def(self) File "/home/jelle/mypy/venv/lib/python3.6/site-packages/mypy/semanal.py", line 617, in visit_class_def with self.analyze_class_body(defn) as should_continue: File "/home/jelle/ans/venv64/lib/python3.6/contextlib.py", line 82, in __enter__ return next(self.gen) File "/home/jelle/mypy/venv/lib/python3.6/site-packages/mypy/semanal.py", line 629, in analyze_class_body if self.analyze_namedtuple_classdef(defn): File "/home/jelle/mypy/venv/lib/python3.6/site-packages/mypy/semanal.py", line 819, in analyze_namedtuple_classdef defn.name, items, types, default_items) File "/home/jelle/mypy/venv/lib/python3.6/site-packages/mypy/semanal.py", line 2053, in build_namedtuple_typeinfo fallback = self.named_type('__builtins__.tuple', [join.join_type_list(types)]) File "/home/jelle/mypy/venv/lib/python3.6/site-packages/mypy/join.py", line 388, in join_type_list joined = join_types(joined, t) File "/home/jelle/mypy/venv/lib/python3.6/site-packages/mypy/join.py", line 88, in join_types return t.accept(TypeJoinVisitor(s)) File "/home/jelle/mypy/venv/lib/python3.6/site-packages/mypy/types.py", line 411, in accept return visitor.visit_instance(self) File "/home/jelle/mypy/venv/lib/python3.6/site-packages/mypy/join.py", line 141, in visit_instance return join_instances(t, self.s) File "/home/jelle/mypy/venv/lib/python3.6/site-packages/mypy/join.py", line 295, in join_instances return join_instances_via_supertype(s, t) File "/home/jelle/mypy/venv/lib/python3.6/site-packages/mypy/join.py", line 314, in join_instances_via_supertype assert best is not None AssertionError: testnt.py:3: note: use --pdb to drop into pdb
AssertionError
def infer_partial_type(self, name: Var, lvalue: Lvalue, init_type: Type) -> bool: if isinstance(init_type, (NoneTyp, UninhabitedType)): partial_type = PartialType(None, name, [init_type]) elif isinstance(init_type, Instance): fullname = init_type.type.fullname() if ( isinstance(lvalue, (NameExpr, MemberExpr)) and ( fullname == "builtins.list" or fullname == "builtins.set" or fullname == "builtins.dict" ) and all(isinstance(t, (NoneTyp, UninhabitedType)) for t in init_type.args) ): partial_type = PartialType(init_type.type, name, init_type.args) else: return False else: return False self.set_inferred_type(name, lvalue, partial_type) self.partial_types[-1][name] = lvalue return True
def infer_partial_type(self, name: Var, lvalue: Lvalue, init_type: Type) -> bool: if isinstance(init_type, (NoneTyp, UninhabitedType)): partial_type = PartialType(None, name, [init_type]) elif isinstance(init_type, Instance): fullname = init_type.type.fullname() if ( isinstance(lvalue, NameExpr) and ( fullname == "builtins.list" or fullname == "builtins.set" or fullname == "builtins.dict" ) and all(isinstance(t, (NoneTyp, UninhabitedType)) for t in init_type.args) ): partial_type = PartialType(init_type.type, name, init_type.args) else: return False else: return False self.set_inferred_type(name, lvalue, partial_type) self.partial_types[-1][name] = lvalue return True
https://github.com/python/mypy/issues/2998
myfile.py:270: error: INTERNAL ERROR -- please report a bug at https://github.com/python/mypy/issues Traceback (most recent call last): File "/usr/lib/python3.4/runpy.py", line 170, in _run_module_as_main "__main__", mod_spec) File "/usr/lib/python3.4/runpy.py", line 85, in _run_code exec(code, run_globals) File "/usr/local/lib/python3.4/dist-packages/mypy/__main__.py", line 5, in <module> main(None) File "/usr/local/lib/python3.4/dist-packages/mypy/main.py", line 42, in main res = type_check_only(sources, bin_dir, options) File "/usr/local/lib/python3.4/dist-packages/mypy/main.py", line 86, in type_check_only options=options) File "/usr/local/lib/python3.4/dist-packages/mypy/build.py", line 183, in build dispatch(sources, manager) File "/usr/local/lib/python3.4/dist-packages/mypy/build.py", line 1531, in dispatch process_graph(graph, manager) File "/usr/local/lib/python3.4/dist-packages/mypy/build.py", line 1768, in process_graph process_stale_scc(graph, scc) File "/usr/local/lib/python3.4/dist-packages/mypy/build.py", line 1847, in process_stale_scc graph[id].type_check_first_pass() File "/usr/local/lib/python3.4/dist-packages/mypy/build.py", line 1453, in type_check_first_pass self.type_checker.check_first_pass() File "/usr/local/lib/python3.4/dist-packages/mypy/checker.py", line 167, in check_first_pass self.accept(d) File "/usr/local/lib/python3.4/dist-packages/mypy/checker.py", line 233, in accept stmt.accept(self) File "/usr/local/lib/python3.4/dist-packages/mypy/nodes.py", line 717, in accept return visitor.visit_class_def(self) File "/usr/local/lib/python3.4/dist-packages/mypy/checker.py", line 970, in visit_class_def self.accept(defn.defs) File "/usr/local/lib/python3.4/dist-packages/mypy/checker.py", line 233, in accept stmt.accept(self) File "/usr/local/lib/python3.4/dist-packages/mypy/nodes.py", line 778, in accept return visitor.visit_block(self) File "/usr/local/lib/python3.4/dist-packages/mypy/checker.py", line 1063, in visit_block self.accept(s) File "/usr/local/lib/python3.4/dist-packages/mypy/checker.py", line 233, in accept stmt.accept(self) File "/usr/local/lib/python3.4/dist-packages/mypy/nodes.py", line 601, in accept return visitor.visit_decorator(self) File "/usr/local/lib/python3.4/dist-packages/mypy/checker.py", line 2052, in visit_decorator e.func.accept(self) File "/usr/local/lib/python3.4/dist-packages/mypy/nodes.py", line 536, in accept return visitor.visit_func_def(self) File "/usr/local/lib/python3.4/dist-packages/mypy/checker.py", line 425, in visit_func_def self.check_method_override(defn) File "/usr/local/lib/python3.4/dist-packages/mypy/checker.py", line 836, in check_method_override self.check_method_or_accessor_override_for_base(defn, base) File "/usr/local/lib/python3.4/dist-packages/mypy/checker.py", line 846, in check_method_or_accessor_override_for_base self.check_method_override_for_base_with_name(defn, name, base) File "/usr/local/lib/python3.4/dist-packages/mypy/checker.py", line 874, in check_method_override_for_base_with_name assert False, str(base_attr.node) AssertionError: Var(config)
AssertionError
def analyze_super(self, e: SuperExpr, is_lvalue: bool) -> Type: """Type check a super expression.""" if e.info and e.info.bases: # TODO fix multiple inheritance etc if len(e.info.mro) < 2: self.chk.fail( "Internal error: unexpected mro for {}: {}".format( e.info.name(), e.info.mro ), e, ) return AnyType() for base in e.info.mro[1:]: if e.name in base.names or base == e.info.mro[-1]: if e.info.fallback_to_any and base == e.info.mro[-1]: # There's an undefined base class, and we're # at the end of the chain. That's not an error. return AnyType() if not self.chk.in_checked_function(): return AnyType() if self.chk.scope.active_class() is not None: self.chk.fail("super() outside of a method is not supported", e) return AnyType() args = self.chk.scope.top_function().arguments # An empty args with super() is an error; we need something in declared_self if not args: self.chk.fail( "super() requires at least one positional argument", e ) return AnyType() declared_self = args[0].variable.type return analyze_member_access( name=e.name, typ=fill_typevars(e.info), node=e, is_lvalue=False, is_super=True, is_operator=False, builtin_type=self.named_type, not_ready_callback=self.not_ready_callback, msg=self.msg, override_info=base, original_type=declared_self, chk=self.chk, ) assert False, "unreachable" else: # Invalid super. This has been reported by the semantic analyzer. return AnyType()
def analyze_super(self, e: SuperExpr, is_lvalue: bool) -> Type: """Type check a super expression.""" if e.info and e.info.bases: # TODO fix multiple inheritance etc if len(e.info.mro) < 2: self.chk.fail( "Internal error: unexpected mro for {}: {}".format( e.info.name(), e.info.mro ), e, ) return AnyType() for base in e.info.mro[1:]: if e.name in base.names or base == e.info.mro[-1]: if e.info.fallback_to_any and base == e.info.mro[-1]: # There's an undefined base class, and we're # at the end of the chain. That's not an error. return AnyType() if not self.chk.in_checked_function(): return AnyType() args = self.chk.scope.top_function().arguments # An empty args with super() is an error; we need something in declared_self if not args: self.chk.fail( "super() requires at least one positional argument", e ) return AnyType() declared_self = args[0].variable.type return analyze_member_access( name=e.name, typ=fill_typevars(e.info), node=e, is_lvalue=False, is_super=True, is_operator=False, builtin_type=self.named_type, not_ready_callback=self.not_ready_callback, msg=self.msg, override_info=base, original_type=declared_self, chk=self.chk, ) assert False, "unreachable" else: # Invalid super. This has been reported by the semantic analyzer. return AnyType()
https://github.com/python/mypy/issues/2848
Traceback (most recent call last): File "/usr/local/bin/mypy", line 6, in <module> main(__file__) File "/usr/local/lib/python3.4/dist-packages/mypy/main.py", line 42, in main res = type_check_only(sources, bin_dir, options) File "/usr/local/lib/python3.4/dist-packages/mypy/main.py", line 86, in type_check_only options=options) File "/usr/local/lib/python3.4/dist-packages/mypy/build.py", line 183, in build dispatch(sources, manager) File "/usr/local/lib/python3.4/dist-packages/mypy/build.py", line 1531, in dispatch process_graph(graph, manager) File "/usr/local/lib/python3.4/dist-packages/mypy/build.py", line 1768, in process_graph process_stale_scc(graph, scc) File "/usr/local/lib/python3.4/dist-packages/mypy/build.py", line 1847, in process_stale_scc graph[id].type_check_first_pass() File "/usr/local/lib/python3.4/dist-packages/mypy/build.py", line 1453, in type_check_first_pass self.type_checker.check_first_pass() File "/usr/local/lib/python3.4/dist-packages/mypy/checker.py", line 167, in check_first_pass self.accept(d) File "/usr/local/lib/python3.4/dist-packages/mypy/checker.py", line 233, in accept stmt.accept(self) File "/usr/local/lib/python3.4/dist-packages/mypy/nodes.py", line 717, in accept return visitor.visit_class_def(self) File "/usr/local/lib/python3.4/dist-packages/mypy/checker.py", line 964, in visit_class_def self.accept(defn.defs) File "/usr/local/lib/python3.4/dist-packages/mypy/checker.py", line 233, in accept stmt.accept(self) File "/usr/local/lib/python3.4/dist-packages/mypy/nodes.py", line 778, in accept return visitor.visit_block(self) File "/usr/local/lib/python3.4/dist-packages/mypy/checker.py", line 1057, in visit_block self.accept(s) File "/usr/local/lib/python3.4/dist-packages/mypy/checker.py", line 233, in accept stmt.accept(self) File "/usr/local/lib/python3.4/dist-packages/mypy/nodes.py", line 819, in accept return visitor.visit_assignment_stmt(self) File "/usr/local/lib/python3.4/dist-packages/mypy/checker.py", line 1064, in visit_assignment_stmt self.check_assignment(s.lvalues[-1], s.rvalue, s.type is None, s.new_syntax) File "/usr/local/lib/python3.4/dist-packages/mypy/checker.py", line 1140, in check_assignment self.infer_variable_type(inferred, lvalue, self.expr_checker.accept(rvalue), File "/usr/local/lib/python3.4/dist-packages/mypy/checkexpr.py", line 2015, in accept typ = node.accept(self) File "/usr/local/lib/python3.4/dist-packages/mypy/nodes.py", line 1492, in accept return visitor.visit_super_expr(self) File "/usr/local/lib/python3.4/dist-packages/mypy/checkexpr.py", line 1835, in visit_super_expr t = self.analyze_super(e, False) File "/usr/local/lib/python3.4/dist-packages/mypy/checkexpr.py", line 1854, in analyze_super args = self.chk.scope.top_function().arguments AttributeError: 'NoneType' object has no attribute 'arguments'
AttributeError
def add_ancestors(self) -> None: if self.path is not None: _, name = os.path.split(self.path) base, _ = os.path.splitext(name) if "." in base: # This is just a weird filename, don't add anything self.ancestors = [] return # All parent packages are new ancestors. ancestors = [] parent = self.id while "." in parent: parent, _ = parent.rsplit(".", 1) ancestors.append(parent) self.ancestors = ancestors
def add_ancestors(self) -> None: # All parent packages are new ancestors. ancestors = [] parent = self.id while "." in parent: parent, _ = parent.rsplit(".", 1) ancestors.append(parent) self.ancestors = ancestors
https://github.com/python/mypy/issues/2558
Traceback (most recent call last): File "/usr/local/lib/python3.6/runpy.py", line 193, in _run_module_as_main "__main__", mod_spec) File "/usr/local/lib/python3.6/runpy.py", line 85, in _run_code exec(code, run_globals) File "/Users/guido/src/mypy/mypy/__main__.py", line 5, in <module> main(None) File "/Users/guido/src/mypy/mypy/main.py", line 38, in main sources, options = process_options(sys.argv[1:]) File "/Users/guido/src/mypy/mypy/main.py", line 364, in process_options targets.append(BuildSource(f, crawl_up(f)[1], None)) File "/Users/guido/src/mypy/mypy/main.py", line 429, in crawl_up assert '.' not in mod AssertionError
AssertionError
def crawl_up(arg: str) -> Tuple[str, str]: """Given a .py[i] filename, return (root directory, module). We crawl up the path until we find a directory without __init__.py[i], or until we run out of path components. """ dir, mod = os.path.split(arg) mod = strip_py(mod) or mod while dir and get_init_file(dir): dir, base = os.path.split(dir) if not base: break if mod == "__init__" or not mod: mod = base else: mod = base + "." + mod return dir, mod
def crawl_up(arg: str) -> Tuple[str, str]: """Given a .py[i] filename, return (root directory, module). We crawl up the path until we find a directory without __init__.py[i], or until we run out of path components. """ dir, mod = os.path.split(arg) mod = strip_py(mod) or mod assert "." not in mod while dir and get_init_file(dir): dir, base = os.path.split(dir) if not base: break if mod == "__init__" or not mod: mod = base else: mod = base + "." + mod return dir, mod
https://github.com/python/mypy/issues/2558
Traceback (most recent call last): File "/usr/local/lib/python3.6/runpy.py", line 193, in _run_module_as_main "__main__", mod_spec) File "/usr/local/lib/python3.6/runpy.py", line 85, in _run_code exec(code, run_globals) File "/Users/guido/src/mypy/mypy/__main__.py", line 5, in <module> main(None) File "/Users/guido/src/mypy/mypy/main.py", line 38, in main sources, options = process_options(sys.argv[1:]) File "/Users/guido/src/mypy/mypy/main.py", line 364, in process_options targets.append(BuildSource(f, crawl_up(f)[1], None)) File "/Users/guido/src/mypy/mypy/main.py", line 429, in crawl_up assert '.' not in mod AssertionError
AssertionError
def main(script_path: str) -> None: """Main entry point to the type checker. Args: script_path: Path to the 'mypy' script (used for finding data files). """ t0 = time.time() if script_path: bin_dir = find_bin_directory(script_path) else: bin_dir = None sys.setrecursionlimit(2**14) sources, options = process_options(sys.argv[1:]) serious = False try: res = type_check_only(sources, bin_dir, options) a = res.errors except CompileError as e: a = e.messages if not e.use_stdout: serious = True if options.junit_xml: t1 = time.time() util.write_junit_xml(t1 - t0, serious, a, options.junit_xml) if a: f = sys.stderr if serious else sys.stdout try: for m in a: f.write(m + "\n") except BrokenPipeError: pass sys.exit(1)
def main(script_path: str) -> None: """Main entry point to the type checker. Args: script_path: Path to the 'mypy' script (used for finding data files). """ t0 = time.time() if script_path: bin_dir = find_bin_directory(script_path) else: bin_dir = None sys.setrecursionlimit(2**14) sources, options = process_options(sys.argv[1:]) serious = False try: res = type_check_only(sources, bin_dir, options) a = res.errors except CompileError as e: a = e.messages if not e.use_stdout: serious = True if options.junit_xml: t1 = time.time() util.write_junit_xml(t1 - t0, serious, a, options.junit_xml) if a: f = sys.stderr if serious else sys.stdout for m in a: f.write(m + "\n") sys.exit(1)
https://github.com/python/mypy/issues/2893
Traceback (most recent call last): File "/home/.../bin/mypy", line 6, in <module> main(__file__) File "/home/.../lib/python3.5/site-packages/mypy/main.py", line 53, in main f.write(m + '\n') BrokenPipeError: [Errno 32] Broken pipe
BrokenPipeError
def setup_class_def_analysis(self, defn: ClassDef) -> None: """Prepare for the analysis of a class definition.""" if not defn.info: defn.info = TypeInfo(SymbolTable(), defn, self.cur_mod_id) defn.info._fullname = defn.info.name() if self.is_func_scope() or self.type: kind = MDEF if self.is_func_scope(): kind = LDEF node = SymbolTableNode(kind, defn.info) self.add_symbol(defn.name, node, defn) if kind == LDEF: # We need to preserve local classes, let's store them # in globals under mangled unique names local_name = defn.info._fullname + "@" + str(defn.line) defn.info._fullname = self.cur_mod_id + "." + local_name defn.fullname = defn.info._fullname self.globals[local_name] = node
def setup_class_def_analysis(self, defn: ClassDef) -> None: """Prepare for the analysis of a class definition.""" if not defn.info: defn.info = TypeInfo(SymbolTable(), defn, self.cur_mod_id) defn.info._fullname = defn.info.name() if self.is_func_scope() or self.type: kind = MDEF if self.is_func_scope(): kind = LDEF self.add_symbol(defn.name, SymbolTableNode(kind, defn.info), defn)
https://github.com/python/mypy/issues/2559
$ rm -rf .mypy_cache/ $ mypy -i main.py main.py:1: error: Name 'blah' is not defined $ mypy -i main.py Traceback (most recent call last): File "/usr/local/lib/python3.6/runpy.py", line 193, in _run_module_as_main "__main__", mod_spec) File "/usr/local/lib/python3.6/runpy.py", line 85, in _run_code exec(code, run_globals) File "/Users/guido/src/mypy/mypy/__main__.py", line 5, in <module> main(None) File "/Users/guido/src/mypy/mypy/main.py", line 41, in main res = type_check_only(sources, bin_dir, options) File "/Users/guido/src/mypy/mypy/main.py", line 86, in type_check_only options=options) File "/Users/guido/src/mypy/mypy/build.py", line 183, in build dispatch(sources, manager) File "/Users/guido/src/mypy/mypy/build.py", line 1524, in dispatch process_graph(graph, manager) File "/Users/guido/src/mypy/mypy/build.py", line 1753, in process_graph process_fresh_scc(graph, prev_scc) File "/Users/guido/src/mypy/mypy/build.py", line 1822, in process_fresh_scc graph[id].fix_cross_refs() File "/Users/guido/src/mypy/mypy/build.py", line 1307, in fix_cross_refs fixup_module_pass_one(self.tree, self.manager.modules) File "/Users/guido/src/mypy/mypy/fixup.py", line 21, in fixup_module_pass_one node_fixer.visit_symbol_table(tree.names) File "/Users/guido/src/mypy/mypy/fixup.py", line 86, in visit_symbol_table self.visit_type_info(value.node) File "/Users/guido/src/mypy/mypy/fixup.py", line 55, in visit_type_info self.visit_symbol_table(info.names) File "/Users/guido/src/mypy/mypy/fixup.py", line 88, in visit_symbol_table value.node.accept(self) File "/Users/guido/src/mypy/mypy/nodes.py", line 658, in accept return visitor.visit_var(self) File "/Users/guido/src/mypy/mypy/fixup.py", line 131, in visit_var v.type.accept(self.type_fixer) File "/Users/guido/src/mypy/mypy/types.py", line 433, in accept return visitor.visit_instance(self) File "/Users/guido/src/mypy/mypy/fixup.py", line 144, in visit_instance node = lookup_qualified(self.modules, type_ref) File "/Users/guido/src/mypy/mypy/fixup.py", line 234, in lookup_qualified stnode = lookup_qualified_stnode(modules, name) File "/Users/guido/src/mypy/mypy/fixup.py", line 245, in lookup_qualified_stnode assert '.' in head, "Cannot find %s" % (name,) AssertionError: Cannot find A
AssertionError
def check_simple_str_interpolation( self, specifiers: List[ConversionSpecifier], replacements: Expression ) -> None: checkers = self.build_replacement_checkers(specifiers, replacements) if checkers is None: return rhs_type = self.accept(replacements) rep_types = [] # type: List[Type] if isinstance(rhs_type, TupleType): rep_types = rhs_type.items elif isinstance(rhs_type, AnyType): return else: rep_types = [rhs_type] if len(checkers) > len(rep_types): self.msg.too_few_string_formatting_arguments(replacements) elif len(checkers) < len(rep_types): self.msg.too_many_string_formatting_arguments(replacements) else: if len(checkers) == 1: check_node, check_type = checkers[0] if isinstance(rhs_type, TupleType) and len(rhs_type.items) == 1: check_type(rhs_type.items[0]) else: check_node(replacements) elif isinstance(replacements, TupleExpr) and not any( isinstance(item, StarExpr) for item in replacements.items ): for checks, rep_node in zip(checkers, replacements.items): check_node, check_type = checks check_node(rep_node) else: for checks, rep_type in zip(checkers, rep_types): check_node, check_type = checks check_type(rep_type)
def check_simple_str_interpolation( self, specifiers: List[ConversionSpecifier], replacements: Expression ) -> None: checkers = self.build_replacement_checkers(specifiers, replacements) if checkers is None: return rhs_type = self.accept(replacements) rep_types = [] # type: List[Type] if isinstance(rhs_type, TupleType): rep_types = rhs_type.items elif isinstance(rhs_type, AnyType): return else: rep_types = [rhs_type] if len(checkers) > len(rep_types): self.msg.too_few_string_formatting_arguments(replacements) elif len(checkers) < len(rep_types): self.msg.too_many_string_formatting_arguments(replacements) else: if len(checkers) == 1: check_node, check_type = checkers[0] if isinstance(rhs_type, TupleType) and len(rhs_type.items) == 1: check_type(rhs_type.items[0]) else: check_node(replacements) elif isinstance(replacements, TupleExpr): for checks, rep_node in zip(checkers, replacements.items): check_node, check_type = checks check_node(rep_node) else: for checks, rep_type in zip(checkers, rep_types): check_node, check_type = checks check_type(rep_type)
https://github.com/python/mypy/issues/2794
Traceback (most recent call last): File "/usr/local/bin/mypy", line 6, in <module> main(__file__) File "/usr/local/lib/python3.6/site-packages/mypy/main.py", line 42, in main res = type_check_only(sources, bin_dir, options) File "/usr/local/lib/python3.6/site-packages/mypy/main.py", line 87, in type_check_only options=options) File "/usr/local/lib/python3.6/site-packages/mypy/build.py", line 183, in build dispatch(sources, manager) File "/usr/local/lib/python3.6/site-packages/mypy/build.py", line 1526, in dispatch process_graph(graph, manager) File "/usr/local/lib/python3.6/site-packages/mypy/build.py", line 1762, in process_graph process_stale_scc(graph, scc) File "/usr/local/lib/python3.6/site-packages/mypy/build.py", line 1841, in process_stale_scc graph[id].type_check_first_pass() File "/usr/local/lib/python3.6/site-packages/mypy/build.py", line 1451, in type_check_first_pass self.type_checker.check_first_pass() File "/usr/local/lib/python3.6/site-packages/mypy/checker.py", line 175, in check_first_pass self.accept(d) File "/usr/local/lib/python3.6/site-packages/mypy/checker.py", line 247, in accept typ = node.accept(self) File "/usr/local/lib/python3.6/site-packages/mypy/nodes.py", line 788, in accept return visitor.visit_expression_stmt(self) File "/usr/local/lib/python3.6/site-packages/mypy/checker.py", line 1596, in visit_expression_stmt self.accept(s.expr) File "/usr/local/lib/python3.6/site-packages/mypy/checker.py", line 247, in accept typ = node.accept(self) File "/usr/local/lib/python3.6/site-packages/mypy/nodes.py", line 1400, in accept return visitor.visit_op_expr(self) File "/usr/local/lib/python3.6/site-packages/mypy/checker.py", line 2160, in visit_op_expr return self.expr_checker.visit_op_expr(e) File "/usr/local/lib/python3.6/site-packages/mypy/checkexpr.py", line 1110, in visit_op_expr return self.strfrm_checker.check_str_interpolation(e.left, e.right) File "/usr/local/lib/python3.6/site-packages/mypy/checkstrformat.py", line 74, in check_str_interpolation self.check_simple_str_interpolation(specifiers, replacements) File "/usr/local/lib/python3.6/site-packages/mypy/checkstrformat.py", line 146, in check_simple_str_interpolation check_node(rep_node) File "/usr/local/lib/python3.6/site-packages/mypy/checkstrformat.py", line 255, in check_expr check_type(type) File "/usr/local/lib/python3.6/site-packages/mypy/checkstrformat.py", line 251, in check_type 'expression has type', 'placeholder has type') File "/usr/local/lib/python3.6/site-packages/mypy/checker.py", line 2273, in check_subtype if is_subtype(subtype, supertype): File "/usr/local/lib/python3.6/site-packages/mypy/subtypes.py", line 54, in is_subtype for item in right.items) File "/usr/local/lib/python3.6/site-packages/mypy/subtypes.py", line 54, in <genexpr> for item in right.items) File "/usr/local/lib/python3.6/site-packages/mypy/subtypes.py", line 56, in is_subtype return left.accept(SubtypeVisitor(right, type_parameter_checker, AttributeError: 'NoneType' object has no attribute 'accept'
AttributeError
def visit_Subscript(self, n: ast35.Subscript) -> Type: if not isinstance(n.slice, ast35.Index): self.fail(TYPE_COMMENT_SYNTAX_ERROR, self.line, getattr(n, "col_offset", -1)) return AnyType() empty_tuple_index = False if isinstance(n.slice.value, ast35.Tuple): params = self.translate_expr_list(n.slice.value.elts) if len(n.slice.value.elts) == 0: empty_tuple_index = True else: params = [self.visit(n.slice.value)] value = self.visit(n.value) if isinstance(value, UnboundType) and not value.args: return UnboundType( value.name, params, line=self.line, empty_tuple_index=empty_tuple_index ) else: self.fail(TYPE_COMMENT_AST_ERROR, self.line, getattr(n, "col_offset", -1)) return AnyType()
def visit_Subscript(self, n: ast35.Subscript) -> Type: if not isinstance(n.slice, ast35.Index): self.fail(TYPE_COMMENT_SYNTAX_ERROR, self.line, getattr(n, "col_offset", -1)) return AnyType() value = self.visit(n.value) assert isinstance(value, UnboundType) assert not value.args empty_tuple_index = False if isinstance(n.slice.value, ast35.Tuple): params = self.translate_expr_list(n.slice.value.elts) if len(n.slice.value.elts) == 0: empty_tuple_index = True else: params = [self.visit(n.slice.value)] return UnboundType( value.name, params, line=self.line, empty_tuple_index=empty_tuple_index )
https://github.com/python/mypy/issues/2834
Traceback (most recent call last): File "/usr/local/bin/mypy", line 6, in <module> main(__file__) File "/usr/local/lib/python3.4/dist-packages/mypy/main.py", line 42, in main res = type_check_only(sources, bin_dir, options) File "/usr/local/lib/python3.4/dist-packages/mypy/main.py", line 86, in type_check_only options=options) File "/usr/local/lib/python3.4/dist-packages/mypy/build.py", line 183, in build dispatch(sources, manager) File "/usr/local/lib/python3.4/dist-packages/mypy/build.py", line 1523, in dispatch graph = load_graph(sources, manager) File "/usr/local/lib/python3.4/dist-packages/mypy/build.py", line 1605, in load_graph root_source=True) File "/usr/local/lib/python3.4/dist-packages/mypy/build.py", line 1212, in __init__ self.parse_file() File "/usr/local/lib/python3.4/dist-packages/mypy/build.py", line 1376, in parse_file self.ignore_all or self.options.ignore_errors) File "/usr/lib/python3.4/contextlib.py", line 77, in __exit__ self.gen.throw(type, value, traceback) File "/usr/local/lib/python3.4/dist-packages/mypy/build.py", line 1293, in wrap_context yield File "/usr/local/lib/python3.4/dist-packages/mypy/build.py", line 1376, in parse_file self.ignore_all or self.options.ignore_errors) File "/usr/local/lib/python3.4/dist-packages/mypy/build.py", line 462, in parse_file tree = parse(source, path, self.errors, options=self.options) File "/usr/local/lib/python3.4/dist-packages/mypy/parse.py", line 96, in parse custom_typing_module=options.custom_typing_module) File "/usr/local/lib/python3.4/dist-packages/mypy/fastparse.py", line 74, in parse ).visit(ast) File "/usr/local/lib/python3.4/dist-packages/typed_ast-0.6.3-py3.4-linux-x86_64.egg/typed_ast/ast35.py", line 256, in visit return visitor(node) File "/usr/local/lib/python3.4/dist-packages/mypy/fastparse.py", line 257, in visit_Module body = self.fix_function_overloads(self.translate_stmt_list(mod.body)) File "/usr/local/lib/python3.4/dist-packages/mypy/fastparse.py", line 157, in translate_stmt_list stmt = self.visit(e) File "/usr/local/lib/python3.4/dist-packages/typed_ast-0.6.3-py3.4-linux-x86_64.egg/typed_ast/ast35.py", line 256, in visit return visitor(node) File "/usr/local/lib/python3.4/dist-packages/mypy/fastparse.py", line 101, in wrapper node = f(self, ast) File "/usr/local/lib/python3.4/dist-packages/mypy/fastparse.py", line 502, in visit_Assign typ = TypeConverter(self.errors, line=n.lineno).visit(n.annotation) # type: ignore File "/usr/local/lib/python3.4/dist-packages/typed_ast-0.6.3-py3.4-linux-x86_64.egg/typed_ast/ast35.py", line 256, in visit return visitor(node) File "/usr/local/lib/python3.4/dist-packages/mypy/fastparse.py", line 968, in visit_Subscript params = [self.visit(n.slice.value)] File "/usr/local/lib/python3.4/dist-packages/typed_ast-0.6.3-py3.4-linux-x86_64.egg/typed_ast/ast35.py", line 256, in visit return visitor(node) File "/usr/local/lib/python3.4/dist-packages/mypy/fastparse.py", line 979, in visit_Attribute assert isinstance(before_dot, UnboundType) AssertionError:
AssertionError
def visit_Attribute(self, n: ast35.Attribute) -> Type: before_dot = self.visit(n.value) if isinstance(before_dot, UnboundType) and not before_dot.args: return UnboundType("{}.{}".format(before_dot.name, n.attr), line=self.line) else: self.fail(TYPE_COMMENT_AST_ERROR, self.line, getattr(n, "col_offset", -1)) return AnyType()
def visit_Attribute(self, n: ast35.Attribute) -> Type: before_dot = self.visit(n.value) assert isinstance(before_dot, UnboundType) assert not before_dot.args return UnboundType("{}.{}".format(before_dot.name, n.attr), line=self.line)
https://github.com/python/mypy/issues/2834
Traceback (most recent call last): File "/usr/local/bin/mypy", line 6, in <module> main(__file__) File "/usr/local/lib/python3.4/dist-packages/mypy/main.py", line 42, in main res = type_check_only(sources, bin_dir, options) File "/usr/local/lib/python3.4/dist-packages/mypy/main.py", line 86, in type_check_only options=options) File "/usr/local/lib/python3.4/dist-packages/mypy/build.py", line 183, in build dispatch(sources, manager) File "/usr/local/lib/python3.4/dist-packages/mypy/build.py", line 1523, in dispatch graph = load_graph(sources, manager) File "/usr/local/lib/python3.4/dist-packages/mypy/build.py", line 1605, in load_graph root_source=True) File "/usr/local/lib/python3.4/dist-packages/mypy/build.py", line 1212, in __init__ self.parse_file() File "/usr/local/lib/python3.4/dist-packages/mypy/build.py", line 1376, in parse_file self.ignore_all or self.options.ignore_errors) File "/usr/lib/python3.4/contextlib.py", line 77, in __exit__ self.gen.throw(type, value, traceback) File "/usr/local/lib/python3.4/dist-packages/mypy/build.py", line 1293, in wrap_context yield File "/usr/local/lib/python3.4/dist-packages/mypy/build.py", line 1376, in parse_file self.ignore_all or self.options.ignore_errors) File "/usr/local/lib/python3.4/dist-packages/mypy/build.py", line 462, in parse_file tree = parse(source, path, self.errors, options=self.options) File "/usr/local/lib/python3.4/dist-packages/mypy/parse.py", line 96, in parse custom_typing_module=options.custom_typing_module) File "/usr/local/lib/python3.4/dist-packages/mypy/fastparse.py", line 74, in parse ).visit(ast) File "/usr/local/lib/python3.4/dist-packages/typed_ast-0.6.3-py3.4-linux-x86_64.egg/typed_ast/ast35.py", line 256, in visit return visitor(node) File "/usr/local/lib/python3.4/dist-packages/mypy/fastparse.py", line 257, in visit_Module body = self.fix_function_overloads(self.translate_stmt_list(mod.body)) File "/usr/local/lib/python3.4/dist-packages/mypy/fastparse.py", line 157, in translate_stmt_list stmt = self.visit(e) File "/usr/local/lib/python3.4/dist-packages/typed_ast-0.6.3-py3.4-linux-x86_64.egg/typed_ast/ast35.py", line 256, in visit return visitor(node) File "/usr/local/lib/python3.4/dist-packages/mypy/fastparse.py", line 101, in wrapper node = f(self, ast) File "/usr/local/lib/python3.4/dist-packages/mypy/fastparse.py", line 502, in visit_Assign typ = TypeConverter(self.errors, line=n.lineno).visit(n.annotation) # type: ignore File "/usr/local/lib/python3.4/dist-packages/typed_ast-0.6.3-py3.4-linux-x86_64.egg/typed_ast/ast35.py", line 256, in visit return visitor(node) File "/usr/local/lib/python3.4/dist-packages/mypy/fastparse.py", line 968, in visit_Subscript params = [self.visit(n.slice.value)] File "/usr/local/lib/python3.4/dist-packages/typed_ast-0.6.3-py3.4-linux-x86_64.egg/typed_ast/ast35.py", line 256, in visit return visitor(node) File "/usr/local/lib/python3.4/dist-packages/mypy/fastparse.py", line 979, in visit_Attribute assert isinstance(before_dot, UnboundType) AssertionError:
AssertionError
def analyze_ordinary_member_access(self, e: MemberExpr, is_lvalue: bool) -> Type: """Analyse member expression or member lvalue.""" if e.kind is not None: # This is a reference to a module attribute. return self.analyze_ref_expr(e) else: # This is a reference to a non-module attribute. original_type = self.accept(e.expr) member_type = analyze_member_access( e.name, original_type, e, is_lvalue, False, False, self.named_type, self.not_ready_callback, self.msg, original_type=original_type, chk=self.chk, ) if isinstance(member_type, CallableType): for v in member_type.variables: v.id.meta_level = 0 if isinstance(member_type, Overloaded): for it in member_type.items(): for v in it.variables: v.id.meta_level = 0 if is_lvalue: return member_type else: return self.analyze_descriptor_access(original_type, member_type, e)
def analyze_ordinary_member_access(self, e: MemberExpr, is_lvalue: bool) -> Type: """Analyse member expression or member lvalue.""" if e.kind is not None: # This is a reference to a module attribute. return self.analyze_ref_expr(e) else: # This is a reference to a non-module attribute. original_type = self.accept(e.expr) member_type = analyze_member_access( e.name, original_type, e, is_lvalue, False, False, self.named_type, self.not_ready_callback, self.msg, original_type=original_type, chk=self.chk, ) if is_lvalue: return member_type else: return self.analyze_descriptor_access(original_type, member_type, e)
https://github.com/python/mypy/issues/2804
Traceback (most recent call last): File "/usr/local/lib/python3.6/runpy.py", line 193, in _run_module_as_main "__main__", mod_spec) File "/usr/local/lib/python3.6/runpy.py", line 85, in _run_code exec(code, run_globals) File "/Users/guido/src/mypy/mypy/__main__.py", line 5, in <module> main(None) File "/Users/guido/src/mypy/mypy/main.py", line 42, in main res = type_check_only(sources, bin_dir, options) File "/Users/guido/src/mypy/mypy/main.py", line 86, in type_check_only options=options) File "/Users/guido/src/mypy/mypy/build.py", line 183, in build dispatch(sources, manager) File "/Users/guido/src/mypy/mypy/build.py", line 1531, in dispatch process_graph(graph, manager) File "/Users/guido/src/mypy/mypy/build.py", line 1768, in process_graph process_stale_scc(graph, scc) File "/Users/guido/src/mypy/mypy/build.py", line 1856, in process_stale_scc graph[id].write_cache() File "/Users/guido/src/mypy/mypy/build.py", line 1512, in write_cache self.manager) File "/Users/guido/src/mypy/mypy/build.py", line 862, in write_cache data = tree.serialize() File "/Users/guido/src/mypy/mypy/nodes.py", line 271, in serialize 'names': self.names.serialize(self._fullname), File "/Users/guido/src/mypy/mypy/nodes.py", line 2265, in serialize data[key] = value.serialize(fullname, key) File "/Users/guido/src/mypy/mypy/nodes.py", line 2211, in serialize data['node'] = self.node.serialize() File "/Users/guido/src/mypy/mypy/nodes.py", line 671, in serialize 'type': None if self.type is None else self.type.serialize(), File "/Users/guido/src/mypy/mypy/types.py", line 837, in serialize 'items': [t.serialize() for t in self.items()], File "/Users/guido/src/mypy/mypy/types.py", line 837, in <listcomp> 'items': [t.serialize() for t in self.items()], File "/Users/guido/src/mypy/mypy/types.py", line 763, in serialize for t in self.arg_types], File "/Users/guido/src/mypy/mypy/types.py", line 763, in <listcomp> for t in self.arg_types], File "/Users/guido/src/mypy/mypy/types.py", line 1079, in serialize 'items': [t.serialize() for t in self.items], File "/Users/guido/src/mypy/mypy/types.py", line 1079, in <listcomp> 'items': [t.serialize() for t in self.items], File "/Users/guido/src/mypy/mypy/types.py", line 496, in serialize assert not self.id.is_meta_var() AssertionError
AssertionError
def apply_generic_arguments( callable: CallableType, types: List[Type], msg: MessageBuilder, context: Context ) -> CallableType: """Apply generic type arguments to a callable type. For example, applying [int] to 'def [T] (T) -> T' results in 'def (int) -> int'. Note that each type can be None; in this case, it will not be applied. """ tvars = callable.variables assert len(tvars) == len(types) # Check that inferred type variable values are compatible with allowed # values and bounds. Also, promote subtype values to allowed values. types = types[:] for i, type in enumerate(types): values = callable.variables[i].values if values and type: if isinstance(type, AnyType): continue if isinstance(type, TypeVarType) and type.values: # Allow substituting T1 for T if every allowed value of T1 # is also a legal value of T. if all(any(is_same_type(v, v1) for v in values) for v1 in type.values): continue for value in values: if isinstance(type, PartialType) or mypy.subtypes.is_subtype( type, value ): types[i] = value break else: msg.incompatible_typevar_value(callable, i + 1, type, context) upper_bound = callable.variables[i].upper_bound if ( type and not isinstance(type, PartialType) and not mypy.subtypes.satisfies_upper_bound(type, upper_bound) ): msg.incompatible_typevar_value(callable, i + 1, type, context) # Create a map from type variable id to target type. id_to_type = {} # type: Dict[TypeVarId, Type] for i, tv in enumerate(tvars): if types[i]: id_to_type[tv.id] = types[i] # Apply arguments to argument types. arg_types = [expand_type(at, id_to_type) for at in callable.arg_types] # The callable may retain some type vars if only some were applied. remaining_tvars = [tv for tv in tvars if tv.id not in id_to_type] return callable.copy_modified( arg_types=arg_types, ret_type=expand_type(callable.ret_type, id_to_type), variables=remaining_tvars, )
def apply_generic_arguments( callable: CallableType, types: List[Type], msg: MessageBuilder, context: Context ) -> CallableType: """Apply generic type arguments to a callable type. For example, applying [int] to 'def [T] (T) -> T' results in 'def (int) -> int'. Note that each type can be None; in this case, it will not be applied. """ tvars = callable.variables assert len(tvars) == len(types) # Check that inferred type variable values are compatible with allowed # values and bounds. Also, promote subtype values to allowed values. types = types[:] for i, type in enumerate(types): values = callable.variables[i].values if values and type: if isinstance(type, AnyType): continue if isinstance(type, TypeVarType) and type.values: # Allow substituting T1 for T if every allowed value of T1 # is also a legal value of T. if all(any(is_same_type(v, v1) for v in values) for v1 in type.values): continue for value in values: if mypy.subtypes.is_subtype(type, value): types[i] = value break else: msg.incompatible_typevar_value(callable, i + 1, type, context) upper_bound = callable.variables[i].upper_bound if type and not mypy.subtypes.satisfies_upper_bound(type, upper_bound): msg.incompatible_typevar_value(callable, i + 1, type, context) # Create a map from type variable id to target type. id_to_type = {} # type: Dict[TypeVarId, Type] for i, tv in enumerate(tvars): if types[i]: id_to_type[tv.id] = types[i] # Apply arguments to argument types. arg_types = [expand_type(at, id_to_type) for at in callable.arg_types] # The callable may retain some type vars if only some were applied. remaining_tvars = [tv for tv in tvars if tv.id not in id_to_type] return callable.copy_modified( arg_types=arg_types, ret_type=expand_type(callable.ret_type, id_to_type), variables=remaining_tvars, )
https://github.com/python/mypy/issues/1587
Traceback (most recent call last): File "/usr/local/bin/mypy", line 6, in <module> main(__file__) File "/usr/local/lib/python3.5/site-packages/mypy/main.py", line 54, in main res = type_check_only(sources, bin_dir, options) File "/usr/local/lib/python3.5/site-packages/mypy/main.py", line 102, in type_check_only python_path=options.python_path) File "/usr/local/lib/python3.5/site-packages/mypy/build.py", line 209, in build dispatch(sources, manager) File "/usr/local/lib/python3.5/site-packages/mypy/build.py", line 1325, in dispatch process_graph(graph, manager) File "/usr/local/lib/python3.5/site-packages/mypy/build.py", line 1456, in process_graph process_stale_scc(graph, scc) File "/usr/local/lib/python3.5/site-packages/mypy/build.py", line 1486, in process_stale_scc graph[id].type_check() File "/usr/local/lib/python3.5/site-packages/mypy/build.py", line 1305, in type_check manager.type_checker.visit_file(self.tree, self.xpath) File "/usr/local/lib/python3.5/site-packages/mypy/checker.py", line 424, in visit_file self.accept(d) File "/usr/local/lib/python3.5/site-packages/mypy/checker.py", line 465, in accept typ = node.accept(self) File "/usr/local/lib/python3.5/site-packages/mypy/nodes.py", line 862, in accept return visitor.visit_if_stmt(self) File "/usr/local/lib/python3.5/site-packages/mypy/checker.py", line 1661, in visit_if_stmt self.accept(b) File "/usr/local/lib/python3.5/site-packages/mypy/checker.py", line 465, in accept typ = node.accept(self) File "/usr/local/lib/python3.5/site-packages/mypy/nodes.py", line 715, in accept return visitor.visit_block(self) File "/usr/local/lib/python3.5/site-packages/mypy/checker.py", line 1149, in visit_block self.accept(s) File "/usr/local/lib/python3.5/site-packages/mypy/checker.py", line 465, in accept typ = node.accept(self) File "/usr/local/lib/python3.5/site-packages/mypy/nodes.py", line 753, in accept return visitor.visit_assignment_stmt(self) File "/usr/local/lib/python3.5/site-packages/mypy/checker.py", line 1158, in visit_assignment_stmt self.check_assignment(s.lvalues[-1], s.rvalue, s.type is None) File "/usr/local/lib/python3.5/site-packages/mypy/checker.py", line 1175, in check_assignment infer_lvalue_type) File "/usr/local/lib/python3.5/site-packages/mypy/checker.py", line 1244, in check_assignment_to_multiple_lvalues self.check_multi_assignment(lvalues, rvalue, context, infer_lvalue_type) File "/usr/local/lib/python3.5/site-packages/mypy/checker.py", line 1277, in check_multi_assignment context, undefined_rvalue, infer_lvalue_type) File "/usr/local/lib/python3.5/site-packages/mypy/checker.py", line 1297, in check_multi_assignment_from_tuple rvalue_type = cast(TupleType, self.accept(rvalue, lvalue_type)) File "/usr/local/lib/python3.5/site-packages/mypy/checker.py", line 465, in accept typ = node.accept(self) File "/usr/local/lib/python3.5/site-packages/mypy/nodes.py", line 1185, in accept return visitor.visit_call_expr(self) File "/usr/local/lib/python3.5/site-packages/mypy/checker.py", line 1997, in visit_call_expr return self.expr_checker.visit_call_expr(e) File "/usr/local/lib/python3.5/site-packages/mypy/checkexpr.py", line 141, in visit_call_expr return self.check_call_expr_with_callee_type(callee_type, e) File "/usr/local/lib/python3.5/site-packages/mypy/checkexpr.py", line 192, in check_call_expr_with_callee_type e.arg_names, callable_node=e.callee)[0] File "/usr/local/lib/python3.5/site-packages/mypy/checkexpr.py", line 230, in check_call callee, context) File "/usr/local/lib/python3.5/site-packages/mypy/checkexpr.py", line 370, in infer_function_type_arguments_using_context args = infer_type_arguments(callable.type_var_ids(), ret_type, erased_ctx) File "/usr/local/lib/python3.5/site-packages/mypy/infer.py", line 43, in infer_type_arguments return solve_constraints(type_var_ids, constraints) File "/usr/local/lib/python3.5/site-packages/mypy/solve.py", line 50, in solve_constraints top = meet_types(top, c.target) File "/usr/local/lib/python3.5/site-packages/mypy/meet.py", line 22, in meet_types return t.accept(TypeMeetVisitor(s)) File "/usr/local/lib/python3.5/site-packages/mypy/types.py", line 763, in accept return visitor.visit_partial_type(self) File "/usr/local/lib/python3.5/site-packages/mypy/meet.py", line 208, in visit_partial_type assert False, 'Internal error' AssertionError: Internal error *** INTERNAL ERROR *** test.py:5: error: Internal error -- please report a bug at https://github.com/python/mypy/issues NOTE: you can use "mypy --pdb ..." to drop into the debugger when this happens.
AssertionError
def visit_tuple_type(self, left: TupleType) -> bool: right = self.right if isinstance(right, Instance): if is_named_instance(right, "typing.Sized"): return True elif ( is_named_instance(right, "builtins.tuple") or is_named_instance(right, "typing.Iterable") or is_named_instance(right, "typing.Container") or is_named_instance(right, "typing.Sequence") or is_named_instance(right, "typing.Reversible") ): if right.args: iter_type = right.args[0] else: iter_type = AnyType() return all(is_subtype(li, iter_type) for li in left.items) elif is_subtype(left.fallback, right, self.check_type_parameter): return True return False elif isinstance(right, TupleType): if len(left.items) != len(right.items): return False for l, r in zip(left.items, right.items): if not is_subtype(l, r, self.check_type_parameter): return False if not is_subtype(left.fallback, right.fallback, self.check_type_parameter): return False return True else: return False
def visit_tuple_type(self, left: TupleType) -> bool: right = self.right if isinstance(right, Instance): if is_named_instance(right, "typing.Sized"): return True elif ( is_named_instance(right, "builtins.tuple") or is_named_instance(right, "typing.Iterable") or is_named_instance(right, "typing.Container") or is_named_instance(right, "typing.Sequence") or is_named_instance(right, "typing.Reversible") ): iter_type = right.args[0] return all(is_subtype(li, iter_type) for li in left.items) elif is_subtype(left.fallback, right, self.check_type_parameter): return True return False elif isinstance(right, TupleType): if len(left.items) != len(right.items): return False for l, r in zip(left.items, right.items): if not is_subtype(l, r, self.check_type_parameter): return False if not is_subtype(left.fallback, right.fallback, self.check_type_parameter): return False return True else: return False
https://github.com/python/mypy/issues/2662
$ mypy --show-traceback repro.py repro.py:11: error: INTERNAL ERROR -- please report a bug at https://github.com/python/mypy/issues Traceback (most recent call last): File "/home/adrake/ve/app/bin/mypy", line 6, in <module> main(__file__) File "/home/adrake/ve/app/lib/python3.5/site-packages/mypy/main.py", line 41, in main res = type_check_only(sources, bin_dir, options) File "/home/adrake/ve/app/lib/python3.5/site-packages/mypy/main.py", line 86, in type_check_only options=options) File "/home/adrake/ve/app/lib/python3.5/site-packages/mypy/build.py", line 183, in build dispatch(sources, manager) File "/home/adrake/ve/app/lib/python3.5/site-packages/mypy/build.py", line 1512, in dispatch process_graph(graph, manager) File "/home/adrake/ve/app/lib/python3.5/site-packages/mypy/build.py", line 1692, in process_graph process_stale_scc(graph, scc) File "/home/adrake/ve/app/lib/python3.5/site-packages/mypy/build.py", line 1771, in process_stale_scc graph[id].type_check_first_pass() File "/home/adrake/ve/app/lib/python3.5/site-packages/mypy/build.py", line 1440, in type_check_first_pass self.type_checker.check_first_pass() File "/home/adrake/ve/app/lib/python3.5/site-packages/mypy/checker.py", line 174, in check_first_pass self.accept(d) File "/home/adrake/ve/app/lib/python3.5/site-packages/mypy/checker.py", line 243, in accept typ = node.accept(self) File "/home/adrake/ve/app/lib/python3.5/site-packages/mypy/nodes.py", line 532, in accept return visitor.visit_func_def(self) File "/home/adrake/ve/app/lib/python3.5/site-packages/mypy/checker.py", line 455, in visit_func_def self.check_func_item(defn, name=defn.name()) File "/home/adrake/ve/app/lib/python3.5/site-packages/mypy/checker.py", line 518, in check_func_item self.check_func_def(defn, typ, name) File "/home/adrake/ve/app/lib/python3.5/site-packages/mypy/checker.py", line 648, in check_func_def self.accept(item.body) File "/home/adrake/ve/app/lib/python3.5/site-packages/mypy/checker.py", line 243, in accept typ = node.accept(self) File "/home/adrake/ve/app/lib/python3.5/site-packages/mypy/nodes.py", line 771, in accept return visitor.visit_block(self) File "/home/adrake/ve/app/lib/python3.5/site-packages/mypy/checker.py", line 1087, in visit_block self.accept(s) File "/home/adrake/ve/app/lib/python3.5/site-packages/mypy/checker.py", line 243, in accept typ = node.accept(self) File "/home/adrake/ve/app/lib/python3.5/site-packages/mypy/nodes.py", line 785, in accept return visitor.visit_expression_stmt(self) File "/home/adrake/ve/app/lib/python3.5/site-packages/mypy/checker.py", line 1522, in visit_expression_stmt self.accept(s.expr) File "/home/adrake/ve/app/lib/python3.5/site-packages/mypy/checker.py", line 243, in accept typ = node.accept(self) File "/home/adrake/ve/app/lib/python3.5/site-packages/mypy/nodes.py", line 1247, in accept return visitor.visit_call_expr(self) File "/home/adrake/ve/app/lib/python3.5/site-packages/mypy/checker.py", line 1968, in visit_call_expr return self.expr_checker.visit_call_expr(e) File "/home/adrake/ve/app/lib/python3.5/site-packages/mypy/checkexpr.py", line 179, in visit_call_expr return self.check_call_expr_with_callee_type(callee_type, e) File "/home/adrake/ve/app/lib/python3.5/site-packages/mypy/checkexpr.py", line 239, in check_call_expr_with_callee_type e.arg_names, callable_node=e.callee)[0] File "/home/adrake/ve/app/lib/python3.5/site-packages/mypy/checkexpr.py", line 280, in check_call callee, args, arg_kinds, formal_to_actual, context) File "/home/adrake/ve/app/lib/python3.5/site-packages/mypy/checkexpr.py", line 539, in infer_function_type_arguments context) File "/home/adrake/ve/app/lib/python3.5/site-packages/mypy/checkexpr.py", line 612, in apply_inferred_arguments return self.apply_generic_arguments(callee_type, inferred_args, context) File "/home/adrake/ve/app/lib/python3.5/site-packages/mypy/checkexpr.py", line 884, in apply_generic_arguments return applytype.apply_generic_arguments(callable, types, self.msg, context) File "/home/adrake/ve/app/lib/python3.5/site-packages/mypy/applytype.py", line 37, in apply_generic_arguments if mypy.subtypes.is_subtype(type, value): File "/home/adrake/ve/app/lib/python3.5/site-packages/mypy/subtypes.py", line 51, in is_subtype return left.accept(SubtypeVisitor(right, type_parameter_checker)) File "/home/adrake/ve/app/lib/python3.5/site-packages/mypy/types.py", line 785, in accept return visitor.visit_tuple_type(self) File "/home/adrake/ve/app/lib/python3.5/site-packages/mypy/subtypes.py", line 174, in visit_tuple_type iter_type = right.args[0] IndexError: list index out of range
IndexError
def analyze_class_attribute_access( itype: Instance, name: str, context: Context, is_lvalue: bool, builtin_type: Callable[[str], Instance], not_ready_callback: Callable[[str, Context], None], msg: MessageBuilder, original_type: Type, ) -> Type: """original_type is the type of E in the expression E.var""" node = itype.type.get(name) if not node: if itype.type.fallback_to_any: return AnyType() return None is_decorated = isinstance(node.node, Decorator) is_method = is_decorated or isinstance(node.node, FuncDef) if is_lvalue: if is_method: msg.cant_assign_to_method(context) if isinstance(node.node, TypeInfo): msg.fail(messages.CANNOT_ASSIGN_TO_TYPE, context) if itype.type.is_enum and not (is_lvalue or is_decorated or is_method): return itype t = node.type if t: if isinstance(t, PartialType): return handle_partial_attribute_type(t, is_lvalue, msg, node.node) is_classmethod = is_decorated and cast(Decorator, node.node).func.is_class return add_class_tvars(t, itype, is_classmethod, builtin_type, original_type) elif isinstance(node.node, Var): not_ready_callback(name, context) return AnyType() if isinstance(node.node, TypeVarExpr): return TypeVarType(node.tvar_def, node.tvar_def.line, node.tvar_def.column) if isinstance(node.node, TypeInfo): return type_object_type(node.node, builtin_type) if isinstance(node.node, MypyFile): # Reference to a module object. return builtin_type("builtins.module") if is_decorated: # TODO: Return type of decorated function. This is quick hack to work around #998. return AnyType() else: return function_type( cast(FuncBase, node.node), builtin_type("builtins.function") )
def analyze_class_attribute_access( itype: Instance, name: str, context: Context, is_lvalue: bool, builtin_type: Callable[[str], Instance], not_ready_callback: Callable[[str, Context], None], msg: MessageBuilder, original_type: Type, ) -> Type: """original_type is the type of E in the expression E.var""" node = itype.type.get(name) if not node: if itype.type.fallback_to_any: return AnyType() return None is_decorated = isinstance(node.node, Decorator) is_method = is_decorated or isinstance(node.node, FuncDef) if is_lvalue: if is_method: msg.cant_assign_to_method(context) if isinstance(node.node, TypeInfo): msg.fail(messages.CANNOT_ASSIGN_TO_TYPE, context) if itype.type.is_enum and not (is_lvalue or is_decorated or is_method): return itype t = node.type if t: if isinstance(t, PartialType): return handle_partial_attribute_type(t, is_lvalue, msg, node.node) is_classmethod = is_decorated and cast(Decorator, node.node).func.is_class return add_class_tvars(t, itype, is_classmethod, builtin_type, original_type) elif isinstance(node.node, Var): not_ready_callback(name, context) return AnyType() if isinstance(node.node, TypeInfo): return type_object_type(node.node, builtin_type) if isinstance(node.node, MypyFile): # Reference to a module object. return builtin_type("builtins.module") if is_decorated: # TODO: Return type of decorated function. This is quick hack to work around #998. return AnyType() else: return function_type( cast(FuncBase, node.node), builtin_type("builtins.function") )
https://github.com/python/mypy/issues/2530
test2.py: note: In function "example": test2.py:9: error: Invalid type "A" test2.py:8: error: INTERNAL ERROR -- please report a bug at https://github.com/python/mypy/issues Traceback (most recent call last): File "/usr/local/bin/mypy", line 6, in <module> main(__file__) File "/usr/local/lib/python3.5/dist-packages/mypy/main.py", line 41, in main res = type_check_only(sources, bin_dir, options) File "/usr/local/lib/python3.5/dist-packages/mypy/main.py", line 86, in type_check_only options=options) File "/usr/local/lib/python3.5/dist-packages/mypy/build.py", line 183, in build dispatch(sources, manager) File "/usr/local/lib/python3.5/dist-packages/mypy/build.py", line 1512, in dispatch process_graph(graph, manager) File "/usr/local/lib/python3.5/dist-packages/mypy/build.py", line 1692, in process_graph process_stale_scc(graph, scc) File "/usr/local/lib/python3.5/dist-packages/mypy/build.py", line 1771, in process_stale_scc graph[id].type_check_first_pass() File "/usr/local/lib/python3.5/dist-packages/mypy/build.py", line 1440, in type_check_first_pass self.type_checker.check_first_pass() File "/usr/local/lib/python3.5/dist-packages/mypy/checker.py", line 174, in check_first_pass self.accept(d) File "/usr/local/lib/python3.5/dist-packages/mypy/checker.py", line 243, in accept typ = node.accept(self) File "/usr/local/lib/python3.5/dist-packages/mypy/nodes.py", line 710, in accept return visitor.visit_class_def(self) File "/usr/local/lib/python3.5/dist-packages/mypy/checker.py", line 992, in visit_class_def self.accept(defn.defs) File "/usr/local/lib/python3.5/dist-packages/mypy/checker.py", line 243, in accept typ = node.accept(self) File "/usr/local/lib/python3.5/dist-packages/mypy/nodes.py", line 771, in accept return visitor.visit_block(self) File "/usr/local/lib/python3.5/dist-packages/mypy/checker.py", line 1087, in visit_block self.accept(s) File "/usr/local/lib/python3.5/dist-packages/mypy/checker.py", line 243, in accept typ = node.accept(self) File "/usr/local/lib/python3.5/dist-packages/mypy/nodes.py", line 597, in accept return visitor.visit_decorator(self) File "/usr/local/lib/python3.5/dist-packages/mypy/checker.py", line 1882, in visit_decorator e.func.accept(self) File "/usr/local/lib/python3.5/dist-packages/mypy/nodes.py", line 532, in accept return visitor.visit_func_def(self) File "/usr/local/lib/python3.5/dist-packages/mypy/checker.py", line 455, in visit_func_def self.check_func_item(defn, name=defn.name()) File "/usr/local/lib/python3.5/dist-packages/mypy/checker.py", line 518, in check_func_item self.check_func_def(defn, typ, name) File "/usr/local/lib/python3.5/dist-packages/mypy/checker.py", line 648, in check_func_def self.accept(item.body) File "/usr/local/lib/python3.5/dist-packages/mypy/checker.py", line 243, in accept typ = node.accept(self) File "/usr/local/lib/python3.5/dist-packages/mypy/nodes.py", line 771, in accept return visitor.visit_block(self) File "/usr/local/lib/python3.5/dist-packages/mypy/checker.py", line 1087, in visit_block self.accept(s) File "/usr/local/lib/python3.5/dist-packages/mypy/checker.py", line 243, in accept typ = node.accept(self) File "/usr/local/lib/python3.5/dist-packages/mypy/nodes.py", line 812, in accept return visitor.visit_assignment_stmt(self) File "/usr/local/lib/python3.5/dist-packages/mypy/checker.py", line 1095, in visit_assignment_stmt self.check_assignment(s.lvalues[-1], s.rvalue, s.type is None, s.new_syntax) File "/usr/local/lib/python3.5/dist-packages/mypy/checker.py", line 1161, in check_assignment self.infer_variable_type(inferred, lvalue, self.accept(rvalue), File "/usr/local/lib/python3.5/dist-packages/mypy/checker.py", line 243, in accept typ = node.accept(self) File "/usr/local/lib/python3.5/dist-packages/mypy/nodes.py", line 1202, in accept return visitor.visit_member_expr(self) File "/usr/local/lib/python3.5/dist-packages/mypy/checker.py", line 2054, in visit_member_expr return self.expr_checker.visit_member_expr(e) File "/usr/local/lib/python3.5/dist-packages/mypy/checkexpr.py", line 889, in visit_member_expr result = self.analyze_ordinary_member_access(e, False) File "/usr/local/lib/python3.5/dist-packages/mypy/checkexpr.py", line 904, in analyze_ordinary_member_access original_type=original_type, chk=self.chk) File "/usr/local/lib/python3.5/dist-packages/mypy/checkmember.py", line 142, in analyze_member_access original_type=original_type) File "/usr/local/lib/python3.5/dist-packages/mypy/checkmember.py", line 387, in analyze_class_attribute_access return function_type(cast(FuncBase, node.node), builtin_type('builtins.function')) File "/usr/local/lib/python3.5/dist-packages/mypy/types.py", line 1508, in function_type if func.type: AttributeError: 'TypeVarExpr' object has no attribute 'type'
AttributeError
def visit_import_all(self, i: ImportAll) -> None: i_id = self.correct_relative_import(i) if i_id in self.modules: m = self.modules[i_id] self.add_submodules_to_parent_modules(i_id, True) for name, node in m.names.items(): node = self.normalize_type_alias(node, i) if not name.startswith("_") and node.module_public: existing_symbol = self.globals.get(name) if existing_symbol: # Import can redefine a variable. They get special treatment. if self.process_import_over_existing_name( name, existing_symbol, node, i ): continue self.add_symbol( name, SymbolTableNode( node.kind, node.node, self.cur_mod_id, node.type_override ), i, ) else: # Don't add any dummy symbols for 'from x import *' if 'x' is unknown. pass
def visit_import_all(self, i: ImportAll) -> None: i_id = self.correct_relative_import(i) if i_id in self.modules: m = self.modules[i_id] self.add_submodules_to_parent_modules(i_id, True) for name, node in m.names.items(): node = self.normalize_type_alias(node, i) if not name.startswith("_") and node.module_public: existing_symbol = self.globals.get(name) if existing_symbol: # Import can redefine a variable. They get special treatment. if self.process_import_over_existing_name( name, existing_symbol, node, i ): continue self.add_symbol( name, SymbolTableNode(node.kind, node.node, self.cur_mod_id), i ) else: # Don't add any dummy symbols for 'from x import *' if 'x' is unknown. pass
https://github.com/python/mypy/issues/2315
ryan@DevPC-LX ~/blaze-mypy/bug master $ mypy x.py --show-traceback x.py:1: error: INTERNAL ERROR -- please report a bug at https://github.com/python/mypy/issues Traceback (most recent call last): File "/media/ryan/stuff/anaconda/bin/mypy", line 6, in <module> exec(compile(open(__file__).read(), __file__, 'exec')) File "/media/ryan/stuff/mypy/scripts/mypy", line 6, in <module> main(__file__) File "/media/stuff/anaconda/lib/python3.4/site-packages/mypy/main.py", line 38, in main res = type_check_only(sources, bin_dir, options) File "/media/stuff/anaconda/lib/python3.4/site-packages/mypy/main.py", line 79, in type_check_only options=options) File "/media/stuff/anaconda/lib/python3.4/site-packages/mypy/build.py", line 184, in build dispatch(sources, manager) File "/media/stuff/anaconda/lib/python3.4/site-packages/mypy/build.py", line 1494, in dispatch process_graph(graph, manager) File "/media/stuff/anaconda/lib/python3.4/site-packages/mypy/build.py", line 1674, in process_graph process_stale_scc(graph, scc) File "/media/stuff/anaconda/lib/python3.4/site-packages/mypy/build.py", line 1751, in process_stale_scc graph[id].semantic_analysis_pass_three() File "/media/stuff/anaconda/lib/python3.4/site-packages/mypy/build.py", line 1411, in semantic_analysis_pass_three self.manager.semantic_analyzer_pass3.visit_file(self.tree, self.xpath, self.options) File "/media/stuff/anaconda/lib/python3.4/site-packages/mypy/semanal.py", line 2871, in visit_file self.accept(file_node) File "/media/stuff/anaconda/lib/python3.4/site-packages/mypy/semanal.py", line 2875, in accept node.accept(self) File "/media/stuff/anaconda/lib/python3.4/site-packages/mypy/nodes.py", line 259, in accept return visitor.visit_mypy_file(self) File "/media/stuff/anaconda/lib/python3.4/site-packages/mypy/traverser.py", line 29, in visit_mypy_file d.accept(self) File "/media/stuff/anaconda/lib/python3.4/site-packages/mypy/nodes.py", line 815, in accept return visitor.visit_assignment_stmt(self) File "/media/stuff/anaconda/lib/python3.4/site-packages/mypy/semanal.py", line 2952, in visit_assignment_stmt self.analyze(s.type) File "/media/stuff/anaconda/lib/python3.4/site-packages/mypy/semanal.py", line 2972, in analyze type.accept(analyzer) File "/media/stuff/anaconda/lib/python3.4/site-packages/mypy/types.py", line 427, in accept return visitor.visit_instance(self) File "/media/stuff/anaconda/lib/python3.4/site-packages/mypy/typeanal.py", line 363, in visit_instance if not satisfies_upper_bound(arg, TypeVar.upper_bound): File "/media/stuff/anaconda/lib/python3.4/site-packages/mypy/subtypes.py", line 75, in satisfies_upper_bound return isinstance(a, Void) or is_subtype(a, upper_bound) File "/media/stuff/anaconda/lib/python3.4/site-packages/mypy/subtypes.py", line 51, in is_subtype return left.accept(SubtypeVisitor(right, type_parameter_checker)) AttributeError: 'NoneType' object has no attribute 'accept' x.py:1: note: use --pdb to drop into pdb ryan@DevPC-LX ~/blaze-mypy/bug master $
AttributeError
def visit_try_stmt(self, s: TryStmt) -> Type: """Type check a try statement.""" completed_frames = [] # type: List[Frame] self.binder.push_frame() self.binder.try_frames.add(len(self.binder.frames) - 2) self.accept(s.body) self.binder.try_frames.remove(len(self.binder.frames) - 2) self.breaking_out = False changed, frame_on_completion = self.binder.pop_frame() completed_frames.append(frame_on_completion) for i in range(len(s.handlers)): self.binder.push_frame() if s.types[i]: t = self.exception_type(s.types[i]) if s.vars[i]: # To support local variables, we make this a definition line, # causing assignment to set the variable's type. s.vars[i].is_def = True self.check_assignment(s.vars[i], self.temp_node(t, s.vars[i])) self.accept(s.handlers[i]) if s.vars[i]: # Exception variables are deleted in python 3 but not python 2. # But, since it's bad form in python 2 and the type checking # wouldn't work very well, we delete it anyway. # Unfortunately, this doesn't let us detect usage before the # try/except block. if self.pyversion[0] >= 3: source = s.vars[i].name else: source = ( '(exception variable "{}", which we do not accept ' "outside except: blocks even in python 2)".format(s.vars[i].name) ) var = cast(Var, s.vars[i].node) var.type = DeletedType(source=source) self.binder.cleanse(s.vars[i]) self.breaking_out = False changed, frame_on_completion = self.binder.pop_frame() completed_frames.append(frame_on_completion) # Do the else block similar to the way we do except blocks. if s.else_body: self.binder.push_frame() self.accept(s.else_body) self.breaking_out = False changed, frame_on_completion = self.binder.pop_frame() completed_frames.append(frame_on_completion) self.binder.update_from_options(completed_frames) if s.finally_body: self.accept(s.finally_body)
def visit_try_stmt(self, s: TryStmt) -> Type: """Type check a try statement.""" completed_frames = [] # type: List[Frame] self.binder.push_frame() self.binder.try_frames.add(len(self.binder.frames) - 2) self.accept(s.body) self.binder.try_frames.remove(len(self.binder.frames) - 2) if s.else_body: self.accept(s.else_body) self.breaking_out = False changed, frame_on_completion = self.binder.pop_frame() completed_frames.append(frame_on_completion) for i in range(len(s.handlers)): self.binder.push_frame() if s.types[i]: t = self.exception_type(s.types[i]) if s.vars[i]: # To support local variables, we make this a definition line, # causing assignment to set the variable's type. s.vars[i].is_def = True self.check_assignment(s.vars[i], self.temp_node(t, s.vars[i])) self.accept(s.handlers[i]) if s.vars[i]: # Exception variables are deleted in python 3 but not python 2. # But, since it's bad form in python 2 and the type checking # wouldn't work very well, we delete it anyway. # Unfortunately, this doesn't let us detect usage before the # try/except block. if self.pyversion[0] >= 3: source = s.vars[i].name else: source = ( '(exception variable "{}", which we do not accept ' "outside except: blocks even in python 2)".format(s.vars[i].name) ) var = cast(Var, s.vars[i].node) var.type = DeletedType(source=source) self.binder.cleanse(s.vars[i]) self.breaking_out = False changed, frame_on_completion = self.binder.pop_frame() completed_frames.append(frame_on_completion) self.binder.update_from_options(completed_frames) if s.finally_body: self.accept(s.finally_body)
https://github.com/python/mypy/issues/1289
Traceback (most recent call last): File "./scripts/mypy", line 6, in <module> main(__file__) File "mypy/mypy/main.py", line 50, in main type_check_only(sources, bin_dir, options) File "mypy/mypy/main.py", line 94, in type_check_only python_path=options.python_path) File "mypy/mypy/build.py", line 210, in build result = manager.process(initial_states) File "mypy/mypy/build.py", line 425, in process next.process() File "mypy/mypy/build.py", line 930, in process self.type_checker().visit_file(self.tree, self.tree.path) File "mypy/mypy/checker.py", line 409, in visit_file self.accept(d) File "mypy/mypy/checker.py", line 450, in accept typ = node.accept(self) File "mypy/mypy/nodes.py", line 707, in accept return visitor.visit_try_stmt(self) File "mypy/mypy/checker.py", line 1732, in visit_try_stmt self.accept(s.else_body) File "mypy/mypy/checker.py", line 450, in accept typ = node.accept(self) File "mypy/mypy/nodes.py", line 526, in accept return visitor.visit_block(self) File "mypy/mypy/checker.py", line 1113, in visit_block self.accept(s) File "mypy/mypy/checker.py", line 450, in accept typ = node.accept(self) File "mypy/mypy/nodes.py", line 382, in accept return visitor.visit_func_def(self) File "mypy/mypy/checker.py", line 594, in visit_func_def 'redefinition with type') File "mypy/mypy/checker.py", line 2117, in check_subtype if not is_subtype(subtype, supertype): File "mypy/mypy/subtypes.py", line 49, in is_subtype return left.accept(SubtypeVisitor(right, type_parameter_checker)) AttributeError: 'NoneType' object has no attribute 'accept'
AttributeError
def __init__(self) -> None: # The stack of frames currently used. These map # expr.literal_hash -- literals like 'foo.bar' -- # to types. The last element of this list is the # top-most, current frame. Each earlier element # records the state as of when that frame was last # on top of the stack. self.frames = [Frame()] # For frames higher in the stack, we record the set of # Frames that can escape there, either by falling off # the end of the frame or by a loop control construct # or raised exception. The last element of self.frames # has no corresponding element in this list. self.options_on_return = [] # type: List[List[Frame]] # Maps expr.literal_hash] to get_declaration(expr) # for every expr stored in the binder self.declarations = Frame() # Set of other keys to invalidate if a key is changed, e.g. x -> {x.a, x[0]} # Whenever a new key (e.g. x.a.b) is added, we update this self.dependencies = {} # type: Dict[Key, Set[Key]] # Whether the last pop changed the newly top frame on exit self.last_pop_changed = False self.try_frames = set() # type: Set[int] self.break_frames = [] # type: List[int] self.continue_frames = [] # type: List[int]
def __init__(self) -> None: # The set of frames currently used. These map # expr.literal_hash -- literals like 'foo.bar' -- # to types. self.frames = [Frame()] # For frames higher in the stack, we record the set of # Frames that can escape there self.options_on_return = [] # type: List[List[Frame]] # Maps expr.literal_hash] to get_declaration(expr) # for every expr stored in the binder self.declarations = Frame() # Set of other keys to invalidate if a key is changed, e.g. x -> {x.a, x[0]} # Whenever a new key (e.g. x.a.b) is added, we update this self.dependencies = {} # type: Dict[Key, Set[Key]] # breaking_out is set to True on return/break/continue/raise # It is cleared on pop_frame() and placed in last_pop_breaking_out # Lines of code after breaking_out = True are unreachable and not # typechecked. self.breaking_out = False # Whether the last pop changed the newly top frame on exit self.last_pop_changed = False # Whether the last pop was necessarily breaking out, and couldn't fall through self.last_pop_breaking_out = False self.try_frames = set() # type: Set[int] self.loop_frames = [] # type: List[int]
https://github.com/python/mypy/issues/1289
Traceback (most recent call last): File "./scripts/mypy", line 6, in <module> main(__file__) File "mypy/mypy/main.py", line 50, in main type_check_only(sources, bin_dir, options) File "mypy/mypy/main.py", line 94, in type_check_only python_path=options.python_path) File "mypy/mypy/build.py", line 210, in build result = manager.process(initial_states) File "mypy/mypy/build.py", line 425, in process next.process() File "mypy/mypy/build.py", line 930, in process self.type_checker().visit_file(self.tree, self.tree.path) File "mypy/mypy/checker.py", line 409, in visit_file self.accept(d) File "mypy/mypy/checker.py", line 450, in accept typ = node.accept(self) File "mypy/mypy/nodes.py", line 707, in accept return visitor.visit_try_stmt(self) File "mypy/mypy/checker.py", line 1732, in visit_try_stmt self.accept(s.else_body) File "mypy/mypy/checker.py", line 450, in accept typ = node.accept(self) File "mypy/mypy/nodes.py", line 526, in accept return visitor.visit_block(self) File "mypy/mypy/checker.py", line 1113, in visit_block self.accept(s) File "mypy/mypy/checker.py", line 450, in accept typ = node.accept(self) File "mypy/mypy/nodes.py", line 382, in accept return visitor.visit_func_def(self) File "mypy/mypy/checker.py", line 594, in visit_func_def 'redefinition with type') File "mypy/mypy/checker.py", line 2117, in check_subtype if not is_subtype(subtype, supertype): File "mypy/mypy/subtypes.py", line 49, in is_subtype return left.accept(SubtypeVisitor(right, type_parameter_checker)) AttributeError: 'NoneType' object has no attribute 'accept'
AttributeError
def _add_dependencies(self, key: Key, value: Key = None) -> None: if value is None: value = key else: self.dependencies.setdefault(key, set()).add(value) for elt in key: if isinstance(elt, Key): self._add_dependencies(elt, value)
def _add_dependencies(self, key: Key, value: Key = None) -> None: if value is None: value = key else: self.dependencies.setdefault(key, set()).add(value) if isinstance(key, tuple): for elt in key: self._add_dependencies(elt, value)
https://github.com/python/mypy/issues/1289
Traceback (most recent call last): File "./scripts/mypy", line 6, in <module> main(__file__) File "mypy/mypy/main.py", line 50, in main type_check_only(sources, bin_dir, options) File "mypy/mypy/main.py", line 94, in type_check_only python_path=options.python_path) File "mypy/mypy/build.py", line 210, in build result = manager.process(initial_states) File "mypy/mypy/build.py", line 425, in process next.process() File "mypy/mypy/build.py", line 930, in process self.type_checker().visit_file(self.tree, self.tree.path) File "mypy/mypy/checker.py", line 409, in visit_file self.accept(d) File "mypy/mypy/checker.py", line 450, in accept typ = node.accept(self) File "mypy/mypy/nodes.py", line 707, in accept return visitor.visit_try_stmt(self) File "mypy/mypy/checker.py", line 1732, in visit_try_stmt self.accept(s.else_body) File "mypy/mypy/checker.py", line 450, in accept typ = node.accept(self) File "mypy/mypy/nodes.py", line 526, in accept return visitor.visit_block(self) File "mypy/mypy/checker.py", line 1113, in visit_block self.accept(s) File "mypy/mypy/checker.py", line 450, in accept typ = node.accept(self) File "mypy/mypy/nodes.py", line 382, in accept return visitor.visit_func_def(self) File "mypy/mypy/checker.py", line 594, in visit_func_def 'redefinition with type') File "mypy/mypy/checker.py", line 2117, in check_subtype if not is_subtype(subtype, supertype): File "mypy/mypy/subtypes.py", line 49, in is_subtype return left.accept(SubtypeVisitor(right, type_parameter_checker)) AttributeError: 'NoneType' object has no attribute 'accept'
AttributeError
def update_from_options(self, frames: List[Frame]) -> bool: """Update the frame to reflect that each key will be updated as in one of the frames. Return whether any item changes. If a key is declared as AnyType, only update it if all the options are the same. """ frames = [f for f in frames if not f.unreachable] changed = False keys = set(key for f in frames for key in f) for key in keys: current_value = self._get(key) resulting_values = [f.get(key, current_value) for f in frames] if any(x is None for x in resulting_values): # We didn't know anything about key before # (current_value must be None), and we still don't # know anything about key in at least one possible frame. continue if isinstance(self.declarations.get(key), AnyType): type = resulting_values[0] if not all(is_same_type(type, t) for t in resulting_values[1:]): type = AnyType() else: type = resulting_values[0] for other in resulting_values[1:]: type = join_simple(self.declarations[key], type, other) if not is_same_type(type, current_value): self._push(key, type) changed = True self.frames[-1].unreachable = not frames return changed
def update_from_options(self, frames: List[Frame]) -> bool: """Update the frame to reflect that each key will be updated as in one of the frames. Return whether any item changes. If a key is declared as AnyType, only update it if all the options are the same. """ changed = False keys = set(key for f in frames for key in f) for key in keys: current_value = self._get(key) resulting_values = [f.get(key, current_value) for f in frames] if any(x is None for x in resulting_values): continue if isinstance(self.declarations.get(key), AnyType): type = resulting_values[0] if not all(is_same_type(type, t) for t in resulting_values[1:]): type = AnyType() else: type = resulting_values[0] for other in resulting_values[1:]: type = join_simple(self.declarations[key], type, other) if not is_same_type(type, current_value): self._push(key, type) changed = True return changed
https://github.com/python/mypy/issues/1289
Traceback (most recent call last): File "./scripts/mypy", line 6, in <module> main(__file__) File "mypy/mypy/main.py", line 50, in main type_check_only(sources, bin_dir, options) File "mypy/mypy/main.py", line 94, in type_check_only python_path=options.python_path) File "mypy/mypy/build.py", line 210, in build result = manager.process(initial_states) File "mypy/mypy/build.py", line 425, in process next.process() File "mypy/mypy/build.py", line 930, in process self.type_checker().visit_file(self.tree, self.tree.path) File "mypy/mypy/checker.py", line 409, in visit_file self.accept(d) File "mypy/mypy/checker.py", line 450, in accept typ = node.accept(self) File "mypy/mypy/nodes.py", line 707, in accept return visitor.visit_try_stmt(self) File "mypy/mypy/checker.py", line 1732, in visit_try_stmt self.accept(s.else_body) File "mypy/mypy/checker.py", line 450, in accept typ = node.accept(self) File "mypy/mypy/nodes.py", line 526, in accept return visitor.visit_block(self) File "mypy/mypy/checker.py", line 1113, in visit_block self.accept(s) File "mypy/mypy/checker.py", line 450, in accept typ = node.accept(self) File "mypy/mypy/nodes.py", line 382, in accept return visitor.visit_func_def(self) File "mypy/mypy/checker.py", line 594, in visit_func_def 'redefinition with type') File "mypy/mypy/checker.py", line 2117, in check_subtype if not is_subtype(subtype, supertype): File "mypy/mypy/subtypes.py", line 49, in is_subtype return left.accept(SubtypeVisitor(right, type_parameter_checker)) AttributeError: 'NoneType' object has no attribute 'accept'
AttributeError
def pop_frame(self, can_skip: bool, fall_through: int) -> Frame: """Pop a frame and return it. See frame_context() for documentation of fall_through. """ if fall_through > 0: self.allow_jump(-fall_through) result = self.frames.pop() options = self.options_on_return.pop() if can_skip: options.insert(0, self.frames[-1]) self.last_pop_changed = self.update_from_options(options) return result
def pop_frame(self, fall_through: int = 0) -> Frame: """Pop a frame and return it. See frame_context() for documentation of fall_through. """ if fall_through and not self.breaking_out: self.allow_jump(-fall_through) result = self.frames.pop() options = self.options_on_return.pop() self.last_pop_changed = self.update_from_options(options) self.last_pop_breaking_out = self.breaking_out return result
https://github.com/python/mypy/issues/1289
Traceback (most recent call last): File "./scripts/mypy", line 6, in <module> main(__file__) File "mypy/mypy/main.py", line 50, in main type_check_only(sources, bin_dir, options) File "mypy/mypy/main.py", line 94, in type_check_only python_path=options.python_path) File "mypy/mypy/build.py", line 210, in build result = manager.process(initial_states) File "mypy/mypy/build.py", line 425, in process next.process() File "mypy/mypy/build.py", line 930, in process self.type_checker().visit_file(self.tree, self.tree.path) File "mypy/mypy/checker.py", line 409, in visit_file self.accept(d) File "mypy/mypy/checker.py", line 450, in accept typ = node.accept(self) File "mypy/mypy/nodes.py", line 707, in accept return visitor.visit_try_stmt(self) File "mypy/mypy/checker.py", line 1732, in visit_try_stmt self.accept(s.else_body) File "mypy/mypy/checker.py", line 450, in accept typ = node.accept(self) File "mypy/mypy/nodes.py", line 526, in accept return visitor.visit_block(self) File "mypy/mypy/checker.py", line 1113, in visit_block self.accept(s) File "mypy/mypy/checker.py", line 450, in accept typ = node.accept(self) File "mypy/mypy/nodes.py", line 382, in accept return visitor.visit_func_def(self) File "mypy/mypy/checker.py", line 594, in visit_func_def 'redefinition with type') File "mypy/mypy/checker.py", line 2117, in check_subtype if not is_subtype(subtype, supertype): File "mypy/mypy/subtypes.py", line 49, in is_subtype return left.accept(SubtypeVisitor(right, type_parameter_checker)) AttributeError: 'NoneType' object has no attribute 'accept'
AttributeError
def get_declaration(self, expr: Node) -> Type: if isinstance(expr, RefExpr) and isinstance(expr.node, Var): type = expr.node.type if isinstance(type, PartialType): return None return type else: return None
def get_declaration(self, node: Node) -> Type: if isinstance(node, (RefExpr, SymbolTableNode)) and isinstance(node.node, Var): type = node.node.type if isinstance(type, PartialType): return None return type else: return None
https://github.com/python/mypy/issues/1289
Traceback (most recent call last): File "./scripts/mypy", line 6, in <module> main(__file__) File "mypy/mypy/main.py", line 50, in main type_check_only(sources, bin_dir, options) File "mypy/mypy/main.py", line 94, in type_check_only python_path=options.python_path) File "mypy/mypy/build.py", line 210, in build result = manager.process(initial_states) File "mypy/mypy/build.py", line 425, in process next.process() File "mypy/mypy/build.py", line 930, in process self.type_checker().visit_file(self.tree, self.tree.path) File "mypy/mypy/checker.py", line 409, in visit_file self.accept(d) File "mypy/mypy/checker.py", line 450, in accept typ = node.accept(self) File "mypy/mypy/nodes.py", line 707, in accept return visitor.visit_try_stmt(self) File "mypy/mypy/checker.py", line 1732, in visit_try_stmt self.accept(s.else_body) File "mypy/mypy/checker.py", line 450, in accept typ = node.accept(self) File "mypy/mypy/nodes.py", line 526, in accept return visitor.visit_block(self) File "mypy/mypy/checker.py", line 1113, in visit_block self.accept(s) File "mypy/mypy/checker.py", line 450, in accept typ = node.accept(self) File "mypy/mypy/nodes.py", line 382, in accept return visitor.visit_func_def(self) File "mypy/mypy/checker.py", line 594, in visit_func_def 'redefinition with type') File "mypy/mypy/checker.py", line 2117, in check_subtype if not is_subtype(subtype, supertype): File "mypy/mypy/subtypes.py", line 49, in is_subtype return left.accept(SubtypeVisitor(right, type_parameter_checker)) AttributeError: 'NoneType' object has no attribute 'accept'
AttributeError
def allow_jump(self, index: int) -> None: # self.frames and self.options_on_return have different lengths # so make sure the index is positive if index < 0: index += len(self.options_on_return) frame = Frame() for f in self.frames[index + 1 :]: frame.update(f) if f.unreachable: frame.unreachable = True self.options_on_return[index].append(frame)
def allow_jump(self, index: int) -> None: # self.frames and self.options_on_return have different lengths # so make sure the index is positive if index < 0: index += len(self.options_on_return) frame = Frame() for f in self.frames[index + 1 :]: frame.update(f) self.options_on_return[index].append(frame)
https://github.com/python/mypy/issues/1289
Traceback (most recent call last): File "./scripts/mypy", line 6, in <module> main(__file__) File "mypy/mypy/main.py", line 50, in main type_check_only(sources, bin_dir, options) File "mypy/mypy/main.py", line 94, in type_check_only python_path=options.python_path) File "mypy/mypy/build.py", line 210, in build result = manager.process(initial_states) File "mypy/mypy/build.py", line 425, in process next.process() File "mypy/mypy/build.py", line 930, in process self.type_checker().visit_file(self.tree, self.tree.path) File "mypy/mypy/checker.py", line 409, in visit_file self.accept(d) File "mypy/mypy/checker.py", line 450, in accept typ = node.accept(self) File "mypy/mypy/nodes.py", line 707, in accept return visitor.visit_try_stmt(self) File "mypy/mypy/checker.py", line 1732, in visit_try_stmt self.accept(s.else_body) File "mypy/mypy/checker.py", line 450, in accept typ = node.accept(self) File "mypy/mypy/nodes.py", line 526, in accept return visitor.visit_block(self) File "mypy/mypy/checker.py", line 1113, in visit_block self.accept(s) File "mypy/mypy/checker.py", line 450, in accept typ = node.accept(self) File "mypy/mypy/nodes.py", line 382, in accept return visitor.visit_func_def(self) File "mypy/mypy/checker.py", line 594, in visit_func_def 'redefinition with type') File "mypy/mypy/checker.py", line 2117, in check_subtype if not is_subtype(subtype, supertype): File "mypy/mypy/subtypes.py", line 49, in is_subtype return left.accept(SubtypeVisitor(right, type_parameter_checker)) AttributeError: 'NoneType' object has no attribute 'accept'
AttributeError
def frame_context( self, *, can_skip: bool, fall_through: int = 1, break_frame: int = 0, continue_frame: int = 0, try_frame: bool = False, ) -> Iterator[Frame]: """Return a context manager that pushes/pops frames on enter/exit. If can_skip is True, control flow is allowed to bypass the newly-created frame. If fall_through > 0, then it will allow control flow that falls off the end of the frame to escape to its ancestor `fall_through` levels higher. Otherwise control flow ends at the end of the frame. If break_frame > 0, then 'break' statements within this frame will jump out to the frame break_frame levels higher than the frame created by this call to frame_context. Similarly for continue_frame and 'continue' statements. If try_frame is true, then execution is allowed to jump at any point within the newly created frame (or its descendents) to its parent (i.e., to the frame that was on top before this call to frame_context). After the context manager exits, self.last_pop_changed indicates whether any types changed in the newly-topmost frame as a result of popping this frame. """ assert len(self.frames) > 1 if break_frame: self.break_frames.append(len(self.frames) - break_frame) if continue_frame: self.continue_frames.append(len(self.frames) - continue_frame) if try_frame: self.try_frames.add(len(self.frames) - 1) new_frame = self.push_frame() if try_frame: # An exception may occur immediately self.allow_jump(-1) yield new_frame self.pop_frame(can_skip, fall_through) if break_frame: self.break_frames.pop() if continue_frame: self.continue_frames.pop() if try_frame: self.try_frames.remove(len(self.frames) - 1)
def frame_context(self, fall_through: int = 0) -> Iterator[Frame]: """Return a context manager that pushes/pops frames on enter/exit. If fall_through > 0, then it will allow the frame to escape to its ancestor `fall_through` levels higher. A simple 'with binder.frame_context(): pass' will change the last_pop_* flags but nothing else. """ was_breaking_out = self.breaking_out yield self.push_frame() self.pop_frame(fall_through) self.breaking_out = was_breaking_out
https://github.com/python/mypy/issues/1289
Traceback (most recent call last): File "./scripts/mypy", line 6, in <module> main(__file__) File "mypy/mypy/main.py", line 50, in main type_check_only(sources, bin_dir, options) File "mypy/mypy/main.py", line 94, in type_check_only python_path=options.python_path) File "mypy/mypy/build.py", line 210, in build result = manager.process(initial_states) File "mypy/mypy/build.py", line 425, in process next.process() File "mypy/mypy/build.py", line 930, in process self.type_checker().visit_file(self.tree, self.tree.path) File "mypy/mypy/checker.py", line 409, in visit_file self.accept(d) File "mypy/mypy/checker.py", line 450, in accept typ = node.accept(self) File "mypy/mypy/nodes.py", line 707, in accept return visitor.visit_try_stmt(self) File "mypy/mypy/checker.py", line 1732, in visit_try_stmt self.accept(s.else_body) File "mypy/mypy/checker.py", line 450, in accept typ = node.accept(self) File "mypy/mypy/nodes.py", line 526, in accept return visitor.visit_block(self) File "mypy/mypy/checker.py", line 1113, in visit_block self.accept(s) File "mypy/mypy/checker.py", line 450, in accept typ = node.accept(self) File "mypy/mypy/nodes.py", line 382, in accept return visitor.visit_func_def(self) File "mypy/mypy/checker.py", line 594, in visit_func_def 'redefinition with type') File "mypy/mypy/checker.py", line 2117, in check_subtype if not is_subtype(subtype, supertype): File "mypy/mypy/subtypes.py", line 49, in is_subtype return left.accept(SubtypeVisitor(right, type_parameter_checker)) AttributeError: 'NoneType' object has no attribute 'accept'
AttributeError
def visit_file(self, file_node: MypyFile, path: str, options: Options) -> None: """Type check a mypy file with the given path.""" self.options = options self.pass_num = 0 self.is_stub = file_node.is_stub self.errors.set_file(path) self.globals = file_node.names self.enter_partial_types() self.is_typeshed_stub = self.errors.is_typeshed_file(path) self.module_type_map = {} self.module_refs = set() if self.options.strict_optional_whitelist is None: self.suppress_none_errors = not self.options.show_none_errors else: self.suppress_none_errors = not any( fnmatch.fnmatch(path, pattern) for pattern in self.options.strict_optional_whitelist ) with self.binder.top_frame_context(): for d in file_node.defs: self.accept(d) self.leave_partial_types() if self.deferred_nodes: self.check_second_pass() self.current_node_deferred = False all_ = self.globals.get("__all__") if all_ is not None and all_.type is not None: seq_str = self.named_generic_type( "typing.Sequence", [self.named_type("builtins.str")] ) if not is_subtype(all_.type, seq_str): str_seq_s, all_s = self.msg.format_distinctly(seq_str, all_.type) self.fail(messages.ALL_MUST_BE_SEQ_STR.format(str_seq_s, all_s), all_.node) del self.options
def visit_file(self, file_node: MypyFile, path: str, options: Options) -> None: """Type check a mypy file with the given path.""" self.options = options self.pass_num = 0 self.is_stub = file_node.is_stub self.errors.set_file(path) self.globals = file_node.names self.enter_partial_types() self.is_typeshed_stub = self.errors.is_typeshed_file(path) self.module_type_map = {} self.module_refs = set() if self.options.strict_optional_whitelist is None: self.suppress_none_errors = not self.options.show_none_errors else: self.suppress_none_errors = not any( fnmatch.fnmatch(path, pattern) for pattern in self.options.strict_optional_whitelist ) for d in file_node.defs: self.accept(d) self.leave_partial_types() if self.deferred_nodes: self.check_second_pass() self.current_node_deferred = False all_ = self.globals.get("__all__") if all_ is not None and all_.type is not None: seq_str = self.named_generic_type( "typing.Sequence", [self.named_type("builtins.str")] ) if not is_subtype(all_.type, seq_str): str_seq_s, all_s = self.msg.format_distinctly(seq_str, all_.type) self.fail(messages.ALL_MUST_BE_SEQ_STR.format(str_seq_s, all_s), all_.node) del self.options
https://github.com/python/mypy/issues/1289
Traceback (most recent call last): File "./scripts/mypy", line 6, in <module> main(__file__) File "mypy/mypy/main.py", line 50, in main type_check_only(sources, bin_dir, options) File "mypy/mypy/main.py", line 94, in type_check_only python_path=options.python_path) File "mypy/mypy/build.py", line 210, in build result = manager.process(initial_states) File "mypy/mypy/build.py", line 425, in process next.process() File "mypy/mypy/build.py", line 930, in process self.type_checker().visit_file(self.tree, self.tree.path) File "mypy/mypy/checker.py", line 409, in visit_file self.accept(d) File "mypy/mypy/checker.py", line 450, in accept typ = node.accept(self) File "mypy/mypy/nodes.py", line 707, in accept return visitor.visit_try_stmt(self) File "mypy/mypy/checker.py", line 1732, in visit_try_stmt self.accept(s.else_body) File "mypy/mypy/checker.py", line 450, in accept typ = node.accept(self) File "mypy/mypy/nodes.py", line 526, in accept return visitor.visit_block(self) File "mypy/mypy/checker.py", line 1113, in visit_block self.accept(s) File "mypy/mypy/checker.py", line 450, in accept typ = node.accept(self) File "mypy/mypy/nodes.py", line 382, in accept return visitor.visit_func_def(self) File "mypy/mypy/checker.py", line 594, in visit_func_def 'redefinition with type') File "mypy/mypy/checker.py", line 2117, in check_subtype if not is_subtype(subtype, supertype): File "mypy/mypy/subtypes.py", line 49, in is_subtype return left.accept(SubtypeVisitor(right, type_parameter_checker)) AttributeError: 'NoneType' object has no attribute 'accept'
AttributeError
def accept_loop( self, body: Statement, else_body: Statement = None, *, exit_condition: Expression = None, ) -> Type: """Repeatedly type check a loop body until the frame doesn't change. If exit_condition is set, assume it must be False on exit from the loop. Then check the else_body. """ # The outer frame accumulates the results of all iterations with self.binder.frame_context(can_skip=False): while True: with self.binder.frame_context( can_skip=True, break_frame=2, continue_frame=1 ): self.accept(body) if not self.binder.last_pop_changed: break if exit_condition: _, else_map = self.find_isinstance_check(exit_condition) self.push_type_map(else_map) if else_body: self.accept(else_body)
def accept_loop(self, body: Union[IfStmt, Block], else_body: Block = None) -> Type: """Repeatedly type check a loop body until the frame doesn't change. Then check the else_body. """ # The outer frame accumulates the results of all iterations with self.binder.frame_context(1) as outer_frame: self.binder.push_loop_frame() while True: with self.binder.frame_context(1): # We may skip each iteration self.binder.options_on_return[-1].append(outer_frame) self.accept(body) if not self.binder.last_pop_changed: break self.binder.pop_loop_frame() if else_body: self.accept(else_body)
https://github.com/python/mypy/issues/1289
Traceback (most recent call last): File "./scripts/mypy", line 6, in <module> main(__file__) File "mypy/mypy/main.py", line 50, in main type_check_only(sources, bin_dir, options) File "mypy/mypy/main.py", line 94, in type_check_only python_path=options.python_path) File "mypy/mypy/build.py", line 210, in build result = manager.process(initial_states) File "mypy/mypy/build.py", line 425, in process next.process() File "mypy/mypy/build.py", line 930, in process self.type_checker().visit_file(self.tree, self.tree.path) File "mypy/mypy/checker.py", line 409, in visit_file self.accept(d) File "mypy/mypy/checker.py", line 450, in accept typ = node.accept(self) File "mypy/mypy/nodes.py", line 707, in accept return visitor.visit_try_stmt(self) File "mypy/mypy/checker.py", line 1732, in visit_try_stmt self.accept(s.else_body) File "mypy/mypy/checker.py", line 450, in accept typ = node.accept(self) File "mypy/mypy/nodes.py", line 526, in accept return visitor.visit_block(self) File "mypy/mypy/checker.py", line 1113, in visit_block self.accept(s) File "mypy/mypy/checker.py", line 450, in accept typ = node.accept(self) File "mypy/mypy/nodes.py", line 382, in accept return visitor.visit_func_def(self) File "mypy/mypy/checker.py", line 594, in visit_func_def 'redefinition with type') File "mypy/mypy/checker.py", line 2117, in check_subtype if not is_subtype(subtype, supertype): File "mypy/mypy/subtypes.py", line 49, in is_subtype return left.accept(SubtypeVisitor(right, type_parameter_checker)) AttributeError: 'NoneType' object has no attribute 'accept'
AttributeError
def check_func_def(self, defn: FuncItem, typ: CallableType, name: str) -> None: """Type check a function definition.""" # Expand type variables with value restrictions to ordinary types. for item, typ in self.expand_typevars(defn, typ): old_binder = self.binder self.binder = ConditionalTypeBinder() with self.binder.top_frame_context(): defn.expanded.append(item) # We may be checking a function definition or an anonymous # function. In the first case, set up another reference with the # precise type. if isinstance(item, FuncDef): fdef = item else: fdef = None if fdef: # Check if __init__ has an invalid, non-None return type. if ( fdef.info and fdef.name() == "__init__" and not isinstance(typ.ret_type, (Void, NoneTyp)) and not self.dynamic_funcs[-1] ): self.fail(messages.INIT_MUST_HAVE_NONE_RETURN_TYPE, item.type) show_untyped = ( not self.is_typeshed_stub or self.options.warn_incomplete_stub ) if self.options.disallow_untyped_defs and show_untyped: # Check for functions with unspecified/not fully specified types. def is_implicit_any(t: Type) -> bool: return isinstance(t, AnyType) and t.implicit if fdef.type is None: self.fail(messages.FUNCTION_TYPE_EXPECTED, fdef) elif isinstance(fdef.type, CallableType): if is_implicit_any(fdef.type.ret_type): self.fail(messages.RETURN_TYPE_EXPECTED, fdef) if any(is_implicit_any(t) for t in fdef.type.arg_types): self.fail(messages.ARGUMENT_TYPE_EXPECTED, fdef) if name in nodes.reverse_op_method_set: self.check_reverse_op_method(item, typ, name) elif name == "__getattr__": self.check_getattr_method(typ, defn) # Refuse contravariant return type variable if isinstance(typ.ret_type, TypeVarType): if typ.ret_type.variance == CONTRAVARIANT: self.fail( messages.RETURN_TYPE_CANNOT_BE_CONTRAVARIANT, typ.ret_type ) # Check that Generator functions have the appropriate return type. if defn.is_generator: if not self.is_generator_return_type(typ.ret_type, defn.is_coroutine): self.fail(messages.INVALID_RETURN_TYPE_FOR_GENERATOR, typ) # Python 2 generators aren't allowed to return values. if ( self.options.python_version[0] == 2 and isinstance(typ.ret_type, Instance) and typ.ret_type.type.fullname() == "typing.Generator" ): if not isinstance(typ.ret_type.args[2], (Void, NoneTyp, AnyType)): self.fail(messages.INVALID_GENERATOR_RETURN_ITEM_TYPE, typ) # Fix the type if decorated with `@types.coroutine` or `@asyncio.coroutine`. if defn.is_awaitable_coroutine: # Update the return type to AwaitableGenerator. # (This doesn't exist in typing.py, only in typing.pyi.) t = typ.ret_type c = defn.is_coroutine ty = self.get_generator_yield_type(t, c) tc = self.get_generator_receive_type(t, c) tr = self.get_generator_return_type(t, c) ret_type = self.named_generic_type( "typing.AwaitableGenerator", [ty, tc, tr, t] ) typ = typ.copy_modified(ret_type=ret_type) defn.type = typ # Push return type. self.return_types.append(typ.ret_type) # Store argument types. for i in range(len(typ.arg_types)): arg_type = typ.arg_types[i] # Refuse covariant parameter type variables if isinstance(arg_type, TypeVarType): if arg_type.variance == COVARIANT: self.fail( messages.FUNCTION_PARAMETER_CANNOT_BE_COVARIANT, arg_type ) if typ.arg_kinds[i] == nodes.ARG_STAR: # builtins.tuple[T] is typing.Tuple[T, ...] arg_type = self.named_generic_type("builtins.tuple", [arg_type]) elif typ.arg_kinds[i] == nodes.ARG_STAR2: arg_type = self.named_generic_type( "builtins.dict", [self.str_type(), arg_type] ) item.arguments[i].variable.type = arg_type # Type check initialization expressions. for arg in item.arguments: init = arg.initialization_statement if init: self.accept(init) # Type check body in a new scope. with self.binder.top_frame_context(): self.accept(item.body) unreachable = self.binder.is_unreachable() if ( self.options.warn_no_return and not unreachable and not isinstance(self.return_types[-1], (Void, AnyType)) and not defn.is_generator ): # Control flow fell off the end of a function that was # declared to return a non-None type. # Allow functions that are entirely pass/Ellipsis. if self.is_trivial_body(defn.body): pass else: self.msg.note(messages.MISSING_RETURN_STATEMENT, defn) self.return_types.pop() self.binder = old_binder
def check_func_def(self, defn: FuncItem, typ: CallableType, name: str) -> None: """Type check a function definition.""" # Expand type variables with value restrictions to ordinary types. for item, typ in self.expand_typevars(defn, typ): old_binder = self.binder self.binder = ConditionalTypeBinder() with self.binder.frame_context(): defn.expanded.append(item) # We may be checking a function definition or an anonymous # function. In the first case, set up another reference with the # precise type. if isinstance(item, FuncDef): fdef = item else: fdef = None if fdef: # Check if __init__ has an invalid, non-None return type. if ( fdef.info and fdef.name() == "__init__" and not isinstance(typ.ret_type, (Void, NoneTyp)) and not self.dynamic_funcs[-1] ): self.fail(messages.INIT_MUST_HAVE_NONE_RETURN_TYPE, item.type) show_untyped = ( not self.is_typeshed_stub or self.options.warn_incomplete_stub ) if self.options.disallow_untyped_defs and show_untyped: # Check for functions with unspecified/not fully specified types. def is_implicit_any(t: Type) -> bool: return isinstance(t, AnyType) and t.implicit if fdef.type is None: self.fail(messages.FUNCTION_TYPE_EXPECTED, fdef) elif isinstance(fdef.type, CallableType): if is_implicit_any(fdef.type.ret_type): self.fail(messages.RETURN_TYPE_EXPECTED, fdef) if any(is_implicit_any(t) for t in fdef.type.arg_types): self.fail(messages.ARGUMENT_TYPE_EXPECTED, fdef) if name in nodes.reverse_op_method_set: self.check_reverse_op_method(item, typ, name) elif name == "__getattr__": self.check_getattr_method(typ, defn) # Refuse contravariant return type variable if isinstance(typ.ret_type, TypeVarType): if typ.ret_type.variance == CONTRAVARIANT: self.fail( messages.RETURN_TYPE_CANNOT_BE_CONTRAVARIANT, typ.ret_type ) # Check that Generator functions have the appropriate return type. if defn.is_generator: if not self.is_generator_return_type(typ.ret_type, defn.is_coroutine): self.fail(messages.INVALID_RETURN_TYPE_FOR_GENERATOR, typ) # Python 2 generators aren't allowed to return values. if ( self.options.python_version[0] == 2 and isinstance(typ.ret_type, Instance) and typ.ret_type.type.fullname() == "typing.Generator" ): if not isinstance(typ.ret_type.args[2], (Void, NoneTyp, AnyType)): self.fail(messages.INVALID_GENERATOR_RETURN_ITEM_TYPE, typ) # Fix the type if decorated with `@types.coroutine` or `@asyncio.coroutine`. if defn.is_awaitable_coroutine: # Update the return type to AwaitableGenerator. # (This doesn't exist in typing.py, only in typing.pyi.) t = typ.ret_type c = defn.is_coroutine ty = self.get_generator_yield_type(t, c) tc = self.get_generator_receive_type(t, c) tr = self.get_generator_return_type(t, c) ret_type = self.named_generic_type( "typing.AwaitableGenerator", [ty, tc, tr, t] ) typ = typ.copy_modified(ret_type=ret_type) defn.type = typ # Push return type. self.return_types.append(typ.ret_type) # Store argument types. for i in range(len(typ.arg_types)): arg_type = typ.arg_types[i] # Refuse covariant parameter type variables if isinstance(arg_type, TypeVarType): if arg_type.variance == COVARIANT: self.fail( messages.FUNCTION_PARAMETER_CANNOT_BE_COVARIANT, arg_type ) if typ.arg_kinds[i] == nodes.ARG_STAR: # builtins.tuple[T] is typing.Tuple[T, ...] arg_type = self.named_generic_type("builtins.tuple", [arg_type]) elif typ.arg_kinds[i] == nodes.ARG_STAR2: arg_type = self.named_generic_type( "builtins.dict", [self.str_type(), arg_type] ) item.arguments[i].variable.type = arg_type # Type check initialization expressions. for arg in item.arguments: init = arg.initialization_statement if init: self.accept(init) # Type check body in a new scope. with self.binder.frame_context(): self.accept(item.body) self.return_types.pop() self.binder = old_binder
https://github.com/python/mypy/issues/1289
Traceback (most recent call last): File "./scripts/mypy", line 6, in <module> main(__file__) File "mypy/mypy/main.py", line 50, in main type_check_only(sources, bin_dir, options) File "mypy/mypy/main.py", line 94, in type_check_only python_path=options.python_path) File "mypy/mypy/build.py", line 210, in build result = manager.process(initial_states) File "mypy/mypy/build.py", line 425, in process next.process() File "mypy/mypy/build.py", line 930, in process self.type_checker().visit_file(self.tree, self.tree.path) File "mypy/mypy/checker.py", line 409, in visit_file self.accept(d) File "mypy/mypy/checker.py", line 450, in accept typ = node.accept(self) File "mypy/mypy/nodes.py", line 707, in accept return visitor.visit_try_stmt(self) File "mypy/mypy/checker.py", line 1732, in visit_try_stmt self.accept(s.else_body) File "mypy/mypy/checker.py", line 450, in accept typ = node.accept(self) File "mypy/mypy/nodes.py", line 526, in accept return visitor.visit_block(self) File "mypy/mypy/checker.py", line 1113, in visit_block self.accept(s) File "mypy/mypy/checker.py", line 450, in accept typ = node.accept(self) File "mypy/mypy/nodes.py", line 382, in accept return visitor.visit_func_def(self) File "mypy/mypy/checker.py", line 594, in visit_func_def 'redefinition with type') File "mypy/mypy/checker.py", line 2117, in check_subtype if not is_subtype(subtype, supertype): File "mypy/mypy/subtypes.py", line 49, in is_subtype return left.accept(SubtypeVisitor(right, type_parameter_checker)) AttributeError: 'NoneType' object has no attribute 'accept'
AttributeError
def visit_class_def(self, defn: ClassDef) -> Type: """Type check a class definition.""" typ = defn.info self.errors.push_type(defn.name) self.enter_partial_types() old_binder = self.binder self.binder = ConditionalTypeBinder() with self.binder.top_frame_context(): self.accept(defn.defs) self.binder = old_binder if not defn.has_incompatible_baseclass: # Otherwise we've already found errors; more errors are not useful self.check_multiple_inheritance(typ) self.leave_partial_types() self.errors.pop_type()
def visit_class_def(self, defn: ClassDef) -> Type: """Type check a class definition.""" typ = defn.info self.errors.push_type(defn.name) self.enter_partial_types() old_binder = self.binder self.binder = ConditionalTypeBinder() with self.binder.frame_context(): self.accept(defn.defs) self.binder = old_binder if not defn.has_incompatible_baseclass: # Otherwise we've already found errors; more errors are not useful self.check_multiple_inheritance(typ) self.leave_partial_types() self.errors.pop_type()
https://github.com/python/mypy/issues/1289
Traceback (most recent call last): File "./scripts/mypy", line 6, in <module> main(__file__) File "mypy/mypy/main.py", line 50, in main type_check_only(sources, bin_dir, options) File "mypy/mypy/main.py", line 94, in type_check_only python_path=options.python_path) File "mypy/mypy/build.py", line 210, in build result = manager.process(initial_states) File "mypy/mypy/build.py", line 425, in process next.process() File "mypy/mypy/build.py", line 930, in process self.type_checker().visit_file(self.tree, self.tree.path) File "mypy/mypy/checker.py", line 409, in visit_file self.accept(d) File "mypy/mypy/checker.py", line 450, in accept typ = node.accept(self) File "mypy/mypy/nodes.py", line 707, in accept return visitor.visit_try_stmt(self) File "mypy/mypy/checker.py", line 1732, in visit_try_stmt self.accept(s.else_body) File "mypy/mypy/checker.py", line 450, in accept typ = node.accept(self) File "mypy/mypy/nodes.py", line 526, in accept return visitor.visit_block(self) File "mypy/mypy/checker.py", line 1113, in visit_block self.accept(s) File "mypy/mypy/checker.py", line 450, in accept typ = node.accept(self) File "mypy/mypy/nodes.py", line 382, in accept return visitor.visit_func_def(self) File "mypy/mypy/checker.py", line 594, in visit_func_def 'redefinition with type') File "mypy/mypy/checker.py", line 2117, in check_subtype if not is_subtype(subtype, supertype): File "mypy/mypy/subtypes.py", line 49, in is_subtype return left.accept(SubtypeVisitor(right, type_parameter_checker)) AttributeError: 'NoneType' object has no attribute 'accept'
AttributeError
def visit_block(self, b: Block) -> Type: if b.is_unreachable: return None for s in b.body: if self.binder.is_unreachable(): break self.accept(s)
def visit_block(self, b: Block) -> Type: if b.is_unreachable: return None for s in b.body: self.accept(s) if self.binder.breaking_out: break
https://github.com/python/mypy/issues/1289
Traceback (most recent call last): File "./scripts/mypy", line 6, in <module> main(__file__) File "mypy/mypy/main.py", line 50, in main type_check_only(sources, bin_dir, options) File "mypy/mypy/main.py", line 94, in type_check_only python_path=options.python_path) File "mypy/mypy/build.py", line 210, in build result = manager.process(initial_states) File "mypy/mypy/build.py", line 425, in process next.process() File "mypy/mypy/build.py", line 930, in process self.type_checker().visit_file(self.tree, self.tree.path) File "mypy/mypy/checker.py", line 409, in visit_file self.accept(d) File "mypy/mypy/checker.py", line 450, in accept typ = node.accept(self) File "mypy/mypy/nodes.py", line 707, in accept return visitor.visit_try_stmt(self) File "mypy/mypy/checker.py", line 1732, in visit_try_stmt self.accept(s.else_body) File "mypy/mypy/checker.py", line 450, in accept typ = node.accept(self) File "mypy/mypy/nodes.py", line 526, in accept return visitor.visit_block(self) File "mypy/mypy/checker.py", line 1113, in visit_block self.accept(s) File "mypy/mypy/checker.py", line 450, in accept typ = node.accept(self) File "mypy/mypy/nodes.py", line 382, in accept return visitor.visit_func_def(self) File "mypy/mypy/checker.py", line 594, in visit_func_def 'redefinition with type') File "mypy/mypy/checker.py", line 2117, in check_subtype if not is_subtype(subtype, supertype): File "mypy/mypy/subtypes.py", line 49, in is_subtype return left.accept(SubtypeVisitor(right, type_parameter_checker)) AttributeError: 'NoneType' object has no attribute 'accept'
AttributeError
def visit_return_stmt(self, s: ReturnStmt) -> Type: """Type check a return statement.""" self.check_return_stmt(s) self.binder.unreachable()
def visit_return_stmt(self, s: ReturnStmt) -> Type: """Type check a return statement.""" self.binder.breaking_out = True if self.is_within_function(): defn = self.function_stack[-1] if defn.is_generator: return_type = self.get_generator_return_type( self.return_types[-1], defn.is_coroutine ) else: return_type = self.return_types[-1] if s.expr: # Return with a value. typ = self.accept(s.expr, return_type) # Returning a value of type Any is always fine. if isinstance(typ, AnyType): return None if self.is_unusable_type(return_type): # Lambdas are allowed to have a unusable returns. # Functions returning a value of type None are allowed to have a Void return. if isinstance(self.function_stack[-1], FuncExpr) or isinstance( typ, NoneTyp ): return None self.fail(messages.NO_RETURN_VALUE_EXPECTED, s) else: self.check_subtype( subtype_label="got", subtype=typ, supertype_label="expected", supertype=return_type, context=s, msg=messages.INCOMPATIBLE_RETURN_VALUE_TYPE, ) else: # Empty returns are valid in Generators with Any typed returns. if self.function_stack[-1].is_generator and isinstance( return_type, AnyType ): return None if isinstance(return_type, (Void, NoneTyp, AnyType)): return None if self.in_checked_function(): self.fail(messages.RETURN_VALUE_EXPECTED, s)
https://github.com/python/mypy/issues/1289
Traceback (most recent call last): File "./scripts/mypy", line 6, in <module> main(__file__) File "mypy/mypy/main.py", line 50, in main type_check_only(sources, bin_dir, options) File "mypy/mypy/main.py", line 94, in type_check_only python_path=options.python_path) File "mypy/mypy/build.py", line 210, in build result = manager.process(initial_states) File "mypy/mypy/build.py", line 425, in process next.process() File "mypy/mypy/build.py", line 930, in process self.type_checker().visit_file(self.tree, self.tree.path) File "mypy/mypy/checker.py", line 409, in visit_file self.accept(d) File "mypy/mypy/checker.py", line 450, in accept typ = node.accept(self) File "mypy/mypy/nodes.py", line 707, in accept return visitor.visit_try_stmt(self) File "mypy/mypy/checker.py", line 1732, in visit_try_stmt self.accept(s.else_body) File "mypy/mypy/checker.py", line 450, in accept typ = node.accept(self) File "mypy/mypy/nodes.py", line 526, in accept return visitor.visit_block(self) File "mypy/mypy/checker.py", line 1113, in visit_block self.accept(s) File "mypy/mypy/checker.py", line 450, in accept typ = node.accept(self) File "mypy/mypy/nodes.py", line 382, in accept return visitor.visit_func_def(self) File "mypy/mypy/checker.py", line 594, in visit_func_def 'redefinition with type') File "mypy/mypy/checker.py", line 2117, in check_subtype if not is_subtype(subtype, supertype): File "mypy/mypy/subtypes.py", line 49, in is_subtype return left.accept(SubtypeVisitor(right, type_parameter_checker)) AttributeError: 'NoneType' object has no attribute 'accept'
AttributeError
def visit_if_stmt(self, s: IfStmt) -> Type: """Type check an if statement.""" # This frame records the knowledge from previous if/elif clauses not being taken. # Fall-through to the original frame is handled explicitly in each block. with self.binder.frame_context(can_skip=False, fall_through=0): for e, b in zip(s.expr, s.body): t = self.accept(e) self.check_usable_type(t, e) if_map, else_map = self.find_isinstance_check(e) # XXX Issue a warning if condition is always False? with self.binder.frame_context(can_skip=True, fall_through=2): self.push_type_map(if_map) self.accept(b) # XXX Issue a warning if condition is always True? self.push_type_map(else_map) with self.binder.frame_context(can_skip=False, fall_through=2): if s.else_body: self.accept(s.else_body) return None
def visit_if_stmt(self, s: IfStmt) -> Type: """Type check an if statement.""" breaking_out = True # This frame records the knowledge from previous if/elif clauses not being taken. with self.binder.frame_context(): for e, b in zip(s.expr, s.body): t = self.accept(e) self.check_usable_type(t, e) if_map, else_map = find_isinstance_check(e, self.type_map) if if_map is None: # The condition is always false # XXX should issue a warning? pass else: # Only type check body if the if condition can be true. with self.binder.frame_context(2): if if_map: for var, type in if_map.items(): self.binder.push(var, type) self.accept(b) breaking_out = breaking_out and self.binder.last_pop_breaking_out if else_map: for var, type in else_map.items(): self.binder.push(var, type) if else_map is None: # The condition is always true => remaining elif/else blocks # can never be reached. # Might also want to issue a warning # print("Warning: isinstance always true") break else: # Didn't break => can't prove one of the conditions is always true with self.binder.frame_context(2): if s.else_body: self.accept(s.else_body) breaking_out = breaking_out and self.binder.last_pop_breaking_out if breaking_out: self.binder.breaking_out = True return None
https://github.com/python/mypy/issues/1289
Traceback (most recent call last): File "./scripts/mypy", line 6, in <module> main(__file__) File "mypy/mypy/main.py", line 50, in main type_check_only(sources, bin_dir, options) File "mypy/mypy/main.py", line 94, in type_check_only python_path=options.python_path) File "mypy/mypy/build.py", line 210, in build result = manager.process(initial_states) File "mypy/mypy/build.py", line 425, in process next.process() File "mypy/mypy/build.py", line 930, in process self.type_checker().visit_file(self.tree, self.tree.path) File "mypy/mypy/checker.py", line 409, in visit_file self.accept(d) File "mypy/mypy/checker.py", line 450, in accept typ = node.accept(self) File "mypy/mypy/nodes.py", line 707, in accept return visitor.visit_try_stmt(self) File "mypy/mypy/checker.py", line 1732, in visit_try_stmt self.accept(s.else_body) File "mypy/mypy/checker.py", line 450, in accept typ = node.accept(self) File "mypy/mypy/nodes.py", line 526, in accept return visitor.visit_block(self) File "mypy/mypy/checker.py", line 1113, in visit_block self.accept(s) File "mypy/mypy/checker.py", line 450, in accept typ = node.accept(self) File "mypy/mypy/nodes.py", line 382, in accept return visitor.visit_func_def(self) File "mypy/mypy/checker.py", line 594, in visit_func_def 'redefinition with type') File "mypy/mypy/checker.py", line 2117, in check_subtype if not is_subtype(subtype, supertype): File "mypy/mypy/subtypes.py", line 49, in is_subtype return left.accept(SubtypeVisitor(right, type_parameter_checker)) AttributeError: 'NoneType' object has no attribute 'accept'
AttributeError
def visit_while_stmt(self, s: WhileStmt) -> Type: """Type check a while statement.""" self.accept_loop( IfStmt([s.expr], [s.body], None), s.else_body, exit_condition=s.expr )
def visit_while_stmt(self, s: WhileStmt) -> Type: """Type check a while statement.""" self.accept_loop(IfStmt([s.expr], [s.body], None), s.else_body)
https://github.com/python/mypy/issues/1289
Traceback (most recent call last): File "./scripts/mypy", line 6, in <module> main(__file__) File "mypy/mypy/main.py", line 50, in main type_check_only(sources, bin_dir, options) File "mypy/mypy/main.py", line 94, in type_check_only python_path=options.python_path) File "mypy/mypy/build.py", line 210, in build result = manager.process(initial_states) File "mypy/mypy/build.py", line 425, in process next.process() File "mypy/mypy/build.py", line 930, in process self.type_checker().visit_file(self.tree, self.tree.path) File "mypy/mypy/checker.py", line 409, in visit_file self.accept(d) File "mypy/mypy/checker.py", line 450, in accept typ = node.accept(self) File "mypy/mypy/nodes.py", line 707, in accept return visitor.visit_try_stmt(self) File "mypy/mypy/checker.py", line 1732, in visit_try_stmt self.accept(s.else_body) File "mypy/mypy/checker.py", line 450, in accept typ = node.accept(self) File "mypy/mypy/nodes.py", line 526, in accept return visitor.visit_block(self) File "mypy/mypy/checker.py", line 1113, in visit_block self.accept(s) File "mypy/mypy/checker.py", line 450, in accept typ = node.accept(self) File "mypy/mypy/nodes.py", line 382, in accept return visitor.visit_func_def(self) File "mypy/mypy/checker.py", line 594, in visit_func_def 'redefinition with type') File "mypy/mypy/checker.py", line 2117, in check_subtype if not is_subtype(subtype, supertype): File "mypy/mypy/subtypes.py", line 49, in is_subtype return left.accept(SubtypeVisitor(right, type_parameter_checker)) AttributeError: 'NoneType' object has no attribute 'accept'
AttributeError
def visit_assert_stmt(self, s: AssertStmt) -> Type: self.accept(s.expr) # If this is asserting some isinstance check, bind that type in the following code true_map, _ = self.find_isinstance_check(s.expr) self.push_type_map(true_map)
def visit_assert_stmt(self, s: AssertStmt) -> Type: self.accept(s.expr) # If this is asserting some isinstance check, bind that type in the following code true_map, _ = find_isinstance_check(s.expr, self.type_map) if true_map: for var, type in true_map.items(): self.binder.push(var, type)
https://github.com/python/mypy/issues/1289
Traceback (most recent call last): File "./scripts/mypy", line 6, in <module> main(__file__) File "mypy/mypy/main.py", line 50, in main type_check_only(sources, bin_dir, options) File "mypy/mypy/main.py", line 94, in type_check_only python_path=options.python_path) File "mypy/mypy/build.py", line 210, in build result = manager.process(initial_states) File "mypy/mypy/build.py", line 425, in process next.process() File "mypy/mypy/build.py", line 930, in process self.type_checker().visit_file(self.tree, self.tree.path) File "mypy/mypy/checker.py", line 409, in visit_file self.accept(d) File "mypy/mypy/checker.py", line 450, in accept typ = node.accept(self) File "mypy/mypy/nodes.py", line 707, in accept return visitor.visit_try_stmt(self) File "mypy/mypy/checker.py", line 1732, in visit_try_stmt self.accept(s.else_body) File "mypy/mypy/checker.py", line 450, in accept typ = node.accept(self) File "mypy/mypy/nodes.py", line 526, in accept return visitor.visit_block(self) File "mypy/mypy/checker.py", line 1113, in visit_block self.accept(s) File "mypy/mypy/checker.py", line 450, in accept typ = node.accept(self) File "mypy/mypy/nodes.py", line 382, in accept return visitor.visit_func_def(self) File "mypy/mypy/checker.py", line 594, in visit_func_def 'redefinition with type') File "mypy/mypy/checker.py", line 2117, in check_subtype if not is_subtype(subtype, supertype): File "mypy/mypy/subtypes.py", line 49, in is_subtype return left.accept(SubtypeVisitor(right, type_parameter_checker)) AttributeError: 'NoneType' object has no attribute 'accept'
AttributeError
def visit_raise_stmt(self, s: RaiseStmt) -> Type: """Type check a raise statement.""" if s.expr: self.type_check_raise(s.expr, s) if s.from_expr: self.type_check_raise(s.from_expr, s) self.binder.unreachable()
def visit_raise_stmt(self, s: RaiseStmt) -> Type: """Type check a raise statement.""" self.binder.breaking_out = True if s.expr: self.type_check_raise(s.expr, s) if s.from_expr: self.type_check_raise(s.from_expr, s)
https://github.com/python/mypy/issues/1289
Traceback (most recent call last): File "./scripts/mypy", line 6, in <module> main(__file__) File "mypy/mypy/main.py", line 50, in main type_check_only(sources, bin_dir, options) File "mypy/mypy/main.py", line 94, in type_check_only python_path=options.python_path) File "mypy/mypy/build.py", line 210, in build result = manager.process(initial_states) File "mypy/mypy/build.py", line 425, in process next.process() File "mypy/mypy/build.py", line 930, in process self.type_checker().visit_file(self.tree, self.tree.path) File "mypy/mypy/checker.py", line 409, in visit_file self.accept(d) File "mypy/mypy/checker.py", line 450, in accept typ = node.accept(self) File "mypy/mypy/nodes.py", line 707, in accept return visitor.visit_try_stmt(self) File "mypy/mypy/checker.py", line 1732, in visit_try_stmt self.accept(s.else_body) File "mypy/mypy/checker.py", line 450, in accept typ = node.accept(self) File "mypy/mypy/nodes.py", line 526, in accept return visitor.visit_block(self) File "mypy/mypy/checker.py", line 1113, in visit_block self.accept(s) File "mypy/mypy/checker.py", line 450, in accept typ = node.accept(self) File "mypy/mypy/nodes.py", line 382, in accept return visitor.visit_func_def(self) File "mypy/mypy/checker.py", line 594, in visit_func_def 'redefinition with type') File "mypy/mypy/checker.py", line 2117, in check_subtype if not is_subtype(subtype, supertype): File "mypy/mypy/subtypes.py", line 49, in is_subtype return left.accept(SubtypeVisitor(right, type_parameter_checker)) AttributeError: 'NoneType' object has no attribute 'accept'
AttributeError
def visit_try_stmt(self, s: TryStmt) -> Type: """Type check a try statement.""" # Our enclosing frame will get the result if the try/except falls through. # This one gets all possible states after the try block exited abnormally # (by exception, return, break, etc.) with self.binder.frame_context(can_skip=False, fall_through=0): # Not only might the body of the try statement exit # abnormally, but so might an exception handler or else # clause. The finally clause runs in *all* cases, so we # need an outer try frame to catch all intermediate states # in case an exception is raised during an except or else # clause. As an optimization, only create the outer try # frame when there actually is a finally clause. self.visit_try_without_finally(s, try_frame=bool(s.finally_body)) if s.finally_body: # First we check finally_body is type safe on all abnormal exit paths self.accept(s.finally_body) if s.finally_body: # Then we try again for the more restricted set of options # that can fall through. (Why do we need to check the # finally clause twice? Depending on whether the finally # clause was reached by the try clause falling off the end # or exiting abnormally, after completing the finally clause # either flow will continue to after the entire try statement # or the exception/return/etc. will be processed and control # flow will escape. We need to check that the finally clause # type checks in both contexts, but only the resulting types # from the latter context affect the type state in the code # that follows the try statement.) self.accept(s.finally_body) return None
def visit_try_stmt(self, s: TryStmt) -> Type: """Type check a try statement.""" # Our enclosing frame will get the result if the try/except falls through. # This one gets all possible intermediate states with self.binder.frame_context(): if s.finally_body: self.binder.try_frames.add(len(self.binder.frames) - 1) breaking_out = self.visit_try_without_finally(s) self.binder.try_frames.remove(len(self.binder.frames) - 1) # First we check finally_body is type safe for all intermediate frames self.accept(s.finally_body) breaking_out = breaking_out or self.binder.breaking_out else: breaking_out = self.visit_try_without_finally(s) if not breaking_out and s.finally_body: # Then we try again for the more restricted set of options that can fall through self.accept(s.finally_body) self.binder.breaking_out = breaking_out return None
https://github.com/python/mypy/issues/1289
Traceback (most recent call last): File "./scripts/mypy", line 6, in <module> main(__file__) File "mypy/mypy/main.py", line 50, in main type_check_only(sources, bin_dir, options) File "mypy/mypy/main.py", line 94, in type_check_only python_path=options.python_path) File "mypy/mypy/build.py", line 210, in build result = manager.process(initial_states) File "mypy/mypy/build.py", line 425, in process next.process() File "mypy/mypy/build.py", line 930, in process self.type_checker().visit_file(self.tree, self.tree.path) File "mypy/mypy/checker.py", line 409, in visit_file self.accept(d) File "mypy/mypy/checker.py", line 450, in accept typ = node.accept(self) File "mypy/mypy/nodes.py", line 707, in accept return visitor.visit_try_stmt(self) File "mypy/mypy/checker.py", line 1732, in visit_try_stmt self.accept(s.else_body) File "mypy/mypy/checker.py", line 450, in accept typ = node.accept(self) File "mypy/mypy/nodes.py", line 526, in accept return visitor.visit_block(self) File "mypy/mypy/checker.py", line 1113, in visit_block self.accept(s) File "mypy/mypy/checker.py", line 450, in accept typ = node.accept(self) File "mypy/mypy/nodes.py", line 382, in accept return visitor.visit_func_def(self) File "mypy/mypy/checker.py", line 594, in visit_func_def 'redefinition with type') File "mypy/mypy/checker.py", line 2117, in check_subtype if not is_subtype(subtype, supertype): File "mypy/mypy/subtypes.py", line 49, in is_subtype return left.accept(SubtypeVisitor(right, type_parameter_checker)) AttributeError: 'NoneType' object has no attribute 'accept'
AttributeError
def visit_try_without_finally(self, s: TryStmt, try_frame: bool) -> None: """Type check a try statement, ignoring the finally block. On entry, the top frame should receive all flow that exits the try block abnormally (i.e., such that the else block does not execute), and its parent should receive all flow that exits the try block normally. """ # This frame will run the else block if the try fell through. # In that case, control flow continues to the parent of what # was the top frame on entry. with self.binder.frame_context(can_skip=False, fall_through=2, try_frame=try_frame): # This frame receives exit via exception, and runs exception handlers with self.binder.frame_context(can_skip=False, fall_through=2): # Finally, the body of the try statement with self.binder.frame_context( can_skip=False, fall_through=2, try_frame=True ): self.accept(s.body) for i in range(len(s.handlers)): with self.binder.frame_context(can_skip=True, fall_through=4): if s.types[i]: t = self.visit_except_handler_test(s.types[i]) if s.vars[i]: # To support local variables, we make this a definition line, # causing assignment to set the variable's type. s.vars[i].is_def = True self.check_assignment( s.vars[i], self.temp_node(t, s.vars[i]) ) self.accept(s.handlers[i]) if s.vars[i]: # Exception variables are deleted in python 3 but not python 2. # But, since it's bad form in python 2 and the type checking # wouldn't work very well, we delete it anyway. # Unfortunately, this doesn't let us detect usage before the # try/except block. if self.options.python_version[0] >= 3: source = s.vars[i].name else: source = ( '(exception variable "{}", which we do not ' "accept outside except: blocks even in " "python 2)".format(s.vars[i].name) ) var = cast(Var, s.vars[i].node) var.type = DeletedType(source=source) self.binder.cleanse(s.vars[i]) if s.else_body: self.accept(s.else_body)
def visit_try_without_finally(self, s: TryStmt) -> bool: """Type check a try statement, ignoring the finally block. Return whether we are guaranteed to be breaking out. Otherwise, it will place the results possible frames of that don't break out into self.binder.frames[-2]. """ breaking_out = True # This frame records the possible states that exceptions can leave variables in # during the try: block with self.binder.frame_context(): with self.binder.frame_context(3): self.binder.try_frames.add(len(self.binder.frames) - 2) self.accept(s.body) self.binder.try_frames.remove(len(self.binder.frames) - 2) if s.else_body: self.accept(s.else_body) breaking_out = breaking_out and self.binder.last_pop_breaking_out for i in range(len(s.handlers)): with self.binder.frame_context(3): if s.types[i]: t = self.visit_except_handler_test(s.types[i]) if s.vars[i]: # To support local variables, we make this a definition line, # causing assignment to set the variable's type. s.vars[i].is_def = True self.check_assignment(s.vars[i], self.temp_node(t, s.vars[i])) self.accept(s.handlers[i]) if s.vars[i]: # Exception variables are deleted in python 3 but not python 2. # But, since it's bad form in python 2 and the type checking # wouldn't work very well, we delete it anyway. # Unfortunately, this doesn't let us detect usage before the # try/except block. if self.options.python_version[0] >= 3: source = s.vars[i].name else: source = ( '(exception variable "{}", which we do not accept outside' "except: blocks even in python 2)".format(s.vars[i].name) ) var = cast(Var, s.vars[i].node) var.type = DeletedType(source=source) self.binder.cleanse(s.vars[i]) breaking_out = breaking_out and self.binder.last_pop_breaking_out return breaking_out
https://github.com/python/mypy/issues/1289
Traceback (most recent call last): File "./scripts/mypy", line 6, in <module> main(__file__) File "mypy/mypy/main.py", line 50, in main type_check_only(sources, bin_dir, options) File "mypy/mypy/main.py", line 94, in type_check_only python_path=options.python_path) File "mypy/mypy/build.py", line 210, in build result = manager.process(initial_states) File "mypy/mypy/build.py", line 425, in process next.process() File "mypy/mypy/build.py", line 930, in process self.type_checker().visit_file(self.tree, self.tree.path) File "mypy/mypy/checker.py", line 409, in visit_file self.accept(d) File "mypy/mypy/checker.py", line 450, in accept typ = node.accept(self) File "mypy/mypy/nodes.py", line 707, in accept return visitor.visit_try_stmt(self) File "mypy/mypy/checker.py", line 1732, in visit_try_stmt self.accept(s.else_body) File "mypy/mypy/checker.py", line 450, in accept typ = node.accept(self) File "mypy/mypy/nodes.py", line 526, in accept return visitor.visit_block(self) File "mypy/mypy/checker.py", line 1113, in visit_block self.accept(s) File "mypy/mypy/checker.py", line 450, in accept typ = node.accept(self) File "mypy/mypy/nodes.py", line 382, in accept return visitor.visit_func_def(self) File "mypy/mypy/checker.py", line 594, in visit_func_def 'redefinition with type') File "mypy/mypy/checker.py", line 2117, in check_subtype if not is_subtype(subtype, supertype): File "mypy/mypy/subtypes.py", line 49, in is_subtype return left.accept(SubtypeVisitor(right, type_parameter_checker)) AttributeError: 'NoneType' object has no attribute 'accept'
AttributeError
def visit_break_stmt(self, s: BreakStmt) -> Type: self.binder.handle_break() return None
def visit_break_stmt(self, s: BreakStmt) -> Type: self.binder.breaking_out = True self.binder.allow_jump(self.binder.loop_frames[-1] - 1) return None
https://github.com/python/mypy/issues/1289
Traceback (most recent call last): File "./scripts/mypy", line 6, in <module> main(__file__) File "mypy/mypy/main.py", line 50, in main type_check_only(sources, bin_dir, options) File "mypy/mypy/main.py", line 94, in type_check_only python_path=options.python_path) File "mypy/mypy/build.py", line 210, in build result = manager.process(initial_states) File "mypy/mypy/build.py", line 425, in process next.process() File "mypy/mypy/build.py", line 930, in process self.type_checker().visit_file(self.tree, self.tree.path) File "mypy/mypy/checker.py", line 409, in visit_file self.accept(d) File "mypy/mypy/checker.py", line 450, in accept typ = node.accept(self) File "mypy/mypy/nodes.py", line 707, in accept return visitor.visit_try_stmt(self) File "mypy/mypy/checker.py", line 1732, in visit_try_stmt self.accept(s.else_body) File "mypy/mypy/checker.py", line 450, in accept typ = node.accept(self) File "mypy/mypy/nodes.py", line 526, in accept return visitor.visit_block(self) File "mypy/mypy/checker.py", line 1113, in visit_block self.accept(s) File "mypy/mypy/checker.py", line 450, in accept typ = node.accept(self) File "mypy/mypy/nodes.py", line 382, in accept return visitor.visit_func_def(self) File "mypy/mypy/checker.py", line 594, in visit_func_def 'redefinition with type') File "mypy/mypy/checker.py", line 2117, in check_subtype if not is_subtype(subtype, supertype): File "mypy/mypy/subtypes.py", line 49, in is_subtype return left.accept(SubtypeVisitor(right, type_parameter_checker)) AttributeError: 'NoneType' object has no attribute 'accept'
AttributeError
def visit_continue_stmt(self, s: ContinueStmt) -> Type: self.binder.handle_continue() return None
def visit_continue_stmt(self, s: ContinueStmt) -> Type: self.binder.breaking_out = True self.binder.allow_jump(self.binder.loop_frames[-1]) return None
https://github.com/python/mypy/issues/1289
Traceback (most recent call last): File "./scripts/mypy", line 6, in <module> main(__file__) File "mypy/mypy/main.py", line 50, in main type_check_only(sources, bin_dir, options) File "mypy/mypy/main.py", line 94, in type_check_only python_path=options.python_path) File "mypy/mypy/build.py", line 210, in build result = manager.process(initial_states) File "mypy/mypy/build.py", line 425, in process next.process() File "mypy/mypy/build.py", line 930, in process self.type_checker().visit_file(self.tree, self.tree.path) File "mypy/mypy/checker.py", line 409, in visit_file self.accept(d) File "mypy/mypy/checker.py", line 450, in accept typ = node.accept(self) File "mypy/mypy/nodes.py", line 707, in accept return visitor.visit_try_stmt(self) File "mypy/mypy/checker.py", line 1732, in visit_try_stmt self.accept(s.else_body) File "mypy/mypy/checker.py", line 450, in accept typ = node.accept(self) File "mypy/mypy/nodes.py", line 526, in accept return visitor.visit_block(self) File "mypy/mypy/checker.py", line 1113, in visit_block self.accept(s) File "mypy/mypy/checker.py", line 450, in accept typ = node.accept(self) File "mypy/mypy/nodes.py", line 382, in accept return visitor.visit_func_def(self) File "mypy/mypy/checker.py", line 594, in visit_func_def 'redefinition with type') File "mypy/mypy/checker.py", line 2117, in check_subtype if not is_subtype(subtype, supertype): File "mypy/mypy/subtypes.py", line 49, in is_subtype return left.accept(SubtypeVisitor(right, type_parameter_checker)) AttributeError: 'NoneType' object has no attribute 'accept'
AttributeError
def find_isinstance_check( self, n: Expression ) -> Tuple[Optional[Dict[Expression, Type]], Optional[Dict[Expression, Type]]]: return find_isinstance_check(n, self.type_map)
def find_isinstance_check( node: Expression, type_map: Dict[Expression, Type], ) -> Tuple[TypeMap, TypeMap]: """Find any isinstance checks (within a chain of ands). Includes implicit and explicit checks for None. Return value is a map of variables to their types if the condition is true and a map of variables to their types if the condition is false. If either of the values in the tuple is None, then that particular branch can never occur. Guaranteed to not return None, None. (But may return {}, {}) """ if isinstance(node, CallExpr): if refers_to_fullname(node.callee, "builtins.isinstance"): expr = node.args[0] if expr.literal == LITERAL_TYPE: vartype = type_map[expr] type = get_isinstance_type(node.args[1], type_map) return conditional_type_map(expr, vartype, type) elif ( isinstance(node, ComparisonExpr) and any(is_literal_none(n) for n in node.operands) and experiments.STRICT_OPTIONAL ): # Check for `x is None` and `x is not None`. is_not = node.operators == ["is not"] if is_not or node.operators == ["is"]: if_vars = {} # type: Dict[Expression, Type] else_vars = {} # type: Dict[Expression, Type] for expr in node.operands: if ( expr.literal == LITERAL_TYPE and not is_literal_none(expr) and expr in type_map ): # This should only be true at most once: there should be # two elements in node.operands, and at least one of them # should represent a None. vartype = type_map[expr] if_vars, else_vars = conditional_type_map(expr, vartype, NoneTyp()) break if is_not: if_vars, else_vars = else_vars, if_vars return if_vars, else_vars elif isinstance(node, RefExpr): # Restrict the type of the variable to True-ish/False-ish in the if and else branches # respectively vartype = type_map[node] if_type = true_only(vartype) else_type = false_only(vartype) ref = node # type: Expression if_map = {ref: if_type} if not isinstance(if_type, UninhabitedType) else None else_map = ( {ref: else_type} if not isinstance(else_type, UninhabitedType) else None ) return if_map, else_map elif isinstance(node, OpExpr) and node.op == "and": left_if_vars, left_else_vars = find_isinstance_check(node.left, type_map) right_if_vars, right_else_vars = find_isinstance_check(node.right, type_map) # (e1 and e2) is true if both e1 and e2 are true, # and false if at least one of e1 and e2 is false. return ( and_conditional_maps(left_if_vars, right_if_vars), or_conditional_maps(left_else_vars, right_else_vars), ) elif isinstance(node, OpExpr) and node.op == "or": left_if_vars, left_else_vars = find_isinstance_check(node.left, type_map) right_if_vars, right_else_vars = find_isinstance_check(node.right, type_map) # (e1 or e2) is true if at least one of e1 or e2 is true, # and false if both e1 and e2 are false. return ( or_conditional_maps(left_if_vars, right_if_vars), and_conditional_maps(left_else_vars, right_else_vars), ) elif isinstance(node, UnaryExpr) and node.op == "not": left, right = find_isinstance_check(node.expr, type_map) return right, left # Not a supported isinstance check return {}, {}
https://github.com/python/mypy/issues/1289
Traceback (most recent call last): File "./scripts/mypy", line 6, in <module> main(__file__) File "mypy/mypy/main.py", line 50, in main type_check_only(sources, bin_dir, options) File "mypy/mypy/main.py", line 94, in type_check_only python_path=options.python_path) File "mypy/mypy/build.py", line 210, in build result = manager.process(initial_states) File "mypy/mypy/build.py", line 425, in process next.process() File "mypy/mypy/build.py", line 930, in process self.type_checker().visit_file(self.tree, self.tree.path) File "mypy/mypy/checker.py", line 409, in visit_file self.accept(d) File "mypy/mypy/checker.py", line 450, in accept typ = node.accept(self) File "mypy/mypy/nodes.py", line 707, in accept return visitor.visit_try_stmt(self) File "mypy/mypy/checker.py", line 1732, in visit_try_stmt self.accept(s.else_body) File "mypy/mypy/checker.py", line 450, in accept typ = node.accept(self) File "mypy/mypy/nodes.py", line 526, in accept return visitor.visit_block(self) File "mypy/mypy/checker.py", line 1113, in visit_block self.accept(s) File "mypy/mypy/checker.py", line 450, in accept typ = node.accept(self) File "mypy/mypy/nodes.py", line 382, in accept return visitor.visit_func_def(self) File "mypy/mypy/checker.py", line 594, in visit_func_def 'redefinition with type') File "mypy/mypy/checker.py", line 2117, in check_subtype if not is_subtype(subtype, supertype): File "mypy/mypy/subtypes.py", line 49, in is_subtype return left.accept(SubtypeVisitor(right, type_parameter_checker)) AttributeError: 'NoneType' object has no attribute 'accept'
AttributeError
def check_boolean_op(self, e: OpExpr, context: Context) -> Type: """Type check a boolean operation ('and' or 'or').""" # A boolean operation can evaluate to either of the operands. # We use the current type context to guide the type inference of of # the left operand. We also use the left operand type to guide the type # inference of the right operand so that expressions such as # '[1] or []' are inferred correctly. ctx = self.chk.type_context[-1] left_type = self.accept(e.left, ctx) assert e.op in ("and", "or") # Checked by visit_op_expr if e.op == "and": right_map, left_map = self.chk.find_isinstance_check(e.left) restricted_left_type = false_only(left_type) result_is_left = not left_type.can_be_true elif e.op == "or": left_map, right_map = self.chk.find_isinstance_check(e.left) restricted_left_type = true_only(left_type) result_is_left = not left_type.can_be_false right_type = self.analyze_cond_branch(right_map, e.right, left_type) self.check_usable_type(left_type, context) self.check_usable_type(right_type, context) if right_map is None: # The boolean expression is statically known to be the left value assert left_map is not None # find_isinstance_check guarantees this return left_type if left_map is None: # The boolean expression is statically known to be the right value assert right_map is not None # find_isinstance_check guarantees this return right_type if isinstance(restricted_left_type, UninhabitedType): # The left operand can never be the result return right_type elif result_is_left: # The left operand is always the result return left_type else: return UnionType.make_simplified_union([restricted_left_type, right_type])
def check_boolean_op(self, e: OpExpr, context: Context) -> Type: """Type check a boolean operation ('and' or 'or').""" # A boolean operation can evaluate to either of the operands. # We use the current type context to guide the type inference of of # the left operand. We also use the left operand type to guide the type # inference of the right operand so that expressions such as # '[1] or []' are inferred correctly. ctx = self.chk.type_context[-1] left_type = self.accept(e.left, ctx) assert e.op in ("and", "or") # Checked by visit_op_expr if e.op == "and": right_map, left_map = mypy.checker.find_isinstance_check( e.left, self.chk.type_map ) restricted_left_type = false_only(left_type) result_is_left = not left_type.can_be_true elif e.op == "or": left_map, right_map = mypy.checker.find_isinstance_check( e.left, self.chk.type_map ) restricted_left_type = true_only(left_type) result_is_left = not left_type.can_be_false with self.chk.binder.frame_context(): if right_map: for var, type in right_map.items(): self.chk.binder.push(var, type) right_type = self.accept(e.right, left_type) self.check_usable_type(left_type, context) self.check_usable_type(right_type, context) if right_map is None: # The boolean expression is statically known to be the left value assert left_map is not None # find_isinstance_check guarantees this return left_type if left_map is None: # The boolean expression is statically known to be the right value assert right_map is not None # find_isinstance_check guarantees this return right_type if isinstance(restricted_left_type, UninhabitedType): # The left operand can never be the result return right_type elif result_is_left: # The left operand is always the result return left_type else: return UnionType.make_simplified_union([restricted_left_type, right_type])
https://github.com/python/mypy/issues/1289
Traceback (most recent call last): File "./scripts/mypy", line 6, in <module> main(__file__) File "mypy/mypy/main.py", line 50, in main type_check_only(sources, bin_dir, options) File "mypy/mypy/main.py", line 94, in type_check_only python_path=options.python_path) File "mypy/mypy/build.py", line 210, in build result = manager.process(initial_states) File "mypy/mypy/build.py", line 425, in process next.process() File "mypy/mypy/build.py", line 930, in process self.type_checker().visit_file(self.tree, self.tree.path) File "mypy/mypy/checker.py", line 409, in visit_file self.accept(d) File "mypy/mypy/checker.py", line 450, in accept typ = node.accept(self) File "mypy/mypy/nodes.py", line 707, in accept return visitor.visit_try_stmt(self) File "mypy/mypy/checker.py", line 1732, in visit_try_stmt self.accept(s.else_body) File "mypy/mypy/checker.py", line 450, in accept typ = node.accept(self) File "mypy/mypy/nodes.py", line 526, in accept return visitor.visit_block(self) File "mypy/mypy/checker.py", line 1113, in visit_block self.accept(s) File "mypy/mypy/checker.py", line 450, in accept typ = node.accept(self) File "mypy/mypy/nodes.py", line 382, in accept return visitor.visit_func_def(self) File "mypy/mypy/checker.py", line 594, in visit_func_def 'redefinition with type') File "mypy/mypy/checker.py", line 2117, in check_subtype if not is_subtype(subtype, supertype): File "mypy/mypy/subtypes.py", line 49, in is_subtype return left.accept(SubtypeVisitor(right, type_parameter_checker)) AttributeError: 'NoneType' object has no attribute 'accept'
AttributeError
def check_generator_or_comprehension( self, gen: GeneratorExpr, type_name: str, id_for_messages: str ) -> Type: """Type check a generator expression or a list comprehension.""" with self.chk.binder.frame_context(can_skip=True, fall_through=0): self.check_for_comp(gen) # Infer the type of the list comprehension by using a synthetic generic # callable type. tvdef = TypeVarDef("T", -1, [], self.chk.object_type()) tv = TypeVarType(tvdef) constructor = CallableType( [tv], [nodes.ARG_POS], [None], self.chk.named_generic_type(type_name, [tv]), self.chk.named_type("builtins.function"), name=id_for_messages, variables=[tvdef], ) return self.check_call(constructor, [gen.left_expr], [nodes.ARG_POS], gen)[0]
def check_generator_or_comprehension( self, gen: GeneratorExpr, type_name: str, id_for_messages: str ) -> Type: """Type check a generator expression or a list comprehension.""" with self.chk.binder.frame_context(): self.check_for_comp(gen) # Infer the type of the list comprehension by using a synthetic generic # callable type. tvdef = TypeVarDef("T", -1, [], self.chk.object_type()) tv = TypeVarType(tvdef) constructor = CallableType( [tv], [nodes.ARG_POS], [None], self.chk.named_generic_type(type_name, [tv]), self.chk.named_type("builtins.function"), name=id_for_messages, variables=[tvdef], ) return self.check_call(constructor, [gen.left_expr], [nodes.ARG_POS], gen)[0]
https://github.com/python/mypy/issues/1289
Traceback (most recent call last): File "./scripts/mypy", line 6, in <module> main(__file__) File "mypy/mypy/main.py", line 50, in main type_check_only(sources, bin_dir, options) File "mypy/mypy/main.py", line 94, in type_check_only python_path=options.python_path) File "mypy/mypy/build.py", line 210, in build result = manager.process(initial_states) File "mypy/mypy/build.py", line 425, in process next.process() File "mypy/mypy/build.py", line 930, in process self.type_checker().visit_file(self.tree, self.tree.path) File "mypy/mypy/checker.py", line 409, in visit_file self.accept(d) File "mypy/mypy/checker.py", line 450, in accept typ = node.accept(self) File "mypy/mypy/nodes.py", line 707, in accept return visitor.visit_try_stmt(self) File "mypy/mypy/checker.py", line 1732, in visit_try_stmt self.accept(s.else_body) File "mypy/mypy/checker.py", line 450, in accept typ = node.accept(self) File "mypy/mypy/nodes.py", line 526, in accept return visitor.visit_block(self) File "mypy/mypy/checker.py", line 1113, in visit_block self.accept(s) File "mypy/mypy/checker.py", line 450, in accept typ = node.accept(self) File "mypy/mypy/nodes.py", line 382, in accept return visitor.visit_func_def(self) File "mypy/mypy/checker.py", line 594, in visit_func_def 'redefinition with type') File "mypy/mypy/checker.py", line 2117, in check_subtype if not is_subtype(subtype, supertype): File "mypy/mypy/subtypes.py", line 49, in is_subtype return left.accept(SubtypeVisitor(right, type_parameter_checker)) AttributeError: 'NoneType' object has no attribute 'accept'
AttributeError