-
Notifications
You must be signed in to change notification settings - Fork 25
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
add python type information for MessageQueue class #54
Open
sillydan1
wants to merge
5
commits into
osvenskan:develop
Choose a base branch
from
sillydan1:feature/typeshed
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
219d9cd
add python type information for MessageQueue class
sillydan1 f3537a5
add python type information for the rest of the objects mentioned in …
sillydan1 2b2970f
include type info in the packaging
sillydan1 311bae2
add stuff i missed, but was caught by pybind11
sillydan1 50329f1
add unit test that ensures type-compatibility
sillydan1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,3 +12,6 @@ demo/*.o | |
demo/premise | ||
demo/conclusion | ||
post_dist.py | ||
**/*.egg-info | ||
tests/stubs/ | ||
posix_ipc*.so |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
from collections.abc import Callable | ||
from typing import Any | ||
|
||
__all__ = [ | ||
"BusyError", | ||
"Error", | ||
"ExistentialError", | ||
"MESSAGE_QUEUES_SUPPORTED", | ||
"MessageQueue", | ||
"O_CREAT", | ||
"O_CREX", | ||
"O_EXCL", | ||
"O_NONBLOCK", | ||
"O_RDONLY", | ||
"O_RDWR", | ||
"O_TRUNC", | ||
"O_WRONLY", | ||
"PAGE_SIZE", | ||
"PermissionsError", | ||
"QUEUE_MESSAGES_MAX_DEFAULT", | ||
"QUEUE_MESSAGE_SIZE_MAX_DEFAULT", | ||
"QUEUE_PRIORITY_MAX", | ||
"SEMAPHORE_TIMEOUT_SUPPORTED", | ||
"SEMAPHORE_VALUE_MAX", | ||
"SEMAPHORE_VALUE_SUPPORTED", | ||
"Semaphore", | ||
"SharedMemory", | ||
"SignalError", | ||
"USER_SIGNAL_MAX", | ||
"USER_SIGNAL_MIN", | ||
"unlink_message_queue", | ||
"unlink_semaphore", | ||
"unlink_shared_memory", | ||
] | ||
|
||
# module functions | ||
|
||
def unlink_semaphore(name: str) -> None: ... | ||
def unlink_shared_memory(name: str) -> None: ... | ||
def unlink_message_queue(name: str) -> None: ... | ||
|
||
# module constants | ||
|
||
O_CREX: int | ||
O_CREAT: int | ||
O_EXCL: int | ||
O_TRUNC: int | ||
PAGE_SIZE: int | ||
SEMAPHORE_TIMEOUT_SUPPORTED: bool | ||
SEMAPHORE_VALUE_SUPPORTED: bool | ||
SEMAPHORE_VALUE_MAX: int | ||
MESSAGE_QUEUES_SUPPORTED: bool | ||
QUEUE_MESSAGES_MAX_DEFAULT: int | ||
QUEUE_MESSAGE_SIZE_MAX_DEFAULT: int | ||
QUEUE_PRIORITY_MAX: int | ||
USER_SIGNAL_MIN: int | ||
USER_SIGNAL_MAX: int | ||
VERSION: str | ||
O_NONBLOCK: int | ||
O_RDONLY: int | ||
O_RDWR: int | ||
O_WRONLY: int | ||
|
||
# errors | ||
|
||
class SignalError(Error): | ||
pass | ||
|
||
class PermissionsError(Error): | ||
pass | ||
|
||
class BusyError(Error): | ||
pass | ||
|
||
class Error(Exception): | ||
pass | ||
|
||
class ExistentialError(Error): | ||
pass | ||
|
||
# classes | ||
|
||
class Semaphore: | ||
def __init__(self, name: str, flags: int = ..., mode: int = ..., initial_value: int = ...) -> None: ... | ||
def acquire(self, timeout: float | None = ...) -> None: ... | ||
def release(self) -> None: ... | ||
def close(self) -> None: ... | ||
def unlink(self) -> None: ... | ||
def __enter__(self) -> None: ... | ||
def __exit__(self) -> None: ... | ||
|
||
class SharedMemory: | ||
"""POSIX semaphore object.""" | ||
|
||
def __init__( | ||
self, name: str, flags: int = ..., mode: int = ..., size: int = ..., read_only: bool = ... | ||
) -> None: ... | ||
def close_fd(self) -> None: ... | ||
def fileno(self) -> None: ... | ||
def unlink(self) -> None: ... | ||
|
||
class MessageQueue: | ||
def __init__( | ||
self, | ||
name: str | None, | ||
flags: int = ..., | ||
mode: int = ..., | ||
max_messages: int = ..., | ||
max_message_size: int = ..., | ||
read: bool = ..., | ||
write: bool = ..., | ||
) -> None: ... | ||
def send(self, message: str | bytes, timeout: float | None = ..., priority: int = ...) -> None: ... | ||
def receive(self, timeout: float | None = ...) -> tuple[bytes, int]: ... | ||
def request_notification(self, notification: int | tuple[Callable[[Any], None], Any] | None = ...) -> None: ... | ||
def close(self) -> None: ... | ||
def fileno(self) -> None: ... | ||
def unlink(self) -> None: ... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
"""Test that the stubs generated by pybind11-stubgen are compatible with the hand-crafted ones.""" | ||
|
||
import inspect | ||
import os | ||
import sys | ||
import unittest | ||
from unittest.mock import patch | ||
|
||
import posix_ipc as handcrafted | ||
from pybind11_stubgen import main | ||
|
||
from . import base as tests_base | ||
|
||
|
||
class TestPybind11TypesCompatibility(tests_base.Base): | ||
"""Test that the stubs generated by pybind11-stubgen are compatible with the hand-crafted ones.""" | ||
|
||
def setUp(self): | ||
"""Generate the type stubs.""" | ||
# mock the sys.argv - I dont want to do a subprocess.run because it can be error prone depending on which | ||
# packages you may have installed. | ||
with patch.object(sys, 'argv', ["pybind11-stubgen", "posix_ipc", "-o", "tests/stubs"]): | ||
main() | ||
os.rename("tests/stubs/posix_ipc.pyi", "tests/stubs/__init__.py") # to make the stubs importable | ||
|
||
def test_messagequeue(self): | ||
"""Test the generated MessageQueue is the same as the hand-crafted one.""" | ||
from . import stubs as generated | ||
generated_methods = inspect.getmembers(generated.MessageQueue, predicate=inspect.ismethod) | ||
crafted_methods = inspect.getmembers(handcrafted.MessageQueue, predicate=inspect.ismethod) | ||
crafted_method_names = [m[0] for m in crafted_methods] | ||
for method in generated_methods: | ||
self.assertTrue(method[0] in crafted_method_names) | ||
# NOTE: We can't compare the func signatures, because pybind11-stubgen doesnt generate types for parameters. | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Note: I haven't used travis CI before, so I dont know if this is the correct place to do this.