From: Kefu Chai Date: Wed, 11 Mar 2020 08:08:51 +0000 (+0800) Subject: cephadm: add "assert foo is not None" for mypy check X-Git-Tag: v15.1.1~40^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=refs%2Fpull%2F33876%2Fhead;p=ceph.git cephadm: add "assert foo is not None" for mypy check it's legit to pass file objects to fcntl(), but `Popen.stdout` and `Popen.stderr` properies are not necessarily file objects -- they could be None. this cannot be deduced at compile-time. even we can ensure this, as we do pass `subprocess.PIPE` to the constructor. so mypy just complains at seeing this: ``` cephadm:429: error: Argument 1 to "fcntl" has incompatible type "Optional[IO[Any]]"; expected "Union[int, HasFileno]" cephadm:430: error: Argument 1 to "fcntl" has incompatible type "Optional[IO[Any]]"; expected "Union[int, HasFileno]" cephadm:431: error: Argument 1 to "fcntl" has incompatible type "Optional[IO[Any]]"; expected "Union[int, HasFileno]" cephadm:432: error: Argument 1 to "fcntl" has incompatible type "Optional[IO[Any]]"; expected "Union[int, HasFileno]" cephadm:455: error: Item "None" of "Optional[IO[Any]]" has no attribute "fileno" cephadm:465: error: Item "None" of "Optional[IO[Any]]" has no attribute "fileno" cephadm:475: error: Item "None" of "Optional[IO[Any]]" has no attribute "fileno" ``` to silence this warning, insert `assert process.stdout is not None` before accessing `process.stdout` to appease the strict optional checking of mypy. this is a follow-up fix of ee3fe37158422902162257c123ea234da999c961 Fixes: https://tracker.ceph.com/issues/44557 Signed-off-by: Kefu Chai --- diff --git a/src/cephadm/cephadm b/src/cephadm/cephadm index 0bb96ef30413..2c45e4dba22f 100755 --- a/src/cephadm/cephadm +++ b/src/cephadm/cephadm @@ -426,6 +426,8 @@ def call(command, # type: List[str] **kwargs ) # get current p.stdout flags, add O_NONBLOCK + assert process.stdout is not None + assert process.stderr is not None stdout_flags = fcntl.fcntl(process.stdout, fcntl.F_GETFL) stderr_flags = fcntl.fcntl(process.stderr, fcntl.F_GETFL) fcntl.fcntl(process.stdout, fcntl.F_SETFL, stdout_flags | os.O_NONBLOCK)