diff --git a/mypy/checker.py b/mypy/checker.py index 71cf906a7d27..db5f0fb126dc 100644 --- a/mypy/checker.py +++ b/mypy/checker.py @@ -78,6 +78,7 @@ from mypy import state, errorcodes as codes from mypy.traverser import has_return_statement, all_return_statements from mypy.errorcodes import ErrorCode +from mypy.util import is_typeshed_file T = TypeVar('T') @@ -233,7 +234,7 @@ def __init__(self, errors: Errors, modules: Dict[str, MypyFile], options: Option self.pass_num = 0 self.current_node_deferred = False self.is_stub = tree.is_stub - self.is_typeshed_stub = errors.is_typeshed_file(path) + self.is_typeshed_stub = is_typeshed_file(path) self.inferred_attribute_types = None if options.strict_optional_whitelist is None: self.suppress_none_errors = not options.show_none_errors diff --git a/mypy/errors.py b/mypy/errors.py index 89d9baec93f2..06651b764d62 100644 --- a/mypy/errors.py +++ b/mypy/errors.py @@ -11,7 +11,7 @@ from mypy.version import __version__ as mypy_version from mypy.errorcodes import ErrorCode from mypy import errorcodes as codes -from mypy.util import DEFAULT_SOURCE_OFFSET +from mypy.util import DEFAULT_SOURCE_OFFSET, is_typeshed_file T = TypeVar('T') allowed_duplicates = ['@overload', 'Got:', 'Expected:'] # type: Final @@ -372,7 +372,7 @@ def clear_errors_in_targets(self, path: str, targets: Set[str]) -> None: def generate_unused_ignore_errors(self, file: str) -> None: ignored_lines = self.ignored_lines[file] - if not self.is_typeshed_file(file) and file not in self.ignored_files: + if not is_typeshed_file(file) and file not in self.ignored_files: for line in set(ignored_lines) - self.used_ignored_lines[file]: # Don't use report since add_error_info will ignore the error! info = ErrorInfo(self.import_context(), file, self.current_module(), None, @@ -380,10 +380,6 @@ def generate_unused_ignore_errors(self, file: str) -> None: None, False, False) self._add_error_info(file, info) - def is_typeshed_file(self, file: str) -> bool: - # gross, but no other clear way to tell - return 'typeshed' in os.path.normpath(file).split(os.sep) - def num_messages(self) -> int: """Return the number of generated messages.""" return sum(len(x) for x in self.error_info_map.values()) diff --git a/mypy/semanal.py b/mypy/semanal.py index 72ea96173be8..be455a737202 100644 --- a/mypy/semanal.py +++ b/mypy/semanal.py @@ -103,7 +103,7 @@ Plugin, ClassDefContext, SemanticAnalyzerPluginInterface, DynamicClassDefContext ) -from mypy.util import correct_relative_import, unmangle, module_prefix +from mypy.util import correct_relative_import, unmangle, module_prefix, is_typeshed_file from mypy.scope import Scope from mypy.semanal_shared import ( SemanticAnalyzerInterface, set_callable_name, calculate_tuple_fallback, PRIORITY_FALLBACKS @@ -481,7 +481,7 @@ def file_context(self, self.cur_mod_id = file_node.fullname scope.enter_file(self.cur_mod_id) self.is_stub_file = file_node.path.lower().endswith('.pyi') - self._is_typeshed_stub_file = self.errors.is_typeshed_file(file_node.path) + self._is_typeshed_stub_file = is_typeshed_file(file_node.path) self.globals = file_node.names self.tvar_scope = TypeVarScope() diff --git a/mypy/semanal_main.py b/mypy/semanal_main.py index cac2a83214b8..c3f4dd809127 100644 --- a/mypy/semanal_main.py +++ b/mypy/semanal_main.py @@ -44,6 +44,7 @@ from mypy.semanal_infer import infer_decorator_signature_if_simple from mypy.checker import FineGrainedDeferredNode from mypy.server.aststrip import SavedAttributes +from mypy.util import is_typeshed_file import mypy.build if TYPE_CHECKING: @@ -353,7 +354,7 @@ def check_type_arguments(graph: 'Graph', scc: List[str], errors: Errors) -> None assert state.tree analyzer = TypeArgumentAnalyzer(errors, state.options, - errors.is_typeshed_file(state.path or '')) + is_typeshed_file(state.path or '')) with state.wrap_context(): with strict_optional_set(state.options.strict_optional): state.tree.accept(analyzer) @@ -368,7 +369,7 @@ def check_type_arguments_in_targets(targets: List[FineGrainedDeferredNode], stat """ analyzer = TypeArgumentAnalyzer(errors, state.options, - errors.is_typeshed_file(state.path or '')) + is_typeshed_file(state.path or '')) with state.wrap_context(): with strict_optional_set(state.options.strict_optional): for target in targets: diff --git a/mypy/util.py b/mypy/util.py index fe36297d297a..f8d9368804ba 100644 --- a/mypy/util.py +++ b/mypy/util.py @@ -1,4 +1,5 @@ """Utility functions with no non-trivial dependencies.""" + import os import pathlib import re @@ -700,3 +701,8 @@ def format_error(self, n_errors: int, n_files: int, n_sources: int, if not use_color: return msg return self.style(msg, 'red', bold=True) + + +def is_typeshed_file(file: str) -> bool: + # gross, but no other clear way to tell + return 'typeshed' in os.path.normpath(file).split(os.sep)
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: