Skip to content

Commit e6ae7d8

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "typing: Remove use of optional imports"
2 parents 93da5f7 + 9435ef8 commit e6ae7d8

File tree

2 files changed

+12
-20
lines changed

2 files changed

+12
-20
lines changed

openstackclient/image/v1/image.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,6 @@
3030

3131
from openstackclient.i18n import _
3232

33-
if os.name == "nt":
34-
import msvcrt
35-
else:
36-
msvcrt = None
37-
38-
3933
CONTAINER_CHOICES = ["ami", "ari", "aki", "bare", "docker", "ova", "ovf"]
4034
DEFAULT_CONTAINER_FORMAT = 'bare'
4135
DEFAULT_DISK_FORMAT = 'raw'
@@ -53,7 +47,6 @@
5347
"ploop",
5448
]
5549

56-
5750
LOG = logging.getLogger(__name__)
5851

5952

@@ -323,8 +316,10 @@ def take_action(self, parsed_args):
323316
else:
324317
# Read file from stdin
325318
if not sys.stdin.isatty():
326-
if msvcrt:
327-
msvcrt.setmode(sys.stdin.fileno(), os.O_BINARY)
319+
if os.name == "nt":
320+
import msvcrt
321+
322+
msvcrt.setmode(sys.stdin.fileno(), os.O_BINARY) # type: ignore
328323
if hasattr(sys.stdin, 'buffer'):
329324
kwargs['data'] = sys.stdin.buffer
330325
else:
@@ -774,8 +769,10 @@ def take_action(self, parsed_args):
774769
# Read file from stdin
775770
if sys.stdin.isatty() is not True:
776771
if parsed_args.stdin:
777-
if msvcrt:
778-
msvcrt.setmode(sys.stdin.fileno(), os.O_BINARY)
772+
if os.name == "nt":
773+
import msvcrt
774+
775+
msvcrt.setmode(sys.stdin.fileno(), os.O_BINARY) # type: ignore
779776
if hasattr(sys.stdin, 'buffer'):
780777
kwargs['data'] = sys.stdin.buffer
781778
else:

openstackclient/image/v2/image.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,6 @@
3737
from openstackclient.i18n import _
3838
from openstackclient.identity import common as identity_common
3939

40-
if os.name == "nt":
41-
import msvcrt
42-
else:
43-
msvcrt = None
44-
45-
4640
CONTAINER_CHOICES = ["ami", "ari", "aki", "bare", "docker", "ova", "ovf"]
4741
DEFAULT_CONTAINER_FORMAT = 'bare'
4842
DEFAULT_DISK_FORMAT = 'raw'
@@ -61,7 +55,6 @@
6155
]
6256
MEMBER_STATUS_CHOICES = ["accepted", "pending", "rejected", "all"]
6357

64-
6558
LOG = logging.getLogger(__name__)
6659

6760

@@ -155,8 +148,10 @@ def get_data_from_stdin():
155148
image = sys.stdin
156149
if hasattr(sys.stdin, 'buffer'):
157150
image = sys.stdin.buffer
158-
if msvcrt:
159-
msvcrt.setmode(sys.stdin.fileno(), os.O_BINARY)
151+
if os.name == "nt":
152+
import msvcrt
153+
154+
msvcrt.setmode(sys.stdin.fileno(), os.O_BINARY) # type: ignore
160155

161156
return image
162157
else:

0 commit comments

Comments
 (0)