Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ To be released.
- Python 3.5 and 3.6 are no more supported. Instead, Python 3.8, 3.9, and 3.10
are now officially supported.
- Added ``show-bencodex``, a CLI program.
- Added ``BKey`` type.
- Fixed ``BValue`` type.


Version 1.0.1
Expand Down
10 changes: 7 additions & 3 deletions bencodex/types.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
from typing import Any
from typing import Mapping, Sequence, Union

__all__ = 'BValue',
__all__ = (
"BKey",
"BValue",
)


BValue = Any
BKey = Union[str, bytes]
BValue = Union[BKey, int, None, Mapping[BKey, "BValue"], Sequence["BValue"]]
# Mypy currently does not support recursive types.
# https://github.com/python/mypy/issues/731
2 changes: 1 addition & 1 deletion bencodex/writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def is_unicode(k: Union[bytes, str]) -> bool:
return True
raise TypeError('dictionary key must be a bytes or str')
items = [
(u, k.encode('utf-8') if u else k, v)
(u, k.encode('utf-8') if u and isinstance(k, str) else k, v)
for k, v in value.items()
for u in [is_unicode(k)]
]
Expand Down
4 changes: 2 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ commands =
[testenv:mypy]
basepython = python3
deps =
mypy >= 0.971
mypy >= 0.981
commands =
mypy --install-types --non-interactive -p bencodex
mypy --install-types --non-interactive -p bencodex --enable-recursive-aliases

[flake8]
exclude =
Expand Down