From: Stephen Berman via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
To: 71797@debbugs.gnu.org
Subject: bug#71797: 30.0.60; Face of variables and function parameters in Python
Date: Thu, 27 Jun 2024 16:04:58 +0200 [thread overview]
Message-ID: <87v81uscqd.fsf@gmx.net> (raw)
[-- Attachment #1: Type: text/plain, Size: 2235 bytes --]
0. emacs -Q, where Emacs has been built with treesitter support and the
treesitter Python grammar library is installed.
1. Visit the attached file "test.py", which contains examples in Python
of variables and function parameters with type hints. The buffer is
now in the default (non-treesitter) python-mode.
2. Notice that the initialized annotated variable `age' and the
(unannotated) assigned to occurrences of `child' are fontified with
font-lock-variable-name-face, while the uninitialized annotated
variables `a' and `child' and the annotated function parameters
`num', `num1' and `num2' are displayed in the default face.
3. M-x python-ts-mode. Now the uninitialized `age', `a' and `child' as
well as the function parameters `num', `num1' and `num2' are all
fontified with font-lock-variable-name-face.
I don't know if this difference demonstrates a bug in python-mode or in
python-ts-mode, but I assume only one of them is right. I note that in
much online Python documentation variables in assignments or function
parameters (with or without type hints) are mostly not fontified
(e.g. in Python's own documentation and in
https://mypy.readthedocs.io/en/stable/cheat_sheet_py3.html, which is
where the examples in the attached file come from). On the other hand,
I note that python-ts-mode also fontifies function parameters that lack
type hints or default values with font-lock-variable-name-face (the
default python-mode does not).
In GNU Emacs 30.0.60 (build 3, x86_64-pc-linux-gnu, GTK+ Version
3.24.42, cairo version 1.18.0) of 2024-06-26 built on strobelfs
Repository revision: 1809f6a93efe0ab3ac0f62743c92bd90860ff3ea
Repository branch: emacs-30
Windowing system distributor 'The X.Org Foundation', version 11.0.12101013
System Description: Linux From Scratch r12.1-85
Configured using:
'configure -C 'CFLAGS=-Og -g3''
Configured features:
ACL CAIRO DBUS FREETYPE GIF GLIB GMP GNUTLS GPM GSETTINGS HARFBUZZ JPEG
LCMS2 LIBSYSTEMD LIBXML2 MODULES NATIVE_COMP NOTIFY INOTIFY PDUMPER PNG
RSVG SECCOMP SOUND SQLITE3 THREADS TIFF TOOLKIT_SCROLL_BARS TREE_SITTER
WEBP X11 XDBE XIM XINPUT2 XPM GTK3 ZLIB
Important settings:
value of $LANG: en_US.UTF-8
locale-coding-system: utf-8-unix
[-- Attachment #2: test.py --]
[-- Type: application/octet-stream, Size: 499 bytes --]
# This is how you declare the type of a variable
age: int = 1
# You don't need to initialize a variable to annotate it
a: int # Ok (no value at runtime until assigned)
# Doing so can be useful in conditional branches
child: bool
if age < 18:
child = True
else:
child = False
# This is how you annotate a function definition
def stringify(num: int) -> str:
return str(num)
# And here's how you specify multiple arguments
def plus(num1: int, num2: int) -> int:
return num1 + num2
next reply other threads:[~2024-06-27 14:04 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-27 14:04 Stephen Berman via Bug reports for GNU Emacs, the Swiss army knife of text editors [this message]
2024-06-28 1:01 ` bug#71797: 30.0.60; Face of variables and function parameters in Python Dmitry Gutov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87v81uscqd.fsf@gmx.net \
--to=bug-gnu-emacs@gnu.org \
--cc=71797@debbugs.gnu.org \
--cc=stephen.berman@gmx.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.