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

[python] Make the method fields of requests, responses and notifications literals #355

Merged

Conversation

svenberkvens
Copy link
Contributor

This makes it possible for cattrs to build a disambiguation function based on this unique field, which allows one to do things like:

>>> from lsprotocol import types, converters
>>>
>>> converter = converters.get_converter()
>>> d = {"jsonrpc":"2.0","method":"window/logMessage","params":{"type":3,"message":"Server starting"}}
>>> converter.structure(d, types.NOTIFICATIONS | types.REQUESTS)
WindowLogMessageNotification(params=LogMessageParams(type=<MessageType.Info: 3>, message='Server starting'), method='window/logMessage', jsonrpc='2.0')

…ons literals

This makes it possible for cattrs to build a disambiguation function
based on this unique field, which allows one to do things like:

```python
>>> from lsprotocol import types, converters
>>>
>>> converter = converters.get_converter()
>>> d = {"jsonrpc":"2.0","method":"window/logMessage","params":{"type":3,"message":"Server starting"}}
>>> converter.structure(d, types.NOTIFICATIONS | types.REQUESTS)
WindowLogMessageNotification(params=LogMessageParams(type=<MessageType.Info: 3>, message='Server starting'), method='window/logMessage', jsonrpc='2.0')
```
@svenberkvens
Copy link
Contributor Author

@microsoft-github-policy-service agree

@karthiknadig karthiknadig self-assigned this May 24, 2024
@karthiknadig karthiknadig added the feature-request Request for new features or functionality label May 24, 2024
@karthiknadig karthiknadig merged commit a9f0921 into microsoft:main Jun 6, 2024
25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request Request for new features or functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants