Skip to content

Commit 73e2b06

Browse files
authored
Merge pull request ceph#59888 from phlogistonjohn/jjm-mypy-more
prepare mypy checking for newer python (3.12) Reviewed-by: Adam King <[email protected]>
2 parents 4a5715f + de90c32 commit 73e2b06

File tree

6 files changed

+21
-7
lines changed

6 files changed

+21
-7
lines changed

src/mypy-constrains.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# Unfortunately this means we have to manually update those
33
# packages regularly.
44

5-
mypy==1.1.1
5+
mypy==1.9
66

77
# global
88
types-python-dateutil==0.1.3

src/pybind/mgr/dashboard/tools.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
import time
1010
import urllib
1111
from datetime import datetime, timedelta
12-
from distutils.util import strtobool
1312

1413
import cherrypy
14+
from ceph.utils import strtobool
1515
from mgr_util import build_url
1616

1717
from . import mgr

src/pybind/mgr/smb/enums.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class CephFSStorageProvider(_StrEnum):
2121

2222
def expand(self) -> 'CephFSStorageProvider':
2323
"""Expand abbreviated/default values into the full/expanded form."""
24-
if self == self.SAMBA_VFS:
24+
if self is self.SAMBA_VFS:
2525
# mypy gets confused by enums
2626
return self.__class__(self.SAMBA_VFS_NEW)
2727
return self
@@ -89,9 +89,9 @@ class LoginAccess(_StrEnum):
8989
def expand(self) -> 'LoginAccess':
9090
"""Exapend abbreviated enum values into their full forms."""
9191
# the extra LoginAccess(...) calls are to appease mypy
92-
if self == self.READ_ONLY_SHORT:
92+
if self is self.READ_ONLY_SHORT:
9393
return LoginAccess(self.READ_ONLY)
94-
if self == self.READ_WRITE_SHORT:
94+
if self is self.READ_WRITE_SHORT:
9595
return LoginAccess(self.READ_WRITE)
9696
return self
9797

src/pybind/mgr/telemetry/tox.ini

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
[tox]
22
envlist =
33
py3
4-
mypy
54
skipsdist = true
65

76
[testenv]

src/pybind/mgr/volumes/fs/operations/pin_util.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import cephfs
44

55
from ..exception import VolumeException
6-
from distutils.util import strtobool
6+
from ceph.utils import strtobool
77

88
_pin_value = {
99
"export": lambda x: int(x),

src/python-common/ceph/utils.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,3 +167,18 @@ def http_req(hostname: str = '',
167167
log.error(e)
168168
# handle error here if needed
169169
raise
170+
171+
172+
_TRUE_VALS = {'y', 'yes', 't', 'true', 'on', '1'}
173+
_FALSE_VALS = {'n', 'no', 'f', 'false', 'off', '0'}
174+
175+
176+
def strtobool(value: str) -> bool:
177+
"""Convert a string to a boolean value.
178+
Based on a simlilar function once available at distutils.util.strtobool.
179+
"""
180+
if value.lower() in _TRUE_VALS:
181+
return True
182+
if value.lower() in _FALSE_VALS:
183+
return False
184+
raise ValueError(f'invalid truth value {value!r}')

0 commit comments

Comments
 (0)