Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix missing NoReturn annotations and incorrect try placements #12705

Merged
merged 5 commits into from
May 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions mypy/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

from typing import (AbstractSet, Any, Dict, Iterable, Iterator, List, Sequence,
Mapping, NamedTuple, Optional, Set, Tuple, TypeVar, Union, Callable, TextIO)
from typing_extensions import ClassVar, Final, TYPE_CHECKING, TypeAlias as _TypeAlias
from typing_extensions import ClassVar, NoReturn, Final, TYPE_CHECKING, TypeAlias as _TypeAlias
from mypy_extensions import TypedDict

from mypy.nodes import MypyFile, ImportBase, Import, ImportFrom, ImportAll, SymbolTable
Expand Down Expand Up @@ -398,7 +398,7 @@ def load_plugins_from_config(
if line == -1:
line = 1 # We need to pick some line number that doesn't look too confusing

def plugin_error(message: str) -> None:
def plugin_error(message: str) -> NoReturn:
errors.report(line, 0, message)
errors.raise_error(use_stdout=False)

Expand Down
3 changes: 2 additions & 1 deletion mypy/dmypy/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import traceback

from typing import Any, Callable, Dict, Mapping, Optional, Tuple, List
from typing_extensions import NoReturn

from mypy.dmypy_util import DEFAULT_STATUS_FILE, receive
from mypy.ipc import IPCClient, IPCException
Expand Down Expand Up @@ -161,7 +162,7 @@ def main(argv: List[str]) -> None:
sys.exit(2)


def fail(msg: str) -> None:
def fail(msg: str) -> NoReturn:
print(msg, file=sys.stderr)
sys.exit(2)

Expand Down
6 changes: 3 additions & 3 deletions mypy/dmypy_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,8 @@ def _response_metadata(self) -> Dict[str, str]:
def serve(self) -> None:
"""Serve requests, synchronously (no thread or fork)."""
command = None
server = IPCServer(CONNECTION_NAME, self.timeout)
try:
server = IPCServer(CONNECTION_NAME, self.timeout)
with open(self.status_file, 'w') as f:
json.dump({'pid': os.getpid(), 'connection_name': server.connection_name}, f)
f.write('\n') # I like my JSON with a trailing newline
Expand Down Expand Up @@ -298,11 +298,11 @@ def cmd_stop(self) -> Dict[str, object]:
def cmd_run(self, version: str, args: Sequence[str],
is_tty: bool, terminal_width: int) -> Dict[str, object]:
"""Check a list of files, triggering a restart if needed."""
stderr = io.StringIO()
stdout = io.StringIO()
try:
# Process options can exit on improper arguments, so we need to catch that and
# capture stderr so the client can report it
stderr = io.StringIO()
stdout = io.StringIO()
with redirect_stderr(stderr):
with redirect_stdout(stdout):
sources, options = mypy.main.process_options(
Expand Down
7 changes: 4 additions & 3 deletions mypy/errors.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import os.path
import sys
import traceback

from mypy.backports import OrderedDict
from collections import defaultdict

from typing import Tuple, List, TypeVar, Set, Dict, Optional, TextIO, Callable, Union
from typing_extensions import Final, Literal
from typing_extensions import Final, Literal, NoReturn

from mypy.scope import Scope
from mypy.options import Options
Expand Down Expand Up @@ -633,7 +634,7 @@ def is_errors_for_file(self, file: str) -> bool:
"""Are there any errors for the given file?"""
return file in self.error_info_map

def raise_error(self, use_stdout: bool = True) -> None:
def raise_error(self, use_stdout: bool = True) -> NoReturn:
"""Raise a CompileError with the generated messages.

Render the messages suitable for displaying.
Expand Down Expand Up @@ -908,7 +909,7 @@ def report_internal_error(err: Exception,
options: Options,
stdout: Optional[TextIO] = None,
stderr: Optional[TextIO] = None,
) -> None:
) -> NoReturn:
"""Report internal error and exit.

This optionally starts pdb or shows a traceback.
Expand Down
2 changes: 1 addition & 1 deletion mypy/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -1138,7 +1138,7 @@ def maybe_write_junit_xml(td: float, serious: bool, messages: List[str], options
td, serious, messages, options.junit_xml, py_version, options.platform)


def fail(msg: str, stderr: TextIO, options: Options) -> None:
def fail(msg: str, stderr: TextIO, options: Options) -> NoReturn:
"""Fail with a serious error."""
stderr.write('%s\n' % msg)
maybe_write_junit_xml(0.0, serious=True, messages=[msg], options=options)
Expand Down
2 changes: 2 additions & 0 deletions mypy/semanal.py
Original file line number Diff line number Diff line change
Expand Up @@ -4573,6 +4573,8 @@ def lookup_qualified(self, name: str, ctx: Context,
assert isinstance(node.target, ProperType)
if isinstance(node.target, Instance):
nextsym = node.target.type.get(part)
else:
nextsym = None
else:
if isinstance(node, Var):
typ = get_proper_type(node.type)
Expand Down