Skip to content

Conversation

@cdce8p
Copy link
Collaborator

@cdce8p cdce8p commented Oct 2, 2025

No description provided.

@cdce8p cdce8p requested a review from ilevkivskyi October 2, 2025 11:32
@ilevkivskyi
Copy link
Member

Hm, just to understand: why exactly this is needed? We already have stubs here https://github.com/python/mypy/blob/master/mypy/typeshed/stubs/mypy-native/native_internal.pyi (similar to mypy_extensions). Is it for the benefit of other type checkers, or you think it is simply a cleaner pattern to ship the stubs as part of the distribution?

Btw looking at this we should change the distribution name to librt.

def read_float(data: Buffer, /) -> float: ...
def write_int(data: Buffer, value: int, /) -> None: ...
def read_int(data: Buffer, /): ...
def write_tag(data: Buffer, value: int, /) -> None: ...
Copy link
Member

Choose a reason for hiding this comment

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

This should be mypy_extensions.u8, not int.

def __init__(self, source: bytes | None = None, /) -> None: ...
def getvalue(self) -> bytes: ...

def write_bool(data: Buffer, value: bool, /) -> None: ...
Copy link
Member

Choose a reason for hiding this comment

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

All the read/write functions actually support calling with keywords, e.g. write_int(data=Buffer(), value=42) is valid.

@@ -0,0 +1,14 @@
class Buffer:
def __init__(self, source: bytes | None = None, /) -> None: ...
Copy link
Member

Choose a reason for hiding this comment

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

I tried and explicit None fails with TypeError, also it looks like this one also supports call with keyword. So my original stubs are correct :-)

@cdce8p
Copy link
Collaborator Author

cdce8p commented Oct 2, 2025

Hm, just to understand: why exactly this is needed? We already have stubs here https://github.com/python/mypy/blob/master/mypy/typeshed/stubs/mypy-native/native_internal.pyi (similar to mypy_extensions). Is it for the benefit of other type checkers, or you think it is simply a cleaner pattern to ship the stubs as part of the distribution?

Tbh I missed that completely. I just saw the editor highlighting / missing autocompletion (in VS Code) and couldn't didn't see the stubs file 😅

Screenshot 2025-10-02 at 18 04 49

Guess that would also one of the main benefits of including the stubs in the librt distribution.

Not sure if that magic in the modulefinder would still work then though, so going to close this one.

--

All the read/write functions actually support calling with keywords, e.g. write_int(data=Buffer(), value=42) is valid.

Yeah. I just figured it might make sense to enforce only positional attributes via the stubs :)

@cdce8p cdce8p closed this Oct 2, 2025
@cdce8p cdce8p deleted the native-internal-stub-file branch October 2, 2025 16:08
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