-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Add binaryornot stubs #13920
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Add binaryornot stubs #13920
Conversation
This comment has been minimized.
This comment has been minimized.
According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Remarks below.
@@ -0,0 +1 @@ | |||
__email__: str = ... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When we're including __email__
we should also include __author__
and __version__
. Also, these should be final:
__email__: str = ... | |
from typing import Final | |
__author__: Final[str] | |
__email__: Final[str] | |
__version__: Final[str] |
import os | ||
from typing import Any | ||
|
||
def is_binary(filename: os.PathLike[Any] | bytes | str) -> bool: ... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We actually have a helper for the argument type:
import os | |
from typing import Any | |
def is_binary(filename: os.PathLike[Any] | bytes | str) -> bool: ... | |
import os | |
from _typeshed import StrOrBytesPath | |
def is_binary(filename: StrOrBytesPath) -> bool: ... |
import os | ||
from typing import Any | ||
|
||
def print_as_hex(s: str) -> None: ... | ||
def get_starting_chunk(filename: os.PathLike[Any] | bytes | str, length: int = 1024) -> bytes: ... | ||
def is_binary_string(bytes_to_check: bytes | bytearray) -> bool: ... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here as well:
import os | |
from typing import Any | |
def print_as_hex(s: str) -> None: ... | |
def get_starting_chunk(filename: os.PathLike[Any] | bytes | str, length: int = 1024) -> bytes: ... | |
def is_binary_string(bytes_to_check: bytes | bytearray) -> bool: ... | |
import os | |
from _typeshed import StrOrBytesPath | |
def print_as_hex(s: str) -> None: ... | |
def get_starting_chunk(filename: StrOrBytesPath, length: int = 1024) -> bytes: ... | |
def is_binary_string(bytes_to_check: bytes | bytearray) -> bool: ... |
https://github.com/binaryornot/binaryornot
Upstream has been inactive for 2 months and has a PR open to add a minimal type stubs (in the code would be better), but it is incomplete.
helpers.is_binary_string
does not acceptstr
(as the name may suggest) because it calls onchardet.detect()
which only acceptsbytes | bytearray
.