diff options
author | Jelle Zijlstra <jelle.zijlstra@gmail.com> | 2024-06-17 15:01:49 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-06-17 15:01:49 (GMT) |
commit | 7c47f93dff878bdc43f5162dd878cbb375711570 (patch) | |
tree | 7b02b412d2bc0f718d9df2912fa0b6cd66205de1 /Doc | |
parent | 03b89e3a3d155a06827f58d51238a731d8800cc9 (diff) | |
download | cpython-7c47f93dff878bdc43f5162dd878cbb375711570.zip cpython-7c47f93dff878bdc43f5162dd878cbb375711570.tar.gz cpython-7c47f93dff878bdc43f5162dd878cbb375711570.tar.bz2 |
[3.13] gh-119933: Improve ``SyntaxError`` message for invalid type parameters expressions (GH-119976) (#120641)
(cherry picked from commit 4bf17c381fb7b465f0f26aecb94a6c54cf9be2d3)
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Diffstat (limited to 'Doc')
-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 0480502..cc10265 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. |