Bug 442012 - [python3] Keywords-only enforcement using `*,` partly breaks syntax highlighting
Summary: [python3] Keywords-only enforcement using `*,` partly breaks syntax highlighting
Status: CONFIRMED
Alias: None
Product: kdev-python
Classification: Developer tools
Component: Language support (show other bugs)
Version: 5.6.2
Platform: Neon Linux
: NOR normal
Target Milestone: ---
Assignee: Sven Brauch
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-09-04 19:56 UTC by geisserml
Modified: 2021-09-05 08:26 UTC (History)
3 users (show)

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments
With *, syntax (19.96 KB, image/png)
2021-09-04 19:56 UTC, geisserml
Details
Without `*,` syntax (19.60 KB, image/png)
2021-09-04 19:56 UTC, geisserml
Details

Note You need to log in before you can comment on or make changes to this bug.
Description geisserml 2021-09-04 19:56:06 UTC
Created attachment 141294 [details]
With *, syntax

SUMMARY

Since Python 3, one can enforce the use of keyword arguments in method definitions. This ensures that downstream code is proof against possible future changes to the order of positional arguments. All arguments from a `*,` onwards need to be preceeded with explicit keywords (cf. https://www.vegardstikbakke.com/python-keyword-only/).

However, this syntax seems to partly break KDevelop's Python syntax highlighting, with default arguments following the `*,` not being recognised/highlighted anymore.

Example:
```python3
import os

class Backend:
    AUTO = None

def run(
        info,
        tempdir,
        *,
        backend = Backend.AUTO,
        n_processes = os.cpu_count()+1,
        n_chunks = 1,
        scaling = 1,
        cache_name = 'cache',
        verbose = True,
    ):
    pass
```

STEPS TO REPRODUCE
1. Paste a Python code using the keyword-only enforcing `*,` into KDevelop, for instance the above example.
2. Save it as $SOME_FILENAME.py for syntax highlighting to get active.
3. Remove the `*,` and see how syntax highlighting changes

OBSERVED RESULT
Default arguments after `*,` are not highlighted. Without `*,` they are.

EXPECTED RESULT
Default arguments should always be highlighted correctly, regardless of whether there is a `*,` or not.

SOFTWARE/OS VERSIONS
Operating System: KDE neon 5.22
KDE Plasma Version: 5.22.5
KDE Frameworks Version: 5.85.0
Qt Version: 5.15.3
Kernel Version: 5.11.0-27-generic (64-bit)
Graphics Platform: Wayland

ADDITIONAL INFORMATION
Maybe this is rather a problem with KDevelop than with the syntax highlighting framework. If you think so, feel free to move the issue.
Comment 1 geisserml 2021-09-04 19:56:45 UTC
Created attachment 141295 [details]
Without `*,` syntax
Comment 2 geisserml 2021-09-04 20:03:21 UTC
At first I was a bit puzzled by this issue because stopping syntax highlighting first gave me the impression that there was a fault in my code.
Comment 3 Jan Paul Batrina 2021-09-05 02:56:54 UTC
Can confirm with KDevelop built from master and kdevelop-python 5.62 from the KDE Neon repos.

The highlighting of arguments, class, etc. are provided by kdevelop's python support plugin and the syntax-highlighting framework only provides basic syntax highlighting in this case (e.g. in Kate, only 1, `cache`, and True will be highlighted differently in the parameter list). Moved to kdev-python
Comment 4 Sven Brauch 2021-09-05 08:26:34 UTC
Yes, this is a kdevelop-python bug, I can also reproduce it.