SublimeText / sublime_lib

Utility library for frequently used functionality in Sublime Text and convenience functions or classes
https://sublimetext.github.io/sublime_lib
MIT License
52 stars 4 forks source link

Type annotations don't work correctly with pyright #171

Closed rchl closed 3 years ago

rchl commented 3 years ago

Opening this project in ST with LSP-pyright enabled highlights all type annotations with errors. This is because pyright can't handle try/except based import logic like in: https://github.com/SublimeText/sublime_lib/blob/54bcf41ee8de4a7c6482a3e60aa0d72383465d96/st3/sublime_lib/_compat/typing.py It will always use the "last" import in such case.

The solution to that is doing a check based on python version like in: https://github.com/sublimelsp/LSP/blob/7fc1f80c3d3730b34d1f2fb8be65e41cfb43f2fe/plugin/core/typing.py#L3-L3

Fixing that would improve developer experience.

Thom1729 commented 3 years ago

I'd like to get it working with pyright, but I've had other issues as well. For instance, it seems to complain about using Union[T, U] instead of the new T | U syntax. I may need to change my configuration.

rchl commented 3 years ago

It does show error but with clear explanation why it is shown:

Screenshot 2021-05-18 at 18 05 55

The python version should be controllable with the pythonVersion setting in the configuration file

rchl commented 3 years ago

But for compatibility with the ST runtime I guess you wouldn't want to use that new syntax.

rwols commented 3 years ago

Noticed this as well :)

image
rchl commented 3 years ago

This is likely related because it uses stubbed List type here instead of the proper one.