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
Not add base classes to its internal text_command_classes
and etc variables
#2175
Comments
To be frank: no. The heuristic to determine a "base class" seems arbitrary and will only fit for your particular use case of a different function signature in The proper way to define a "base class" is to do it as a mixin, i.e. do not derive a command class and for the actual command use multiple inheritance. Then you can do whatever you must inside your class's |
It is definitely not arbitrary, and it dictated by Sublime Text instantiation of the command classes on: File: D:/User/Programs/SublimeText/3143/sublime_plugin.py
199: cmds.append(class_(view)) Here it is instantiating the command classes and forcing them to have exactly 2 parameters (self and view).
I cannot do easily a mixing which needs to call super without adding 2 constructors call on the derived class. To illustrate it, consider the following: from sublime_plugin import TextCommand
class LspTextCommand(object):
def __init__(self, capability):
self.capability = capability
class LspFormatDocumentCommand(TextCommand, LspTextCommand):
def __init__(self, view):
TextCommand.__init__(view)
LspTextCommand__init__('other_stuff')
class LspSymbolDefinitionCommand(LspTextCommand):
def __init__(self, view):
TextCommand.__init__(view)
LspTextCommand.__init__('more_other_stuff') This forces on all derived classes to do 2 super constructors calls from sublime_plugin import TextCommand
class LspTextCommand(TextCommand):
def __init__(self, view, capability):
super(LspTextCommand, self).__init__(view)
self.capability = capability
class LspFormatDocumentCommand(LspTextCommand):
def __init__(self, view):
super(LspFormatDocumentCommand, self).__init__(view, 'other_stuff')
class LspSymbolDefinitionCommand(LspTextCommand):
def __init__(self, view):
super(LspFormatDocumentCommand, self).__init__(view, 'more_other_stuff') Unless I am missing something? Also, Sublime Text should not add any classes to its internal lists if it cannot instantiate them later on: File: D:/User/Programs/SublimeText/3143/sublime_plugin.py
199: cmds.append(class_(view)) Otherwise, some even plugin can just break most things with #2066 or and not allow me to create the inheritance just above. Do you see some flaw in this? Do you still think Sublime Text should keep blinding adding everything which just happens to extend Why do you think it is random to require Sublime Text to load only classes he can instantiate? Why do you want to Sublime Text to be loading user custom bases classes he cannot instantiate? This is not a monster fix. This is a simple if checking which is clearly not random. Do you still not understanding why not load them? |
def __init__(self, view, capability='', last_check=lambda: True): Defining all the other parameters except File: F:/SublimeText/sublime_plugin.py
198: for class_ in text_command_classes:
199: cmds.append(class_(view)) |
from sublime_plugin import TextCommand
class LspTextCommand(object):
def __init__(self, view, capability):
super().__init__(view) # this will call TextCommand.__init__
self.capability = capability
class LspFormatDocumentCommand(LspTextCommand, TextCommand): # the order is important here!
def __init__(self, view):
super().__init__(view, 'other_stuff') # this will call LspTextCommand.__init__
class LspSymbolDefinitionCommand(LspTextCommand, TextCommand):
def __init__(self, view):
super().__init__(view, 'more_other_stuff') https://docs.python.org/3/tutorial/classes.html#multiple-inheritance |
Well, I did this: class LspFormatDocumentCommand(TextCommand, LspTextCommand): And said, |
By the way, if the data you want to specify in, say, from sublime_plugin import TextCommand
class LspTextCommand(object):
capability = None
# … some methods doing stuff with `cls.capability` or `self.capability`
class LspFormatDocumentCommand(LspTextCommand, TextCommand): # the order is *still* important here if LspTextCommand overrides any of TextCommand's methods
capability = 'other_stuff'
class LspSymbolDefinitionCommand(LspTextCommand, TextCommand):
capability = 'more_other_stuff' |
Not add base classes to its internal `text_command_classes` and etc variables sublimehq/sublime_text#2175
Not add base classes to its internal `text_command_classes` and etc variables sublimehq/sublime_text#2175
Thanks, yes, I did not have though about doing that, but in this case, the |
So, can we close this issue? I believe with what I showed, the proposal is simply unnecessary.
I don't see an issue here. That's just polymorphism. |
I would close the as a Duplicate of:
Because they have the same fix.
Well, when I see something like it, I brain just trigger |
commit 09d5f319803e4ea08cfc70001a898a3c471d480b Author: Tom van Ommeren <tom.vanommeren@gmail.com> Date: Mon Feb 5 22:54:50 2018 +0100 Small fixes before merging - don't cache client in hover.py (risk to client restart functionality) - improvement: show diagnostics hovers even if no hoverProvider capability. - remove unneeded event param additions in main.py - restore is_at_word in definition.py commit 36e339b Author: evandrocoan <evandrocoan@hotmail.com> Date: Mon Feb 5 05:53:09 2018 -0200 Passed event to is_at_word(self.view, event) commit ac5e228 Author: evandrocoan <evandrocoan@hotmail.com> Date: Mon Feb 5 00:38:18 2018 -0200 Added missing return on plugin/symbols.py commit 45170ab Author: evandrocoan <evandrocoan@hotmail.com> Date: Sun Feb 4 22:08:22 2018 -0200 TypeError: is_enabled() got an unexpected keyword argument 'point' commit 1a8cd9a Merge: 887a480 bf6a5b4 Author: evandrocoan <evandrocoan@hotmail.com> Date: Sun Feb 4 20:12:10 2018 -0200 Merge branch 'master' into smart_context_menu commit 887a480 Author: evandrocoan <evandrocoan@hotmail.com> Date: Sun Feb 4 20:09:12 2018 -0200 Moved capability from LspTextCommand constructor to has_client_with_capability(). commit c790187 Author: evandrocoan <evandrocoan@hotmail.com> Date: Sun Feb 4 19:52:15 2018 -0200 Fixed clients.py:54:1: E302 expected 2 blank lines, found 1 commit 12bd209 Author: evandrocoan <evandrocoan@hotmail.com> Date: Sun Feb 4 19:49:37 2018 -0200 Fixed hover.py:51: error: Name 'client_for_view' is not defined commit c314e37 Author: evandrocoan <evandrocoan@hotmail.com> Date: Sun Feb 4 19:22:21 2018 -0200 Implemented is_enabled() on all derived classes. commit 6b23fec Merge: 5519535 3bc9cca Author: evandrocoan <evandrocoan@hotmail.com> Date: Sun Feb 4 15:39:24 2018 -0200 Merge branch 'master' into smart_context_menu commit 5519535 Merge: 544d487 b6a3b9d Author: evandrocoan <evandrocoan@hotmail.com> Date: Sat Feb 3 20:19:19 2018 -0200 Merge branch 'master' into smart_context_menu commit 544d487 Author: evandrocoan <evandrocoan@hotmail.com> Date: Fri Feb 2 14:18:43 2018 -0200 Replaced Python 2 super(...) call style by Python 3 super() commit 598a0f6 Merge: e4e5929 7ef8268 Author: evandrocoan <evandrocoan@hotmail.com> Date: Fri Feb 2 14:09:52 2018 -0200 Merge branch 'master' into smart_context_menu commit e4e5929 Author: evandrocoan <evandrocoan@hotmail.com> Date: Thu Feb 1 23:39:18 2018 -0200 Removed the mixing to simply code reading, writing and remove the mypy error: mypy -p plugin clients.py:26: error: Too many arguments for "__init__" of "object" commit 0a397e3 Author: evandrocoan <evandrocoan@hotmail.com> Date: Thu Feb 1 19:30:02 2018 -0200 Fix clients.py 'sublime_plugin.TextCommand' imported but unused commit af5bb11 Author: evandrocoan <evandrocoan@hotmail.com> Date: Wed Jan 31 23:06:16 2018 -0200 Created a mixing with TextCommand and LspTextCommand, issue: Not add base classes to its internal `text_command_classes` and etc variables sublimehq/sublime_text#2175 commit b0f6de3 Author: evandrocoan <evandrocoan@hotmail.com> Date: Wed Jan 31 21:52:10 2018 -0200 Added is_enabled() to LspTextCommand base class. commit 18d080a Author: evandrocoan <evandrocoan@hotmail.com> Date: Wed Jan 31 19:25:04 2018 -0200 Renamed LspContextMenu to LspTextCommand on configurations.py commit a192796 Author: evandrocoan <evandrocoan@hotmail.com> Date: Tue Jan 30 20:35:15 2018 -0200 Fixed The command "mypy -p plugin" exited with 0. 1.94s$ flake8 --exclude=./boot.py ./plugin/code_actions.py:2:1: F401 'sublime_plugin' imported but unused ./plugin/definition.py:2:1: F401 'sublime_plugin' imported but unused ./plugin/formatting.py:1:1: F401 'sublime_plugin' imported but unused ./plugin/references.py:3:1: F401 'sublime_plugin' imported but unused ./plugin/rename.py:1:1: F401 'sublime_plugin' imported but unused ./plugin/symbols.py:1:1: F401 'sublime_plugin' imported but unused commit 31f435c Author: evandrocoan <evandrocoan@hotmail.com> Date: Tue Jan 30 20:26:02 2018 -0200 Hide Context.sublime-menu when working on projects without language servers
Summary
When you do these
if issubclass(t, TextCommand)
,if issubclass(t, WindowCommand)
, etc. You also add the base classLspTextCommand
from an inheritance chain like this:So far no problems. But if the base class
LspTextCommand
defines a different constructor interface like:And as Sublime Text added this base class
LspTextCommand
totext_command_classes
, it will cause this other line:To throw a nice error:
Therefore, Sublime Text should not add base classes to its internal
text_command_classes
variable.Expected behavior
This will also fix: #2066 Commands are not propagated when any TextCommand with invalid init signature is defined
On this commit, I push an example of this bug:
Environment
dpi_scale
used in ST 1.0The text was updated successfully, but these errors were encountered: