From 32b3340ee460a5104d7f1d45a4cbaa6e0d3f6112 Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Wed, 11 Mar 2020 16:08:51 +0800 Subject: [PATCH] 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 --- src/cephadm/cephadm | 2 ++ 1 file changed, 2 insertions(+) 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) -- 2.47.3