ST-API-stubs icon indicating copy to clipboard operation
ST-API-stubs copied to clipboard

type mismatch: base parameter is type "Any", override parameter is type "Any"

Open Serega124 opened this issue 3 years ago • 5 comments

When creating a new plugin with a text command and adding a type annotation to run() method, an error appears in the Diagnostics panel:

buffer://sublime/150:
    6:7   error   Method "run" overrides class "TextCommand" in an incompatible manner ​Pyright: reportIncompatibleMethodOverride 
                    Parameter 2 type mismatch: base parameter is type "Any", override parameter is type "Any"

code:

from typing import Any
import sublime_plugin


class ExampleCommand(sublime_plugin.TextCommand):
  def run(self, edit: Any):
    self.view.insert(edit, 0, "Hello, World!")

LSP-pyright 1.1.136

Serega124 avatar Feb 04 '22 03:02 Serega124

I can't reproduce this with your code. No matter it's a saved file or a buffer (from Tools > Developer > New Plugin). Though I don't think this issue comes from here.


Not the cause, but it should be edit: sublime.Edit.

jfcherng avatar Feb 04 '22 04:02 jfcherng

Tested on a clean portable Sublime Text (installed only LSP and LSP-pyright packages) - got the same error.

image

I know that it should be sublime.Edit, but I just tried to annotate it to the Any type so that all errors are gone, but instead I got a cryptic error saing type Any is incompatible with type Any. Maybe it's a pyright type checker issue?

Serega124 avatar Feb 04 '22 05:02 Serega124

Tested on a clean portable Sublime Text (installed only LSP and LSP-pyright packages) - got the same error.

Not reproduce-able.

https://user-images.githubusercontent.com/6594915/152478192-cdb4c348-5b72-4f93-9616-c9b1ee8d2418.mp4

jfcherng avatar Feb 04 '22 05:02 jfcherng

Sorry, I forgot to mention the setting "python.analysis.typeCheckingMode": "strict" that enables the reportIncompatibleMethodOverride rule.

Serega124 avatar Feb 04 '22 05:02 Serega124

Sorry, I forgot to mention the setting "python.analysis.typeCheckingMode": "strict" that enables the reportIncompatibleMethodOverride rule.

Yes, that's the reason. But I have no idea how to fix that unfortunately since run accepts literally any amount of any arguments, which I guess "strict" doesn't like.

class TextCommand(Command):
    run: Callable[..., None]

If someone comes up a solution, I am definitely welcome. Just open a pull request 😄

jfcherng avatar Feb 04 '22 05:02 jfcherng