Skip to content

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

Merged
Karthik Nadig (karthiknadig) merged 1 commit into
microsoft:mainfrom
svenberkvens:python-literals-for-disambiguation
Jun 6, 2024
Merged

Karthik Nadig (karthiknadig) merged 1 commit into
microsoft:mainfrom
svenberkvens:python-literals-for-disambiguation

Conversation

@svenberkvens

Copy link
Copy Markdown
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
Copy Markdown
Contributor Author

@microsoft-github-policy-service agree

@karthiknadig
Karthik Nadig (karthiknadig) merged commit a9f0921 into microsoft:main Jun 6, 2024
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