]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commit
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)
commit32b3340ee460a5104d7f1d45a4cbaa6e0d3f6112
treeb679076f02cc95886ae741ac148ff832a1fe5c71
parent691b44810e83bb3bceced1ded512857d1f579125
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 <kchai@redhat.com>
src/cephadm/cephadm