Skip to content
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 type hints to Subscription #1440

Merged
merged 2 commits into from
Sep 14, 2023

Conversation

okapies
Copy link
Contributor

@okapies okapies commented Sep 13, 2023

  • Add type hints to Subscription
  • Add SubscriptionHandler protocol class for type hinting

@okapies okapies force-pushed the feature/typing-subscription-1 branch from 21b2e26 to 2704ce9 Compare September 13, 2023 10:31
@oroulet
Copy link
Member

oroulet commented Sep 13, 2023

to solve that error. use if typing.TYPE_CHECKING: import whatever for typing

@okapies okapies force-pushed the feature/typing-subscription-1 branch from 2704ce9 to a120b54 Compare September 13, 2023 12:50
@okapies
Copy link
Contributor Author

okapies commented Sep 14, 2023

@oroulet Some tests failed because they pass Node to subscribe_events directly instead of NodeId:

etype = await opc.server.create_custom_event_type(2, 'MyEvent', ua.ObjectIds.BaseEventType, [
('PropertyNum', ua.VariantType.Float),
('PropertyString', ua.VariantType.String)
])
evgen = await opc.server.get_event_generator(etype)
myhandler = MySubHandler()
sub = await opc.opc.create_subscription(100, myhandler)
handle = await sub.subscribe_events(evtypes=etype)

against the pydoc:

    async def subscribe_events(
        ...
    ) -> int:
        """
        ...
        :param evtypes: ua.ObjectIds or ua.NodeId

Do you think we still need to support Node, or fix the tests to pass NodeId?

@oroulet
Copy link
Member

oroulet commented Sep 14, 2023

We have been supporting both for ages, so we should continue with it

@okapies
Copy link
Contributor Author

okapies commented Sep 14, 2023

Ok, I'll fix both the implementation and the type hint.

@okapies okapies force-pushed the feature/typing-subscription-1 branch from 6637ee6 to 9723d0c Compare September 14, 2023 05:41
@oroulet oroulet merged commit 6c0c53d into FreeOpcUa:master Sep 14, 2023
5 checks passed
@okapies
Copy link
Contributor Author

okapies commented Sep 14, 2023

Thank you!

@okapies okapies deleted the feature/typing-subscription-1 branch September 14, 2023 07:16
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