Skip to content

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Add binaryornot stubs #13920

wants to merge 1 commit into from

Conversation

Tatsh
Copy link
Contributor

@Tatsh Tatsh commented May 2, 2025

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 accept str (as the name may suggest) because it calls on chardet.detect() which only accepts bytes | bytearray.

This comment has been minimized.

Copy link
Contributor

github-actions bot commented May 2, 2025

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

Copy link
Collaborator

@srittau srittau left a 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 = ...
Copy link
Collaborator

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:

Suggested change
__email__: str = ...
from typing import Final
__author__: Final[str]
__email__: Final[str]
__version__: Final[str]

Comment on lines +1 to +4
import os
from typing import Any

def is_binary(filename: os.PathLike[Any] | bytes | str) -> bool: ...
Copy link
Collaborator

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:

Suggested change
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: ...

Comment on lines +1 to +6
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: ...
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here as well:

Suggested change
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: ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants