Skip to content

Commit

Permalink
Merge branch 'trunk' into 10002-mypy-internet
Browse files Browse the repository at this point in the history
# Conflicts:
#	mypy.ini
  • Loading branch information
wsanchez committed Oct 9, 2020
2 parents a9d7319 + 26f7b3b commit 43fd9e7
Show file tree
Hide file tree
Showing 54 changed files with 1,697 additions and 1,728 deletions.
42 changes: 22 additions & 20 deletions mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,31 @@ warn_unused_ignores = True
allow_untyped_defs = True
check_untyped_defs = False

[mypy-twisted.application.*]
[mypy-twisted.application.app]
allow_untyped_defs = True
check_untyped_defs = False

[mypy-twisted.application.runner.test.test_runner]
allow_incomplete_defs = True
[mypy-twisted.application.internet]
allow_untyped_defs = True
check_untyped_defs = False

[mypy-twisted.application.reactors]
allow_untyped_defs = True

[mypy-twisted.application.service]
allow_untyped_defs = True
check_untyped_defs = False

[mypy-twisted.application.strports]
allow_untyped_defs = True
check_untyped_defs = False

[mypy-twisted.application.test.test_internet]
allow_untyped_defs = True
check_untyped_defs = False

[mypy-twisted.application.test.test_service]
allow_untyped_defs = True

[mypy-twisted.conch.*]
allow_untyped_defs = True
Expand Down Expand Up @@ -810,20 +829,3 @@ warn_return_any = False

[mypy-twisted.words.xish.domish]
warn_return_any = False

# Disable warn_unreachable for some modules until we clean them up

[mypy-twisted.conch.scripts.conch]
warn_unreachable = False

[mypy-twisted.conch.telnet]
warn_unreachable = False

[mypy-twisted.conch.test.test_agent]
warn_unreachable = False

[mypy-twisted.conch.test.test_connection]
warn_unreachable = False

[mypy-twisted.conch.test.test_ssh]
warn_unreachable = False
115 changes: 39 additions & 76 deletions src/twisted/application/runner/_exit.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,35 +6,10 @@
System exit support.
"""

from enum import IntEnum
from sys import stdout, stderr, exit as sysexit

from constantly import Values, ValueConstant


def exit(status, message=None):
"""
Exit the python interpreter with the given status and an optional message.
@param status: An exit status.
@type status: L{int} or L{ValueConstant} from L{ExitStatus}.
@param message: An options message to print.
@type status: L{str}
"""
if isinstance(status, ValueConstant):
code = status.value
else:
code = int(status)

if message:
if code == 0:
out = stdout
else:
out = stderr
out.write(message)
out.write("\n")

sysexit(code)
import typing
from typing import Union


try:
Expand Down Expand Up @@ -66,72 +41,60 @@ class Status: # type: ignore[no-redef]
EX_CONFIG = EX__BASE + 14


class ExitStatus(Values):
class ExitStatus(IntEnum):
"""
Standard exit status codes for system programs.
@cvar EX_OK: Successful termination.
@type EX_OK: L{ValueConstant}
@cvar EX_USAGE: Command line usage error.
@type EX_USAGE: L{ValueConstant}
@cvar EX_DATAERR: Data format error.
@type EX_DATAERR: L{ValueConstant}
@cvar EX_NOINPUT: Cannot open input.
@type EX_NOINPUT: L{ValueConstant}
@cvar EX_NOUSER: Addressee unknown.
@type EX_NOUSER: L{ValueConstant}
@cvar EX_NOHOST: Host name unknown.
@type EX_NOHOST: L{ValueConstant}
@cvar EX_UNAVAILABLE: Service unavailable.
@type EX_UNAVAILABLE: L{ValueConstant}
@cvar EX_SOFTWARE: Internal software error.
@type EX_SOFTWARE: L{ValueConstant}
@cvar EX_OSERR: System error (e.g., can't fork).
@type EX_OSERR: L{ValueConstant}
@cvar EX_OSFILE: Critical OS file missing.
@type EX_OSFILE: L{ValueConstant}
@cvar EX_CANTCREAT: Can't create (user) output file.
@type EX_CANTCREAT: L{ValueConstant}
@cvar EX_IOERR: Input/output error.
@type EX_IOERR: L{ValueConstant}
@cvar EX_TEMPFAIL: Temporary failure; the user is invited to retry.
@type EX_TEMPFAIL: L{ValueConstant}
@cvar EX_PROTOCOL: Remote error in protocol.
@type EX_PROTOCOL: L{ValueConstant}
@cvar EX_NOPERM: Permission denied.
@type EX_NOPERM: L{ValueConstant}
@cvar EX_CONFIG: Configuration error.
@type EX_CONFIG: L{ValueConstant}
"""

EX_OK = ValueConstant(Status.EX_OK)
EX_USAGE = ValueConstant(Status.EX_USAGE)
EX_DATAERR = ValueConstant(Status.EX_DATAERR)
EX_NOINPUT = ValueConstant(Status.EX_NOINPUT)
EX_NOUSER = ValueConstant(Status.EX_NOUSER)
EX_NOHOST = ValueConstant(Status.EX_NOHOST)
EX_UNAVAILABLE = ValueConstant(Status.EX_UNAVAILABLE)
EX_SOFTWARE = ValueConstant(Status.EX_SOFTWARE)
EX_OSERR = ValueConstant(Status.EX_OSERR)
EX_OSFILE = ValueConstant(Status.EX_OSFILE)
EX_CANTCREAT = ValueConstant(Status.EX_CANTCREAT)
EX_IOERR = ValueConstant(Status.EX_IOERR)
EX_TEMPFAIL = ValueConstant(Status.EX_TEMPFAIL)
EX_PROTOCOL = ValueConstant(Status.EX_PROTOCOL)
EX_NOPERM = ValueConstant(Status.EX_NOPERM)
EX_CONFIG = ValueConstant(Status.EX_CONFIG)
EX_OK = Status.EX_OK
EX_USAGE = Status.EX_USAGE
EX_DATAERR = Status.EX_DATAERR
EX_NOINPUT = Status.EX_NOINPUT
EX_NOUSER = Status.EX_NOUSER
EX_NOHOST = Status.EX_NOHOST
EX_UNAVAILABLE = Status.EX_UNAVAILABLE
EX_SOFTWARE = Status.EX_SOFTWARE
EX_OSERR = Status.EX_OSERR
EX_OSFILE = Status.EX_OSFILE
EX_CANTCREAT = Status.EX_CANTCREAT
EX_IOERR = Status.EX_IOERR
EX_TEMPFAIL = Status.EX_TEMPFAIL
EX_PROTOCOL = Status.EX_PROTOCOL
EX_NOPERM = Status.EX_NOPERM
EX_CONFIG = Status.EX_CONFIG


def exit(status: Union[int, ExitStatus], message: str = "") -> "typing.NoReturn":
"""
Exit the python interpreter with the given status and an optional message.
@param status: An exit status. An appropriate value from L{ExitStatus} is
recommended.
@param message: An optional message to print.
"""
if message:
if status == ExitStatus.EX_OK:
out = stdout
else:
out = stderr
out.write(message)
out.write("\n")

sysexit(status)
Loading

0 comments on commit 43fd9e7

Please sign in to comment.