all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#71797: 30.0.60; Face of variables and function parameters in Python
@ 2024-06-27 14:04 Stephen Berman via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2024-06-28  1:01 ` Dmitry Gutov
  0 siblings, 1 reply; 2+ messages in thread
From: Stephen Berman via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2024-06-27 14:04 UTC (permalink / raw)
  To: 71797

[-- 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

^ permalink raw reply	[flat|nested] 2+ messages in thread

* bug#71797: 30.0.60; Face of variables and function parameters in Python
  2024-06-27 14:04 bug#71797: 30.0.60; Face of variables and function parameters in Python Stephen Berman via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2024-06-28  1:01 ` Dmitry Gutov
  0 siblings, 0 replies; 2+ messages in thread
From: Dmitry Gutov @ 2024-06-28  1:01 UTC (permalink / raw)
  To: Stephen Berman, 71797

On 27/06/2024 17:04, Stephen Berman via Bug reports for GNU Emacs, the 
Swiss army knife of text editors wrote:
> 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.

That seems all right: in all of these cases the variable is being 
introduced, aren't they?

python-mode doesn't have access to a parser of the same quality, so we 
shouldn't expect the exact same features.





^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-06-28  1:01 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-06-27 14:04 bug#71797: 30.0.60; Face of variables and function parameters in Python Stephen Berman via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-06-28  1:01 ` Dmitry Gutov

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.