Skip to content

Commit 115c3bd

Browse files
committed
Deprecate int_from_byte() and byte_array_{index,min,max}()
These methods were really just Python 2 compatibility helpers. Now that we only support Python 3, there is no reason to use them anymore.
1 parent 4ae5cd2 commit 115c3bd

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

kaitaistruct.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -813,6 +813,20 @@ def process_rotate_left(data, amount, group_size):
813813

814814
@staticmethod
815815
def int_from_byte(v):
816+
"""Convert a byte array item to an integer.
817+
818+
Deprecated and no longer used as of KSC 0.12. It is only available
819+
for backwards compatibility and will be removed in the future.
820+
821+
This method only made sense to ensure compatibility with Python 2.
822+
In Python 3, it's simply an identity function.
823+
"""
824+
warnings.warn(
825+
"int_from_byte() is deprecated since 0.12 "
826+
"(in Python 3, it is an identity function)",
827+
DeprecationWarning,
828+
stacklevel=2,
829+
)
816830
return v
817831

818832
@staticmethod
@@ -821,14 +835,53 @@ def byte_from_int(i):
821835

822836
@staticmethod
823837
def byte_array_index(data, i):
838+
"""Return the byte at index `i` in the byte array `data` as an integer.
839+
840+
Deprecated and no longer used as of KSC 0.12. It is only available
841+
for backwards compatibility and will be removed in the future.
842+
843+
This method only made sense to ensure compatibility with Python 2.
844+
In Python 3, `data[i]` should be used instead.
845+
"""
846+
warnings.warn(
847+
"byte_array_index(data, i) is deprecated since 0.12, use data[i] instead",
848+
DeprecationWarning,
849+
stacklevel=2,
850+
)
824851
return data[i]
825852

826853
@staticmethod
827854
def byte_array_min(b):
855+
"""Return the minimum byte in the byte array `data` as an integer.
856+
857+
Deprecated and no longer used as of KSC 0.12. It is only available
858+
for backwards compatibility and will be removed in the future.
859+
860+
This method only made sense to ensure compatibility with Python 2.
861+
In Python 3, `min(b)` should be used instead.
862+
"""
863+
warnings.warn(
864+
"byte_array_min(b) is deprecated since 0.12, use min(b) instead",
865+
DeprecationWarning,
866+
stacklevel=2,
867+
)
828868
return min(b)
829869

830870
@staticmethod
831871
def byte_array_max(b):
872+
"""Return the maximum byte in the byte array `data` as an integer.
873+
874+
Deprecated and no longer used as of KSC 0.12. It is only available
875+
for backwards compatibility and will be removed in the future.
876+
877+
This method only made sense to ensure compatibility with Python 2.
878+
In Python 3, `max(b)` should be used instead.
879+
"""
880+
warnings.warn(
881+
"byte_array_max(b) is deprecated since 0.12, use max(b) instead",
882+
DeprecationWarning,
883+
stacklevel=2,
884+
)
832885
return max(b)
833886

834887
@staticmethod

0 commit comments

Comments
 (0)