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

feature and command decorators loose type annotations #88

Closed
perrinjerome opened this issue Jan 6, 2020 · 0 comments · Fixed by #89
Closed

feature and command decorators loose type annotations #88

perrinjerome opened this issue Jan 6, 2020 · 0 comments · Fixed by #89
Assignees
Labels
bug Something isn't working

Comments

@perrinjerome
Copy link
Contributor

If I use this patch on json-extension example:

diff --git a/examples/json-extension/server/server.py b/examples/json-extension/server/server.py
index efd6087..70fd3bf 100644
--- a/examples/json-extension/server/server.py
+++ b/examples/json-extension/server/server.py
@@ -90,7 +90,7 @@ def _validate_json(source):
 
 
 @json_server.feature(COMPLETION, trigger_characters=[','])
-def completions(params: CompletionParams = None):
+def completions(params: CompletionParams = None) -> CompletionList:
     """Returns completion items."""
     return CompletionList(False, [
         CompletionItem('"'),
diff --git a/examples/json-extension/server/tests/unit/test_features.py b/examples/json-extension/server/tests/unit/test_features.py
index b2ff762..3ec98d7 100644
--- a/examples/json-extension/server/tests/unit/test_features.py
+++ b/examples/json-extension/server/tests/unit/test_features.py
@@ -50,8 +50,9 @@ def _reset_mocks():
     server.show_message_log.reset_mock()
 
 
-def test_completions():
-    completion_list = completions()
+def test_completions() -> None:
+    completion_list = completions("type error")
+    reveal_type(completion_list)
     labels = [i.label for i in completion_list.items]
 
     assert '"' in labels

I would expect that mypy report type error for wrong "type error" argument and reveal type of completion_list as CompletionList, instead, I have:

$ mypy examples/json-extension/server/tests/unit/test_features.py 
...
examples/json-extension/server/tests/unit/test_features.py:55: note: Revealed type is 'Any'

I would have expected something like:

$ mypy examples/json-extension/server/tests/unit/test_features.py
...
examples/json-extension/server/tests/unit/test_features.py:54: error: Argument 1 to "completions" has incompatible type "str"; expected "Optional[CompletionParams]"
examples/json-extension/server/tests/unit/test_features.py:55: note: Revealed type is 'pygls.types.CompletionList'
perrinjerome added a commit to perrinjerome/pygls that referenced this issue Jan 6, 2020
Use a TypeVar so that type checkers understand that the signature is
same as the decorated functions, so that these functions can be
typechecked.

fixes openlawlibrary#88
perrinjerome added a commit to perrinjerome/pygls that referenced this issue Jan 6, 2020
Use a TypeVar so that type checkers understand that the signature is
same as the decorated functions, so that these functions can be
typechecked.

fixes openlawlibrary#88
@perrinjerome perrinjerome mentioned this issue Jan 6, 2020
5 tasks
@danixeee danixeee added the bug Something isn't working label Jan 17, 2020
perrinjerome added a commit to perrinjerome/pygls that referenced this issue Jan 26, 2020
Use a TypeVar so that type checkers understand that the signature is
same as the decorated functions, so that these functions can be
typechecked.

fixes openlawlibrary#88
perrinjerome added a commit to perrinjerome/pygls that referenced this issue Jan 26, 2020
Use a TypeVar so that type checkers understand that the signature is
same as the decorated functions, so that these functions can be
typechecked.

fixes openlawlibrary#88
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants