Skip to content

Commit

Permalink
Fix compatibility with Python 3.14.0a1
Browse files Browse the repository at this point in the history
typing.ByteString has been removed from Python 3.14.
Ported the suggested way from the documentation:
https://docs.python.org/3.13/library/typing.html#typing.ByteString
  • Loading branch information
befeleme committed Nov 13, 2024
1 parent 7752341 commit a82b795
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/nacl/bindings/crypto_secretstream.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from typing import ByteString, Optional, Tuple, cast
from typing import Optional, Tuple, cast, Union

from nacl import exceptions as exc
from nacl._sodium import ffi, lib
Expand Down Expand Up @@ -73,6 +73,7 @@ class crypto_secretstream_xchacha20poly1305_state:

def __init__(self) -> None:
"""Initialize a clean state object."""
ByteString = Union[bytes, bytearray, memoryview]
self.statebuf: ByteString = ffi.new(
"unsigned char[]",
crypto_secretstream_xchacha20poly1305_STATEBYTES,
Expand Down
3 changes: 2 additions & 1 deletion tests/test_secretstream.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import json
import os
import random
from typing import ByteString, List, Optional, Tuple
from typing import List, Optional, Tuple, Union

from _pytest._code import ExceptionInfo
from _pytest.monkeypatch import MonkeyPatch
Expand Down Expand Up @@ -219,6 +219,7 @@ def test_it_like_libsodium():

header = crypto_secretstream_xchacha20poly1305_init_push(state, k)

ByteString = Union[bytes, bytearray, memoryview]
state_save: ByteString = ffi.buffer(state.statebuf)[:]

c1 = crypto_secretstream_xchacha20poly1305_push(
Expand Down

0 comments on commit a82b795

Please sign in to comment.