openlawlibrary / pygls

A pythonic generic language server
https://pygls.readthedocs.io/en/latest/
Apache License 2.0
568 stars 103 forks source link

Fix detection of `LanguageServer` type annotation when future annotations are used #352

Closed zanieb closed 1 year ago

zanieb commented 1 year ago

Description

The following example fails on main because the annotation is a string rather than a concrete type due to the use of from __future__ import annotations. typing.get_type_hints can be used to resolve the annotations for the signature to support detection in this case.

from __future__ import annotations

from pygls import server

async def example(
    foo: server.LanguageServer,
    params: None,
) -> None:
    pass

from pygls.feature_manager import has_ls_param_or_annotation

assert has_ls_param_or_annotation(example, server.LanguageServer)

This can also be reproduced by wrapping the annotation type in a string manually (as I do in the test in this pull request).

Code review checklist (for code reviewer to complete)

tombh commented 1 year ago

Looks good ❤️

I'm happy to merge. But maybe @alcarney wants to give it a thumbs up too?

tombh commented 1 year ago

Thank you 🙇

alcarney commented 1 year ago

But maybe @alcarney wants to give it a thumbs up too?

Better late than never! :sweat_smile: Looks good!