Make command classes backwards compatible with existing class hierarchies - #38
Make command classes backwards compatible with existing class hierarchies#38rwols wants to merge 2 commits into
Conversation
This allows inheriting from the new sublime_aio command classes without disturbing existing inheritance hierarchies and dependent packages.
|
I am aware of this being possible, but as mentioned in the other PR this is not supported by intent. Synchronous code is to use synchronous functions and async code is to use |
|
Anything else ends in unpredictable chaos. |
|
Imo LSP should create a new If you really want to not change your interface for Lsp plugins, you should create your own wrapper class with the desired functionality. |
|
What is the actual, technical, problem being avoided when choosing to not allowing sync I see claims like:
Can you elaborate on what is unpredictable or weird about it? Let me try to make a case... You mention:
As proven in this PR, there is no technical reason why exclusive use of async def is required in these command classes.
The plugin may decide to do something synchronous, and then invoke But on top of that, like I mentioned a few times, there is a gradual refactoring / upgrade path possible when allowing these run functions to remain sync.
Regarding the unpredictable chaos, I really don't see it. (But perhaps I have to get better educated on this). If you have a sync I hope this helps sway the opinion. |
This statement is too true and summarizes python asyncio's major design failure as a whole. Everything - the insane it might be - is possible. Quick comparison: Python does not support protected/private modifiers to enforce visibility/accessibility rules like C++/C# or Java. Users are responsible to use the language in sane ways, but they can do everything insane as well. It's the same with asyncio. Being technically able to to everything doesn't mean it is good design nor desirable. Instead of asynchronous io concept and its async/await keywords being a core language feature as in other popular languages, python added I don't want to argue about reasons. It didn't even know about or support See how they even leave you as a user behind with responsibility for pending tasks to not get garbage collected before being called. They track the tasks, would be able to do it on their own, but do it in weakrefs to ensure they get deleted before called. See how asyncio can't even handle asynchronous file io at its core. Even addons like anyio just call synchronous functions pushed to worker threads in a world of GIL effectively blocking multiple threads from working concurrently, efficiently. Python's asyncio works on an insane high level of entropy. This is what I call "chaos". IMHO, they should restart thinking about it, completely. This is where libraries such as This is what all 3rd-party libraries are heading to. Exclusively support async/await APIs. A common design found in libraries is:
The major point is explicit visibility about what something does and what desired target runtime is - async or sync. The core requirement therefore is: Classes and their methods "must" be clear about whether they are designed for being executed in an event loop or in synchronous code to avoid possibly fatal confusion and minimize risk of critical bugs, such as running expensive long lasting CPU bound synchronous functions on the core event loop thread, effectively blocking anything else. And this is what sublime_aio is designed for and what this PR violates. Merging this PR would open doors with dragons behind, which can't be closed again, adding support undesirable design flaws. The only use case and justification for any Idea is for migration to be as easy as replacing If a package needs extra steps to maintain certain levels of backward compatibility by violating modern python's asyncio design goals, it is to be implemented by that plugin. It is not within scope of a core library to provide all sorts of insanity which is technically possible. That's what was refered to as "not designed for" or "design decision". A design decision decides for one of many technically possible directions to keep infrastructure and API in sane limits. |
This is both a PR but also a proposal to have the functionality as I mentioned in this comment. It makes the changes in sublimelsp/LSP#3004 work. Meaning, it allows existing packages to inherit from sublime_aio.ViewCommand safely.
If the
runmethod is not a coroutine function, it is simply invoked as-is, and in the case of a view command the edit_token is passed as first argument as well.