]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
cephadm: add "assert foo is not None" for mypy check 33876/head
authorKefu Chai <kchai@redhat.com>
Wed, 11 Mar 2020 08:08:51 +0000 (16:08 +0800)
committerKefu Chai <kchai@redhat.com>
Wed, 11 Mar 2020 10:50:56 +0000 (18:50 +0800)
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 <kchai@redhat.com>
src/cephadm/cephadm

index 0bb96ef304132b63d6ba40f033b453d4067aa489..2c45e4dba22f542bee7aa2b5e0b1ce08a3ab7606 100755 (executable)
@@ -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)