python-language-server icon indicating copy to clipboard operation
python-language-server copied to clipboard

Implement typing `Literal` support

Open jakebailey opened this issue 6 years ago • 2 comments

After #1640 stops the crashes, we'll have to add real Literal support. This involves:

  • Adding a new class PythonLiteral and adding it to the typing module.
  • Modify the SpecificTypeConstructor delegate type to accept IMembers instead of IPythonTypes, since we now need to be able to have non-types.
  • Potentially undo some of #1631, since None would be a valid non-type and could be passed through, allowing NoneType to return with None as its sole instance.

Related to #535, but this is a more specific case.

jakebailey avatar Oct 08 '19 19:10 jakebailey

This is probably going to require some hefty changes to the TypeAnnotation stuff, since right now if a constant string is seen, we assume that it's supposed to be another type and parse it, but if it's a literal, we don't want to do that. (Maybe we shouldn't be doing that at all past a top level annotation being a string; need to read the spec.)

That and TypeAnnotation also relies on annotations be solely constructed with IPythonType.

jakebailey avatar Oct 08 '19 20:10 jakebailey

FWIW the new LS we released today has full typing support: https://devblogs.microsoft.com/python/announcing-pylance-fast-feature-rich-language-support-for-python-in-visual-studio-code/

jakebailey avatar Jun 30 '20 22:06 jakebailey