1

I have python code that uses __getattr__ to relay non existing member accesses to another object.

I have written a Mypy plugin which makes the type hints work.

class StrProxy(Proxy[str])
    s: str

    def __init__(self, s: str):
        self.s = s

    def get(self) -> str:
        return self.s

    def __deref__(self) -> str:
        return s

sp = StrProxy("test")
sp.get # exists according to mypy & pylance
sp.encode # exists according to mypy only (because of my plugin)

The problem: Pylance uses its own type checker (Pyright) for autocomplete.

Is there any way I can tell Pylance to use Mypy? Or switch pylance for an LSP that respects Mypy?

5
  • Language server (autocomplete) != typechecker. Langserver offers results of type checking to you, but not other way around: autocomplete stays separate. Please clarify your intent: do you want to see results of mypy typechecking instead of pyright warnings or to make some attributes shown in the autocomplete prompt? There should be such plugin for all major IDEs for the former, and the latter is impossible (mypy does simply not offer such functionality, neither pyright does). Commented Jan 9, 2024 at 18:51
  • @STerliakov like I said, I want pylance to use Mypy instead of Pyright. Which means I want to see the results of mypy's checks in the autocomplete - the first option you mentioned. I couldn't find any way to do that myself. Commented Jan 10, 2024 at 19:08
  • Again, neither mypy nor pyright provide autocomplete suggestions - it's a job of another component. Do you want to see errors display (warnings by mypy or pyright) or autocomplete? The former is just a matter of installing mypy plugin, probably (you may start here), and the latter is just impossible by design. Commented Jan 10, 2024 at 23:31
  • @STerliakov let me ask - because that might be the root of my misunderstanding - when pylance wants to autocomplete an attribute name, does it not get the attribute list via Pyright? If it doesn't, then how? Commented Jan 11, 2024 at 10:21
  • 1
    Unfortunately, Pylance is closed-source (so I don't use it and can hardly reason about the internals). To learn the how you'd need access to its source. Pyright is more than type checker, it provides more options (github.com/microsoft/pyright/tree/main/packages/…), including langserver. Mypy is definitely only a type checker and does not emit anything related to IDE autocomplete. Consult the LSP "standard" for some more details (mypy does not follow it) Commented Jan 11, 2024 at 13:51

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.