-
Notifications
You must be signed in to change notification settings - Fork 184
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
Import from typing, typing_extensions and enum modules on Python 3.8 #2446
Conversation
This reverts commit c70cd57.
* main: Cut 1.29.0 Fix usage of sublime.score_selector (sublimelsp#2427) docs: add info about typst-lsp commands (sublimelsp#2424)
This commit adopts `unittesting.ViewTestCase` to run view related test cases. ViewTestCase ... 1. provides `view` and `window` members pointing to a dedicated view, being created for testing. 2. ensures not to close empty windows, which was probably the most likely reason for unittests failing before on MacOS.
Fwiw, with |
I would say that we can make those changes step by step in separate PRs. So the next steps could be
The pipe operator was introduced in Python 3.10 and the syntax with And this is probably significantly more work if done manually throughout the whole code base, so we should check how well it would work to do it automatically. |
By the way, with this PR there are still 3 classes required to be imported from the local |
Nice! I would rather not rush into merging this in feat/py38, |
Okay, I can change the target branch then and rebase. Regarding typing_extensions, I can see that it was merged two weeks ago in packagecontrol/channel@cd8ec01, but it's not (yet?) in the https://packagecontrol.github.io/channel/channel_v4.json file used by Package Control. So maybe we need to wait a bit until it gets updated. I think with if TYPE_CHECKING:
from typing import NotRequired, TypeGuard but it wouldn't work with |
Will check the |
typing_extensions seems to be fixed upstream now. So the question would be if we want to have it as an additional dependency or not. With it, I missed to mention above that there is still |
I think more or less, class StrEnum(str, Enum):
def __str__(self) -> str:
return self.value.__str__() |
There is another problem with LSP's fake enums. Currently we can use the syntax I guess I'll revert using the "real" enums, for now... |
Maybe you can try from enum import IntEnum
class Color(IntEnum):
RED = 10
def __str__(self) -> str:
return self.value.__str__() In ST console, it works. But I am not sure about other APIs. >>> from enum import IntEnum
class Color(IntEnum):
RED = 10
>>> Color.RED
<Color.RED: 10>
>>> r = sublime.Region(Color.RED)
>>> r
Region(10, 10) ref: https://docs.python.org/3.12/library/enum.html#enum.IntEnum |
The IntEnum classes are actually not problematic, because comparisons work out of the box for them. But a problem is that some other classes in protocol.py inherit from And there are some problems in the initialize request, where we access the enum members directly in the code (and not via |
#2446 (comment) works in my test. >>> from enum import Enum
class StrEnum(str, Enum):
def __str__(self) -> str:
return self.value.__str__()
class Kind(StrEnum):
KEYWORD = "1"
CONSTANT = "2"
>>> Kind.KEYWORD == '1'
True
>>> Kind.KEYWORD < '2'
True Would it be problematic if it inherits from this Lines 81 to 82 in 5891ff4
class StrEnum(str, Enum):
def __str__(self) -> str:
return self.value.__str__() |
No, your suggestion should work too. But it's not much different in practice from what we currently have with class StrEnum:
pass The problem was that the enums in protocol.py are automatically generated from https://github.com/microsoft/lsprotocol and they used |
But then do we still have |
Problem 1 was that for the initialize request we used for example Line 299 in 5891ff4
which would give us something like Problem 2 was that comparisons of enums which have string values would not work anymore in the code, because those enums only used the But both should be fixed now in 8c01147 |
@predragnikolic I wonder can you restore the |
Will do, I saw what happened. I thought that it would just switch to the |
Well, I died a bit inside when I saw this :D |
On Python 3.8
enum
andtyping
are part of the standard library..core.typing
still contains all the fake typing classes, because many LSP-* plugins import fromLSP.plugin.core.typing
.