.. _python-language-reference: Python Language Reference Coverage ================================== This is a 1:1 mapping of the features listed in https://docs.python.org/3/reference/ and their support in TorchScript. The categorizations are as follows: .. list-table:: :header-rows: 1 * - Section - Status - Note * - `1. Introduction `_ - Not Relevant - * - `1.1. Alternate Implementations `_ - Not Relevant - * - `1.2. Notation `_ - Not Relevant - * - `2. Lexical analysis `_ - Not Relevant - * - `2.1. Line structure `_ - Not Relevant - * - `2.1.1. Logical lines `_ - Not Relevant - * - `2.1.2. Physical lines `_ - Supported - * - `2.1.3. Comments `_ - Supported - * - `2.1.4. Encoding declarations `_ - Not Supported - TorchScript explicitly don't support unicode * - `2.1.5. Explicit line joining `_ - Supported - * - `2.1.6. Implicit line joining `_ - Supported - * - `2.1.7. Blank lines `_ - Supported - * - `2.1.8. Indentation `_ - Supported - * - `2.1.9. Whitespace between tokens `_ - Not Relevant - * - `2.2. Other tokens `_ - Not Relevant - * - `2.3. Identifiers and keywords `_ - Supported - * - `2.3.1. Keywords `_ - Supported - * - `2.3.2. Reserved classes of identifiers `_ - Supported - * - `2.4. Literals `_ - Not Relevant - * - `2.4.1. String and Bytes literals `_ - Supported - * - `2.4.2. String literal concatenation `_ - Supported - * - `2.4.3. Formatted string literals `_ - Partially Supported - * - `2.4.4. Numeric literals `_ - Supported - * - `2.4.5. Integer literals `_ - Supported - * - `2.4.6. Floating point literals `_ - Supported - * - `2.4.7. Imaginary literals `_ - Not Supported - * - `2.5. Operators `_ - Partially Supported - Not supported: ``<<``, ``>>``, ``:=`` * - `2.6. Delimiters `_ - Partially Supported - Not supported: ``**=``, ``<<=``, ``>>=``, ``%=``, ``^=``, ``@=``, ``&=``, ``//=``, ``%`` operator for some types (e.g. ``str``\ ) * - `3. Data model `_ - Not Relevant - * - `3.1. Objects, values and types `_ - Not Relevant - * - `3.2. The standard type hierarchy `_ - Partially Supported - Not supported: NotImplemented, Ellipsis, numbers.Complex, bytes, byte arrays, sets, frozen sets, generators, coroutines, async generators, modules, I/O objects, internal objects, slice objects ( though slicing is supported), classmethod * - `3.3. Special method names `_ - Supported - * - `3.3.1. Basic customization `_ - Partially Supported - Not supported: ``__new__`` , ``__del__`` , ``__bytes__`` , ``__format__`` , ``__hash__`` , * - `3.3.2. Customizing attribute access `_ - Not Supported - * - `3.3.2.1. Customizing module attribute access `_ - Not Supported - * - `3.3.2.2. Implementing Descriptors `_ - Not Supported - * - `3.3.2.3. Invoking Descriptors `_ - Not Supported - * - `3.3.2.4. __slots__ `_ - Not Supported - * - `3.3.2.4.1. Notes on using __slots__ `_ - Not Supported - * - `3.3.3. Customizing class creation `_ - Not Supported - * - `3.3.3.1. Metaclasses `_ - Not Supported - * - `3.3.3.2. Resolving MRO entries `_ - Not Supported - ``super()`` is not supported * - `3.3.3.3. Determining the appropriate metaclass `_ - Not relevant - * - `3.3.3.4. Preparing the class namespace `_ - Not relevant - * - `3.3.3.5. Executing the class body `_ - Not relevant - * - `3.3.3.6. Creating the class object `_ - Not relevant - * - `3.3.3.7. Uses for metaclasses `_ - Not relevant - * - `3.3.4. Customizing instance and subclass checks `_ - Not Supported - * - `3.3.5. Emulating generic types `_ - Not Supported - * - `3.3.6. Emulating callable objects `_ - Supported - * - `3.3.7. Emulating container types `_ - Partially Supported - Some magic methods not supported (e.g. ``__iter__`` ) * - `3.3.8. Emulating numeric types `_ - Partially Supported - Magic methods with swapped operands not supported (``__r*__``) * - `3.3.9. With Statement Context Managers `_ - Not Supported - * - `3.3.10. Special method lookup `_ - Not relevant - * - `3.4. Coroutines `_ - Not Supported - * - `3.4.1. Awaitable Objects `_ - Not Supported - * - `3.4.2. Coroutine Objects `_ - Not Supported - * - `3.4.3. Asynchronous Iterators `_ - Not Supported - * - `3.4.4. Asynchronous Context Managers `_ - Not Supported - * - `4. Execution model `_ - Not Relevant - * - `4.1. Structure of a program `_ - Not Relevant - * - `4.2. Naming and binding `_ - Not Relevant - Names are bound at compile time in TorchScript * - `4.2.1. Binding of names `_ - Not Relevant - See ``global`` and ``nonlocal`` statements section * - `4.2.2. Resolution of names `_ - Not Relevant - See ``global`` and ``nonlocal`` statements section * - `4.2.3. Builtins and restricted execution `_ - Not Relevant - * - `4.2.4. Interaction with dynamic features `_ - Not Supported - Python values cannot be captured * - `4.3. Exceptions `_ - Partially Supported - See ``try`` and ``raise`` statement section * - `5. The import system `_ - Not Relevant - * - `6. Expressions `_ - Not Relevant - See expressions section * - `6.1. Arithmetic conversions `_ - Supported - * - `6.2. Atoms `_ - Not Relevant - * - `6.2.1. Identifiers (Names) `_ - Supported - * - `6.2.2. Literals `_ - Partially Supported - ``bytesliteral``\ , ``imagnumber`` not supported * - `6.2.3. Parenthesized forms `_ - Supported - * - `6.2.4. Displays for lists, sets and dictionaries `_ - Partially Supported - Not supported: comprehension ifs, async iterators * - `6.2.5. List displays `_ - Supported - * - `6.2.6. Set displays `_ - Not Supported - * - `6.2.7. Dictionary displays `_ - Supported - dict() constructor with kwargs doesn't work, dict comprehensions, dictionary unpacking * - `6.2.8. Generator expressions `_ - Not Supported - * - `6.2.9. Yield expressions `_ - Not Supported - * - `6.2.9.1. Generator-iterator methods `_ - Not Supported - * - `6.2.9.2. Examples `_ - Not Supported - * - `6.2.9.3. Asynchronous generator functions `_ - Not Supported - * - `6.2.9.4. Asynchronous generator-iterator methods `_ - Not Supported - * - `6.3. Primaries `_ - Supported - * - `6.3.1. Attribute references `_ - Supported - * - `6.3.2. Subscriptions `_ - Supported - * - `6.3.3. Slicings `_ - Partially Supported - Tuple slicing with stride is not supported * - `6.3.4. Calls `_ - Partially Supported - Args unpack / kwargs unpack is not supported * - `6.4. Await expression `_ - Not Supported - * - `6.5. The power operator `_ - Supported - * - `6.6. Unary arithmetic and bitwise operations `_ - Partially Supported - Some bitwise operators are not implemented for primitive types (e.g. ``~x`` where ``x`` is an ``int`` is not currently supported) * - `6.7. Binary arithmetic operations `_ - Partially Supported - See delimiters section * - `6.8. Shifting operations `_ - Not Supported - * - `6.9. Binary bitwise operations `_ - Supported - * - `6.10. Comparisons `_ - Supported - * - `6.10.1. Value comparisons `_ - Partially Supported - Dictionary equality checks are not currently supported * - `6.10.2. Membership test operations `_ - Partially Supported - Not supported for TorchScript classes * - `6.10.3. Identity comparisons `_ - Supported - * - `6.11. Boolean operations `_ - Supported - * - `6.12. Conditional expressions `_ - Supported - * - `6.13. Lambdas `_ - Not Supported - * - `6.14. Expression lists `_ - Partially Supported - Iterable unpacking not supported * - `6.15. Evaluation order `_ - Supported - * - `6.16. Operator precedence `_ - Supported - * - `7. Simple statements `_ - Supported - * - `7.1. Expression statements `_ - Supported - * - `7.2. Assignment statements `_ - Supported - * - `7.2.1. Augmented assignment statements `_ - Partially Supported - See delimiters section * - `7.2.2. Annotated assignment statements `_ - Supported - * - `7.3. The assert statement `_ - Partially Supported - Exception message is not customizable * - `7.4. The pass statement `_ - Supported - * - `7.5. The del statement `_ - Not Supported - * - `7.6. The return statement `_ - Supported - Some other features of returning (e.g. behavior with try..finally) are unsupported * - `7.7. The yield statement `_ - Not Supported - * - `7.8. The raise statement `_ - Partially Supported - Exception message is not customizable * - `7.9. The break statement `_ - Supported - Some other features of returning (e.g. behavior with try..finally) are unsupported * - `7.10. The continue statement `_ - Supported - Some other features of returning (e.g. behavior with try..finally) are unsupported * - `7.11. The import statement `_ - Not Supported - * - `7.11.1. Future statements `_ - Not Supported - * - `7.12. The global statement `_ - Not Supported - * - `7.13. The nonlocal statement `_ - Not Supported - * - `8. Compound statements `_ - Irrelevant - * - `8.1. The if statement `_ - Supported - * - `8.2. The while statement `_ - Partially Supported - while..else is not supported * - `8.3. The for statement `_ - Partially Supported - for..else is not supported * - `8.4. The try statement `_ - Not Supported - * - `8.5. The with statement `_ - Partially Supported - ``__exit__`` is always called with ``exc_type``, ``exc_value``, and ``traceback`` set to None, even if an exception was raised, and ``__exit__``'s return value is ignored. * - `8.6. Function definitions `_ - Not Supported - * - `8.7. Class definitions `_ - Not Supported - * - `8.8. Coroutines `_ - Not Supported - * - `8.8.1. Coroutine function definition `_ - Not Supported - * - `8.8.2. The async for statement `_ - Not Supported - * - `8.8.3. The async with statement `_ - Not Supported - * - `9. Top-level components `_ - Not Relevant - * - `9.1. Complete Python programs `_ - Not Relevant - * - `9.2. File input `_ - Not Relevant - * - `9.3. Interactive input `_ - Not Relevant - * - `9.4. Expression input `_ - Not Relevant -