Skip to content
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

Invalid character position -1 with flake8-annotations #615

Open
ketakopter opened this issue Jan 31, 2025 · 0 comments
Open

Invalid character position -1 with flake8-annotations #615

ketakopter opened this issue Jan 31, 2025 · 0 comments

Comments

@ketakopter
Copy link

Using flake8 with flake8-annotations plugin results in an invalid character position -1 in this simple snippet:

def myfun():
    # erg
    pass

The pylsp server returns the following response:

[jsonrpc] e[22:41:37.731] <-- textDocument/publishDiagnostics
{
  "jsonrpc": "2.0",
  "method": "textDocument/publishDiagnostics",
  "params": {
    "uri": "file:////tmp/hu.py",
    "diagnostics": [
      {
        "source": "flake8",
        "code": "ANN201",
        "range": {
          "start": {
            "line": 1,
            "character": -1
          },
          "end": {
            "line": 1,
            "character": 10
          }
        },
        "message": "ANN201 Missing return type annotation for public function",
        "severity": 2
      }
    ],
    "version": 126
  }
}

As you can see, the ANN201 error starts at character -1. I assume this is invalid, because my client (eglot in Emacs) complains about it.

The issue seems connected to the comment line. An empty line also has the same issue. A docstring line does not.

The python-lsp-server config that I'm using at Emacs:

;; (...)
  '((:pylsp . (:plugins (:mccabe (:enabled :json-false)
                                 :pycodestyle (:enabled :json-false)
                                 :pyflakes (:enabled :json-false)
                                 :flake8 (:enabled t)
                                 )
                        :configurationSources ["flake8"])))

As said, flake8 and flake8-annotations are being used.

Using flake8 directly from CLI doesn't show anything weird, only ANN201 is reported.

> flake8 hu.py
hu.py:2:0: ANN201 Missing return type annotation for public function

Versions:

python-lsp-jsonrpc 1.1.2
python-lsp-server 1.12.0
flake8 7.1.1
flake8-annotations 3.1.1

Honestly I don't know where the source of the problem is, if the LSP server or flake8-annotations or somewhere else.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant