microsoft / pylance-release

Documentation and issues for Pylance
Creative Commons Attribution 4.0 International
1.7k stars 767 forks source link

Error in type annotation #2188

Closed fscali closed 2 years ago

fscali commented 2 years ago

Environment data

Expected behaviour

When inserting a type annotation like this:

def monthly_challenge(request,  month: "note that this is a keyword argument and it corresponds to the name specified in the urls file"):
  pass

I shouldn't get any error

Actual behaviour

Pylance signals two errors:

Logs

Python Language Server Log

[Info  - 04:49:32] Pylance language server 2021.12.2 (pyright 211ebe44) starting
[Info  - 04:49:32] Server root directory: /home/francy/.vscode/extensions/ms-python.vscode-pylance-2021.12.2/dist
[Info  - 04:49:32] No configuration file found.
[Info  - 04:49:32] No pyproject.toml file found.
[Info  - 04:49:32] Setting pythonPath for service "monthly_challenges": "/home/francy/anaconda3-updated/envs/django/bin/python"
[Warn  - 04:49:32] stubPath /home/francy/sviluppo/learning/udemy-django-practical-guide/monthly_challenges/typings is not a valid directory.
[Info  - 04:49:32] Assuming Python version 3.10
[Info  - 04:49:32] Assuming Python platform Linux
Search paths for /home/francy/sviluppo/learning/udemy-django-practical-guide/monthly_challenges
  /home/francy/.vscode/extensions/ms-python.vscode-pylance-2021.12.2/dist/typeshed-fallback/stdlib
  /home/francy/sviluppo/learning/udemy-django-practical-guide/monthly_challenges
  /home/francy/sviluppo/learning/udemy-django-practical-guide/monthly_challenges/typings
  /home/francy/.vscode/extensions/ms-python.vscode-pylance-2021.12.2/dist/typeshed-fallback/stubs/...
  /home/francy/.vscode/extensions/ms-python.vscode-pylance-2021.12.2/dist/bundled/stubs
  /home/francy/anaconda3-updated/envs/django/lib/python3.10
  /home/francy/anaconda3-updated/envs/django/lib/python3.10/lib-dynload
  /home/francy/anaconda3-updated/envs/django/lib/python3.10/site-packages
[Warn  - 04:49:32] Exception received when installing file system watcher: TypeError [ERR_FEATURE_UNAVAILABLE_ON_PLATFORM]: The feature watch recursively is unavailable on the current platform, which is being used to run Node.js
[Warn  - 04:49:32] Exception received when installing file system watcher: TypeError [ERR_FEATURE_UNAVAILABLE_ON_PLATFORM]: The feature watch recursively is unavailable on the current platform, which is being used to run Node.js
[Warn  - 04:49:32] Exception received when installing file system watcher: TypeError [ERR_FEATURE_UNAVAILABLE_ON_PLATFORM]: The feature watch recursively is unavailable on the current platform, which is being used to run Node.js
[Info  - 04:49:32] Searching for source files
[Info  - 04:49:32] Found 14 source files
[Info  - 04:49:32] Background analysis(1) root directory: /home/francy/.vscode/extensions/ms-python.vscode-pylance-2021.12.2/dist
[Info  - 04:49:32] Background analysis(1) started
Background analysis message: setConfigOptions
Background analysis message: setImportResolver
Background analysis message: ensurePartialStubPackages
Background analysis message: setTrackedFiles
Background analysis message: markAllFilesDirty
Background analysis message: setFileOpened
Background analysis message: setFileOpened
[FG] parsing: /home/francy/sviluppo/learning/udemy-django-practical-guide/monthly_challenges/challenges/views.py (20ms)
[FG] parsing: /home/francy/.vscode/extensions/ms-python.vscode-pylance-2021.12.2/dist/typeshed-fallback/stdlib/builtins.pyi [fs read 2ms] (75ms)
[FG] binding: /home/francy/.vscode/extensions/ms-python.vscode-pylance-2021.12.2/dist/typeshed-fallback/stdlib/builtins.pyi (35ms)
[FG] binding: /home/francy/sviluppo/learning/udemy-django-practical-guide/monthly_challenges/challenges/views.py (1ms)
Background analysis message: getDiagnosticsForRange
Background analysis message: getDiagnosticsForRange
Background analysis message: analyze
[BG(1)] analyzing: /home/francy/sviluppo/learning/udemy-django-practical-guide/monthly_challenges/challenges/urls.py ...
[BG(1)]   parsing: /home/francy/sviluppo/learning/udemy-django-practical-guide/monthly_challenges/challenges/urls.py (89ms)
[BG(1)]   parsing: /home/francy/.vscode/extensions/ms-python.vscode-pylance-2021.12.2/dist/typeshed-fallback/stdlib/builtins.pyi [fs read 10ms] (140ms)
[BG(1)]   binding: /home/francy/.vscode/extensions/ms-python.vscode-pylance-2021.12.2/dist/typeshed-fallback/stdlib/builtins.pyi (37ms)
[BG(1)]   binding: /home/francy/sviluppo/learning/udemy-django-practical-guide/monthly_challenges/challenges/urls.py (0ms)
[BG(1)]   checking: /home/francy/sviluppo/learning/udemy-django-practical-guide/monthly_challenges/challenges/urls.py ...
[BG(1)]     parsing: /home/francy/.vscode/extensions/ms-python.vscode-pylance-2021.12.2/dist/typeshed-fallback/stdlib/typing.pyi [fs read 1ms] (28ms)
[BG(1)]     binding: /home/francy/.vscode/extensions/ms-python.vscode-pylance-2021.12.2/dist/typeshed-fallback/stdlib/typing.pyi (9ms)
[BG(1)]     parsing: /home/francy/.vscode/extensions/ms-python.vscode-pylance-2021.12.2/dist/typeshed-fallback/stdlib/_typeshed/__init__.pyi [fs read 0ms] (7ms)
[BG(1)]     binding: /home/francy/.vscode/extensions/ms-python.vscode-pylance-2021.12.2/dist/typeshed-fallback/stdlib/_typeshed/__init__.pyi (1ms)
[BG(1)]     parsing: /home/francy/.vscode/extensions/ms-python.vscode-pylance-2021.12.2/dist/typeshed-fallback/stdlib/types.pyi [fs read 0ms] (9ms)
[BG(1)]     binding: /home/francy/.vscode/extensions/ms-python.vscode-pylance-2021.12.2/dist/typeshed-fallback/stdlib/types.pyi (2ms)
[BG(1)]     parsing: /home/francy/.vscode/extensions/ms-python.vscode-pylance-2021.12.2/dist/typeshed-fallback/stdlib/typing_extensions.pyi [fs read 1ms] (3ms)
[BG(1)]     binding: /home/francy/.vscode/extensions/ms-python.vscode-pylance-2021.12.2/dist/typeshed-fallback/stdlib/typing_extensions.pyi (0ms)
[BG(1)]     parsing: /home/francy/.vscode/extensions/ms-python.vscode-pylance-2021.12.2/dist/typeshed-fallback/stdlib/abc.pyi [fs read 0ms] (0ms)
[BG(1)]     binding: /home/francy/.vscode/extensions/ms-python.vscode-pylance-2021.12.2/dist/typeshed-fallback/stdlib/abc.pyi (0ms)
[BG(1)]     parsing: /home/francy/.vscode/extensions/ms-python.vscode-pylance-2021.12.2/dist/bundled/stubs/django/urls/__init__.pyi [fs read 0ms] (1ms)
[BG(1)]     binding: /home/francy/.vscode/extensions/ms-python.vscode-pylance-2021.12.2/dist/bundled/stubs/django/urls/__init__.pyi (0ms)
[BG(1)]     parsing: /home/francy/.vscode/extensions/ms-python.vscode-pylance-2021.12.2/dist/bundled/stubs/django/urls/conf.pyi [fs read 0ms] (1ms)
[BG(1)]     binding: /home/francy/.vscode/extensions/ms-python.vscode-pylance-2021.12.2/dist/bundled/stubs/django/urls/conf.pyi (0ms)
[BG(1)]     parsing: /home/francy/.vscode/extensions/ms-python.vscode-pylance-2021.12.2/dist/bundled/stubs/django/urls/resolvers.pyi [fs read 0ms] (6ms)
[BG(1)]     binding: /home/francy/.vscode/extensions/ms-python.vscode-pylance-2021.12.2/dist/bundled/stubs/django/urls/resolvers.pyi (2ms)
[BG(1)]     parsing: /home/francy/.vscode/extensions/ms-python.vscode-pylance-2021.12.2/dist/bundled/stubs/django/http/response.pyi [fs read 0ms] (14ms)
[BG(1)]     binding: /home/francy/.vscode/extensions/ms-python.vscode-pylance-2021.12.2/dist/bundled/stubs/django/http/response.pyi (3ms)
[BG(1)]     parsing: /home/francy/.vscode/extensions/ms-python.vscode-pylance-2021.12.2/dist/bundled/stubs/django/conf/urls/__init__.pyi [fs read 0ms] (3ms)
[BG(1)]     binding: /home/francy/.vscode/extensions/ms-python.vscode-pylance-2021.12.2/dist/bundled/stubs/django/conf/urls/__init__.pyi (1ms)
[BG(1)]     parsing: /home/francy/sviluppo/learning/udemy-django-practical-guide/monthly_challenges/challenges/__init__.py [fs read 0ms] (0ms)
[BG(1)]     binding: /home/francy/sviluppo/learning/udemy-django-practical-guide/monthly_challenges/challenges/__init__.py (0ms)
[BG(1)]     parsing: /home/francy/sviluppo/learning/udemy-django-practical-guide/monthly_challenges/challenges/views.py (4ms)
[BG(1)]     binding: /home/francy/sviluppo/learning/udemy-django-practical-guide/monthly_challenges/challenges/views.py (0ms)
[BG(1)]     parsing: /home/francy/.vscode/extensions/ms-python.vscode-pylance-2021.12.2/dist/bundled/stubs/django/http/__init__.pyi [fs read 0ms] (1ms)
[BG(1)]     binding: /home/francy/.vscode/extensions/ms-python.vscode-pylance-2021.12.2/dist/bundled/stubs/django/http/__init__.pyi (1ms)
[BG(1)]   checking: /home/francy/sviluppo/learning/udemy-django-practical-guide/monthly_challenges/challenges/urls.py (138ms)
[BG(1)] analyzing: /home/francy/sviluppo/learning/udemy-django-practical-guide/monthly_challenges/challenges/urls.py (409ms)
Background analysis message: resumeAnalysis
[BG(1)] analyzing: /home/francy/sviluppo/learning/udemy-django-practical-guide/monthly_challenges/challenges/views.py ...
[BG(1)]   checking: /home/francy/sviluppo/learning/udemy-django-practical-guide/monthly_challenges/challenges/views.py ...
[BG(1)]     parsing: /home/francy/.vscode/extensions/ms-python.vscode-pylance-2021.12.2/dist/bundled/stubs/django/shortcuts.pyi [fs read 1ms] (6ms)
[BG(1)]     binding: /home/francy/.vscode/extensions/ms-python.vscode-pylance-2021.12.2/dist/bundled/stubs/django/shortcuts.pyi (0ms)
[BG(1)]     parsing: /home/francy/.vscode/extensions/ms-python.vscode-pylance-2021.12.2/dist/bundled/stubs/django/http/request.pyi [fs read 0ms] (10ms)
[BG(1)]     binding: /home/francy/.vscode/extensions/ms-python.vscode-pylance-2021.12.2/dist/bundled/stubs/django/http/request.pyi (2ms)
[BG(1)]     parsing: /home/francy/.vscode/extensions/ms-python.vscode-pylance-2021.12.2/dist/typeshed-fallback/stdlib/io.pyi [fs read 1ms] (8ms)
[BG(1)]     binding: /home/francy/.vscode/extensions/ms-python.vscode-pylance-2021.12.2/dist/typeshed-fallback/stdlib/io.pyi (12ms)
[BG(1)]   checking: /home/francy/sviluppo/learning/udemy-django-practical-guide/monthly_challenges/challenges/views.py (45ms)
[BG(1)] analyzing: /home/francy/sviluppo/learning/udemy-django-practical-guide/monthly_challenges/challenges/views.py (45ms)
Background analysis message: resumeAnalysis
Background analysis message: getDiagnosticsForRange
Background analysis message: getDiagnosticsForRange

Code Snippet / Additional information

XXX
erictraut commented 2 years ago

Pylance is correct in reporting an error here. This isn't a legal type annotation. For information about type annotations, please refer to PEP 484.

gramster commented 2 years ago

Please see https://www.python.org/dev/peps/pep-0484/#id28

Using strings as annotations is for forward references of type hints. The content of the string needs to be a valid Python expression.