diff options
author | Bénédikt Tran <10796600+picnixz@users.noreply.github.com> | 2024-06-17 13:51:03 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-06-17 13:51:03 (GMT) |
commit | 4bf17c381fb7b465f0f26aecb94a6c54cf9be2d3 (patch) | |
tree | 3c049d8479d282b311584e98231de25372675714 /Doc/library/symtable.rst | |
parent | 274f844830898355f14d6edb6e71894a2f37e53c (diff) | |
download | cpython-4bf17c381fb7b465f0f26aecb94a6c54cf9be2d3.zip cpython-4bf17c381fb7b465f0f26aecb94a6c54cf9be2d3.tar.gz cpython-4bf17c381fb7b465f0f26aecb94a6c54cf9be2d3.tar.bz2 |
gh-119933: Improve ``SyntaxError`` message for invalid type parameters expressions (#119976)
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
Diffstat (limited to 'Doc/library/symtable.rst')
-rw-r--r-- | Doc/library/symtable.rst | 61 |
1 files changed, 57 insertions, 4 deletions
diff --git a/Doc/library/symtable.rst b/Doc/library/symtable.rst index 050a941..a332637 100644 --- a/Doc/library/symtable.rst +++ b/Doc/library/symtable.rst @@ -31,21 +31,74 @@ Generating Symbol Tables Examining Symbol Tables ----------------------- +.. class:: SymbolTableType + + An enumeration indicating the type of a :class:`SymbolTable` object. + + .. attribute:: MODULE + :value: "module" + + Used for the symbol table of a module. + + .. attribute:: FUNCTION + :value: "function" + + Used for the symbol table of a function. + + .. attribute:: CLASS + :value: "class" + + Used for the symbol table of a class. + + The following members refer to different flavors of + :ref:`annotation scopes <annotation-scopes>`. + + .. attribute:: ANNOTATION + :value: "annotation" + + Used for annotations if ``from __future__ import annotations`` is active. + + .. attribute:: TYPE_ALIAS + :value: "type alias" + + Used for the symbol table of :keyword:`type` constructions. + + .. attribute:: TYPE_PARAMETERS + :value: "type parameters" + + Used for the symbol table of :ref:`generic functions <generic-functions>` + or :ref:`generic classes <generic-classes>`. + + .. attribute:: TYPE_VARIABLE + :value: "type variable" + + Used for the symbol table of the bound, the constraint tuple or the + default value of a single type variable in the formal sense, i.e., + a TypeVar, a TypeVarTuple or a ParamSpec object (the latter two do + not support a bound or a constraint tuple). + + .. versionadded:: 3.13 + .. class:: SymbolTable A namespace table for a block. The constructor is not public. .. method:: get_type() - Return the type of the symbol table. Possible values are ``'class'``, - ``'module'``, ``'function'``, ``'annotation'``, ``'TypeVar bound'``, - ``'type alias'``, and ``'type parameter'``. The latter four refer to - different flavors of :ref:`annotation scopes <annotation-scopes>`. + Return the type of the symbol table. Possible values are members + of the :class:`SymbolTableType` enumeration. .. versionchanged:: 3.12 Added ``'annotation'``, ``'TypeVar bound'``, ``'type alias'``, and ``'type parameter'`` as possible return values. + .. versionchanged:: 3.13 + Return values are members of the :class:`SymbolTableType` enumeration. + + The exact values of the returned string may change in the future, + and thus, it is recommended to use :class:`SymbolTableType` members + instead of hard-coded strings. + .. method:: get_id() Return the table's identifier. |