8000 Merge pull request #15927 from eerovaher/struct-alias · astropy/astropy@97bf1e1 · GitHub
[go: up one dir, main page]

Skip to content

Commit 97bf1e1

Browse files
authored
Merge pull request #15927 from eerovaher/struct-alias
Remove aliases for `struct.pack` and `struct.unpack`
2 parents a3f6aea + 4fbfe54 commit 97bf1e1

File tree

1 file changed

+8
-13
lines changed

1 file changed

+8
-13
lines changed

astropy/io/votable/converters.py

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@
66

77
# STDLIB
88
import re
9+
import struct
910
import sys
10-
from struct import pack as _struct_pack
11-
from struct import unpack as _struct_unpack
1211

1312
# THIRD-PARTY
1413
import numpy as np
@@ -57,10 +56,6 @@
5756
_zero_byte = b"\0"
5857

5958

60-
struct_unpack = _struct_unpack
61-
struct_pack = _struct_pack
62-
63-
6459
if sys.byteorder == "little":
6560

6661
def _ensure_bigendian(x):
@@ -154,7 +149,7 @@ def bool_to_bitarray(value):
154149
if bit_no != 7:
155150
bytes.append(byte)
156151

157-
return struct_pack(f"{len(bytes)}B", *bytes)
152+
return struct.pack(f"{len(bytes)}B", *bytes)
158153

159154

160155
class Converter:
@@ -182,11 +177,11 @@ def __init__(self, field, config=None, pos=None):
182177

183178
@staticmethod
184179
def _parse_length(read):
185-
return struct_unpack(">I", read(4))[0]
180+
return struct.unpack(">I", read(4))[0]
186181

187182
@staticmethod
188183
def _write_length(length):
189-
return struct_pack(">I", int(length))
184+
return struct.pack(">I", int(length))
190185

191186
def supports_empty_values(self, config):
192187
"""
@@ -379,7 +374,7 @@ def _binparse_var(self, read):
379374
return read(length).decode("ascii"), False
380375

381376
def _binparse_fixed(self, read):
382-
s = struct_unpack(self._struct_format, read(self.arraysize))[0]
377+
s = struct.unpack(self._struct_format, read(self.arraysize))[0]
383378
end = s.find(_zero_byte)
384379
s = s.decode("ascii")
385380
if end != -1:
@@ -404,7 +399,7 @@ def _binoutput_fixed(self, value, mask):
404399
value = value.encode("ascii")
405400
except ValueError:
406401
vo_raise(E24, (value, self.field_name))
407-
return struct_pack(self._struct_format, value)
402+
return struct.pack(self._struct_format, value)
408403

409404

410405
class UnicodeChar(Converter):
@@ -453,7 +448,7 @@ def _binparse_var(self, read):
453448
return read(length * 2).decode("utf_16_be"), False
454449

455450
def _binparse_fixed(self, read):
456-
s = struct_unpack(self._struct_format, read(self.arraysize * 2))[0]
451+
s = struct.unpack(self._struct_format, read(self.arraysize * 2))[0]
457452
s = s.decode("utf_16_be")
458453
end = s.find("\0")
459454
if end != -1:
@@ -469,7 +464,7 @@ def _binoutput_var(self, value, mask):
469464
def _binoutput_fixed(self, value, mask):
470465
if mask:
471466
value = ""
472-
return struct_pack(self._struct_format, value.encode("utf_16_be"))
467+
return struct.pack(self._struct_format, value.encode("utf_16_be"))
473468

474469

475470
class Array(Converter):

0 commit comments

Comments
 (0)
0