atom / language-python

Python package for Atom
Other
190 stars 146 forks source link

Adds new keywords for match statements #338

Open BekaValentine opened 2 years ago

BekaValentine commented 2 years ago

Description of the Change

This PR adds keywords for the new match statements that were added to Python 3.10.

It does so by making them instances of 'keyword.control.conditional.python'.

Alternate Designs

One alternative option would be to have a separate type for the match statement keywords, however, match statements are arguably a flavor of conditional statement. For example,

match xs:
    case []:
        ...
    case [x,y]:
        ....

is functionally the same as

if type(xs) == list and len(xs) == 0:
    ...
elif type(xs) == list and len(xs) == 2:
    [x,y] = xs
    ...

Benefits

Python 3.10 will highlight correctly in Atom.

Possible Drawbacks

Code for previous versions of Python could have erroneous highlighting.

Applicable Issues

(https://github.com/atom/language-python/issues/335)

BekaValentine commented 2 years ago

I don't know enough about the testing library to properly implement tests for this, unfortunately.

BekaValentine commented 2 years ago

@maxbrunsfeld would you be up for reviewing this?

Yang-Wei-Ting commented 2 years ago

I tried your patch and currently everything looks good to me. Except the print is highlighted as a keyword and built-in exception class is not highlighted.

Before: image

After: image

Note: I disabled the built-in language-python 0.53.6 package and cloned language-python master branch (HEAD=fd71825) with your patch applied under .atom/packages directory.