summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_tokenize.py
Commit message (Collapse)AuthorAgeFilesLines
* gh-115154: Fix untokenize handling of unicode named literals (#115171)Pablo Galindo Salgado2024-02-191-3/+37
|
* gh-112943: Correctly compute end offsets for multiline tokens in the ↵Pablo Galindo Salgado2023-12-111-0/+10
| | | | tokenize module (#112949)
* gh-111031: Check more files in `test_tokenize` (#111032)Nikita Sobolev2023-10-191-10/+0
|
* gh-104169: Fix test_peg_generator after tokenizer refactoring (#110727)Lysandros Nikolaou2023-10-121-2/+2
| | | | * Fix test_peg_generator after tokenizer refactoring * Remove references to tokenizer.c in comments etc.
* gh-108303: Move all inspect test files to `test_inspect/` (#109607)Nikita Sobolev2023-10-101-1/+1
|
* gh-110259: Fix f-strings with multiline expressions and format specs (#110271)Pablo Galindo Salgado2023-10-051-0/+97
| | | Signed-off-by: Pablo Galindo <pablogsal@gmail.com>
* gh-108303: Move tokenize-related data to Lib/test/tokenizedata (GH-109265)Nikita Sobolev2023-09-121-4/+3
|
* gh-108469: Update ast.unparse for unescaped quote support from PEP701 [3.12] ↵Anthony Shaw2023-09-051-1/+1
| | | | | | (#108553) Co-authored-by: sunmy2019 <59365878+sunmy2019@users.noreply.github.com>
* gh-107015: Remove async_hacks from the tokenizer (#107018)Pablo Galindo Salgado2023-07-261-34/+34
|
* gh-106200: Remove unused imports (#106201)Nikita Sobolev2023-06-281-1/+0
|
* gh-71299: Fix __all__ in tokenize (#105907)Lysandros Nikolaou2023-06-191-132/+136
| | | Co-authored-by: Unit03
* gh-105820: Fix tok_mode expression buffer in file & readline tokenizer (#105828)Lysandros Nikolaou2023-06-151-0/+13
|
* gh-105718: Fix buffer allocation in tokenizer with readline (#105728)Lysandros Nikolaou2023-06-131-0/+10
|
* gh-105549: Tokenize separately NUMBER and NAME tokens and allow 0-prefixed ↵Pablo Galindo Salgado2023-06-091-0/+33
| | | | literals (#105555)
* gh-105564: Don't include artificial newlines in the line attribute of tokens ↵Pablo Galindo Salgado2023-06-091-8/+8
| | | | (#105565)
* gh-105435: Fix spurious NEWLINE token if file ends with comment without a ↵Pablo Galindo Salgado2023-06-071-5/+26
| | | | newline (#105442)
* gh-105390: Correctly raise TokenError instead of SyntaxError for tokenize ↵Pablo Galindo Salgado2023-06-071-5/+6
| | | | errors (#105399)
* gh-105259: Ensure we don't show newline characters for trailing NEWLINE ↵Pablo Galindo Salgado2023-06-061-1/+1
| | | | tokens (#105364)
* gh-105042: Disable unmatched parens syntax error in python tokenize (#105061)Lysandros Nikolaou2023-05-301-0/+7
|
* gh-105069: Add a readline-like callable to the tokenizer to consume input ↵Pablo Galindo Salgado2023-05-301-49/+96
| | | | iteratively (#105070)
* gh-105017: Include CRLF lines in strings and column numbers (#105030)Marta Gómez Macías2023-05-281-8/+36
| | | Co-authored-by: Pablo Galindo <pablogsal@gmail.com>
* gh-105017: Fix including additional NL token when using CRLF (#105022)Marta Gómez Macías2023-05-271-0/+8
| | | | Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
* gh-104976: Ensure trailing dedent tokens are emitted as the previous ↵Pablo Galindo Salgado2023-05-261-7/+8
| | | | | tokenizer (#104980) Signed-off-by: Pablo Galindo <pablogsal@gmail.com>
* gh-104972: Ensure that line attributes in tokens in the tokenize module are ↵Pablo Galindo Salgado2023-05-261-2/+13
| | | | correct (#104975)
* gh-104866: Tokenize should emit NEWLINE after exiting block with comment ↵Lysandros Nikolaou2023-05-241-0/+17
| | | | (#104870)
* gh-104825: Remove implicit newline in the line attribute in tokens emitted ↵Pablo Galindo Salgado2023-05-241-2/+2
| | | | in the tokenize module (#104846)
* gh-104741: Add line number attribute to indentation error exception (#104743)Marta Gómez Macías2023-05-221-1/+10
|
* gh-102856: Python tokenizer implementation for PEP 701 (#104323)Marta Gómez Macías2023-05-211-48/+135
| | | | | | | | | | | This commit replaces the Python implementation of the tokenize module with an implementation that reuses the real C tokenizer via a private extension module. The tokenize module now implements a compatibility layer that transforms tokens from the C tokenizer into Python tokenize tokens for backward compatibility. As the C tokenizer does not emit some tokens that the Python tokenizer provides (such as comments and non-semantic newlines), a new special mode has been added to the C tokenizer mode that currently is only used via the extension module that exposes it to the Python layer. This new mode forces the C tokenizer to emit these new extra tokens and add the appropriate metadata that is needed to match the old Python implementation. Co-authored-by: Pablo Galindo <pablogsal@gmail.com>
* gh-103824: fix use-after-free error in Parser/tokenizer.c (#103993)chgnrdv2023-05-011-1/+14
|
* gh-102856: Initial implementation of PEP 701 (#102855)Pablo Galindo Salgado2023-04-191-5/+23
| | | | | | Co-authored-by: Lysandros Nikolaou <lisandrosnik@gmail.com> Co-authored-by: Batuhan Taskaya <isidentical@gmail.com> Co-authored-by: Marta Gómez Macías <mgmacias@google.com> Co-authored-by: sunmy2019 <59365878+sunmy2019@users.noreply.github.com>
* gh-99581: Fix a buffer overflow in the tokenizer when copying lines that ↵Pablo Galindo Salgado2022-11-201-0/+16
| | | | fill the available buffer (#99605)
* gh-94808: Coverage: Test that maximum indentation level is handled (#95926)Michael Droettboom2022-10-061-1/+21
| | | | | * gh-94808: Coverage: Test that maximum indentation level is handled * Use "compile" rather than "exec"
* Remove trailing spaces (GH-31695)Serhiy Storchaka2022-03-051-5/+5
|
* bpo-46091: Correctly calculate indentation levels for whitespace lines with ↵Pablo Galindo Salgado2022-01-251-1/+99
| | | | continuation characters (GH-30130)
* Remove trailing spaces. (GH-28706)Serhiy Storchaka2021-10-031-1/+1
|
* Add tests for the C tokenizer and expose it as a private module (GH-27924)Pablo Galindo Salgado2021-08-241-2/+861
|
* bpo-44667: Treat correctly lines ending with comments and no newlines in the ↵Pablo Galindo Salgado2021-07-311-0/+10
| | | | Python tokenizer (GH-27499)
* bpo-40275: Use new test.support helper submodules in tests (GH-21448)Hai Shi2020-08-031-2/+3
|
* bpo-41043: Escape literal part of the path for glob(). (GH-20994)Serhiy Storchaka2020-06-201-1/+1
|
* bpo-35224: PEP 572 Implementation (#10497)Emily Morehouse2019-01-241-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Add tokenization of := - Add token to Include/token.h. Add token to documentation in Doc/library/token.rst. - Run `./python Lib/token.py` to regenerate Lib/token.py. - Update Parser/tokenizer.c: add case to handle `:=`. * Add initial usage of := in grammar. * Update Python.asdl to match the grammar updates. Regenerated Include/Python-ast.h and Python/Python-ast.c * Update AST and compiler files in Python/ast.c and Python/compile.c. Basic functionality, this isn't scoped properly * Regenerate Lib/symbol.py using `./python Lib/symbol.py` * Tests - Fix failing tests in test_parser.py due to changes in token numbers for internal representation * Tests - Add simple test for := token * Tests - Add simple tests for named expressions using expr and suite * Tests - Update number of levels for nested expressions to prevent stack overflow * Update symbol table to handle NamedExpr * Update Grammar to allow assignment expressions in if statements. Regenerate Python/graminit.c accordingly using `make regen-grammar` * Tests - Add additional tests for named expressions in RoundtripLegalSyntaxTestCase, based on examples and information directly from PEP 572 Note: failing tests are currently commented out (4 out of 24 tests currently fail) * Tests - Add temporary syntax test failure tests in test_parser.py Note: There is an outstanding TODO for this -- syntax tests need to be moved to a different file (presumably test_syntax.py), but this is covering what needs to be tested at the moment, and it's more convenient to run a single test for the time being * Add support for allowing assignment expressions as function argument annotations. Uncomment tests for these cases because they all pass now! * Tests - Move existing syntax tests out of test_parser.py and into test_named_expressions.py. Refactor syntax tests to use unittest * Add TargetScopeError exception to extend SyntaxError Note: This simply creates the TargetScopeError exception, it is not yet used anywhere * Tests - Update tests per PEP 572 Continue refactoring test suite: The named expression test suite now checks for any invalid cases that throw exceptions (no longer limited to SyntaxErrors), assignment tests to ensure that variables are properly assigned, and scope tests to ensure that variable availability and values are correct Note: - There are still tests that are marked to skip, as they are not yet implemented - There are approximately 300 lines of the PEP that have not yet been addressed, though these may be deferred * Documentation - Small updates to XXX/todo comments - Remove XXX from child description in ast.c - Add comment with number of previously supported nested expressions for 3.7.X in test_parser.py * Fix assert in seq_for_testlist() * Cleanup - Denote "Not implemented -- No keyword args" on failing test case. Fix PEP8 error for blank lines at beginning of test classes in test_parser.py * Tests - Wrap all file opens in `with...as` to ensure files are closed * WIP: handle f(a := 1) * Tests and Cleanup - No longer skips keyword arg test. Keyword arg test now uses a simpler test case and does not rely on an external file. Remove print statements from ast.c * Tests - Refactor last remaining test case that relied on on external file to use a simpler test case without the dependency * Tests - Add better description of remaning skipped tests. Add test checking scope when using assignment expression in a function argument * Tests - Add test for nested comprehension, testing value and scope. Fix variable name in skipped comprehension scope test * Handle restriction of LHS for named expressions - can only assign to LHS of type NAME. Specifically, restrict assignment to tuples This adds an alternative set_context specifically for named expressions, set_namedexpr_context. Thus, context is now set differently for standard assignment versus assignment for named expressions in order to handle restrictions. * Tests - Update negative test case for assigning to lambda to match new error message. Add negative test case for assigning to tuple * Tests - Reorder test cases to group invalid syntax cases and named assignment target errors * Tests - Update test case for named expression in function argument - check that result and variable are set correctly * Todo - Add todo for TargetScopeError based on Guido's comment (https://github.com/python/cpython/commit/2b3acd37bdfc2d35e5094228c6684050d2aa8b0a#r30472562) * Tests - Add named expression tests for assignment operator in function arguments Note: One of two tests are skipped, as function arguments are currently treating an assignment expression inside of parenthesis as one child, which does not properly catch the named expression, nor does it count arguments properly * Add NamedStore to expr_context. Regenerate related code with `make regen-ast` * Add usage of NamedStore to ast_for_named_expr in ast.c. Update occurances of checking for Store to also handle NamedStore where appropriate * Add ste_comprehension to _symtable_entry to track if the namespace is a comprehension. Initialize ste_comprehension to 0. Set set_comprehension to 1 in symtable_handle_comprehension * s/symtable_add_def/symtable_add_def_helper. Add symtable_add_def to handle grabbing st->st_cur and passing it to symtable_add_def_helper. This now allows us to call the original code from symtable_add_def by instead calling symtable_add_def_helper with a different ste. * Refactor symtable_record_directive to take lineno and col_offset as arguments instead of stmt_ty. This allows symtable_record_directive to be used for stmt_ty and expr_ty * Handle elevating scope for named expressions in comprehensions. * Handle error for usage of named expression inside a class block * Tests - No longer skip scope tests. Add additional scope tests * Cleanup - Update error message for named expression within a comprehension within a class. Update comments. Add assert for symtable_extend_namedexpr_scope to validate that we always find at least a ModuleScope if we don't find a Class or FunctionScope * Cleanup - Add missing case for NamedStore in expr_context_name. Remove unused var in set_namedexpr_content * Refactor - Consolidate set_context and set_namedexpr_context to reduce duplicated code. Special cases for named expressions are handled by checking if ctx is NamedStore * Cleanup - Add additional use cases for ast_for_namedexpr in usage comment. Fix multiple blank lines in test_named_expressions * Tests - Remove unnecessary test case. Renumber test case function names * Remove TargetScopeError for now. Will add back if needed * Cleanup - Small comment nit for consistency * Handle positional argument check with named expression * Add TargetScopeError exception definition. Add documentation for TargetScopeError in c-api docs. Throw TargetScopeError instead of SyntaxError when using a named expression in a comprehension within a class scope * Increase stack size for parser by 200. This is a minimal change (approx. 5kb) and should not have an impact on any systems. Update parser test to allow 99 nested levels again * Add TargetScopeError to exception_hierarchy.txt for test_baseexception.py_ * Tests - Major update for named expression tests, both in test_named_expressions and test_parser - Add test for TargetScopeError - Add tests for named expressions in comprehension scope and edge cases - Add tests for named expressions in function arguments (declarations and call sites) - Reorganize tests to group them more logically * Cleanup - Remove unnecessary comment * Cleanup - Comment nitpicks * Explicitly disallow assignment expressions to a name inside parentheses, e.g.: ((x) := 0) - Add check for LHS types to detect a parenthesis then a name (see note) - Add test for this scenario - Update tests for changed error message for named assignment to a tuple (also, see note) Note: This caused issues with the previous error handling for named assignment to a LHS that contained an expression, such as a tuple. Thus, the check for the LHS of a named expression must be changed to be more specific if we wish to maintain the previous error messages * Cleanup - Wrap lines more strictly in test file * Revert "Explicitly disallow assignment expressions to a name inside parentheses, e.g.: ((x) := 0)" This reverts commit f1531400ca7d7a2d148830c8ac703f041740896d. * Add NEWS.d entry * Tests - Fix error in test_pickle.test_exceptions by adding TargetScopeError to list of exceptions * Tests - Update error message tests to reflect improved messaging convention (s/can't/cannot) * Remove cases that cannot be reached in compile.c. Small linting update. * Update Grammar/Tokens to add COLONEQUAL. Regenerate all files * Update TargetScopeError PRE_INIT and POST_INIT, as this was purposefully left out when fixing rebase conflicts * Add NamedStore back and regenerate files * Pass along line number and end col info for named expression * Simplify News entry * Fix compiler warning and explicity mark fallthrough
* bpo-30455: Generate all token related code and docs from Grammar/Tokens. ↵Serhiy Storchaka2018-12-221-0/+2
| | | | | | | | | | | | | | | | | | | (GH-10370) "Include/token.h", "Lib/token.py" (containing now some data moved from "Lib/tokenize.py") and new files "Parser/token.c" (containing the code moved from "Parser/tokenizer.c") and "Doc/library/token-list.inc" (included in "Doc/library/token.rst") are now generated from "Grammar/Tokens" by "Tools/scripts/generate_token.py". The script overwrites files only if needed and can be used on the read-only sources tree. "Lib/symbol.py" is now generated by "Tools/scripts/generate_symbol_py.py" instead of been executable itself. Added new make targets "regen-token" and "regen-symbol" which are now dependencies of "regen-all". The documentation contains now strings for operators and punctuation tokens.
* Fixed several assertTrue() that were intended to be assertEqual(). (GH-8191)Sergey Fedoseev2018-07-091-1/+1
| | | Fixed also testing the "always" warning filter.
* bpo-33899: Make tokenize module mirror end-of-file is end-of-line behavior ↵Ammar Askar2018-07-061-24/+47
| | | | | | | | | (GH-7891) Most of the change involves fixing up the test suite, which previously made the assumption that there wouldn't be a new line if the input didn't end in one. Contributed by Ammar Askar.
* bpo-12486: Document tokenize.generate_tokens() as public API (#6957)Thomas Kluyver2018-06-051-2/+15
| | | | | | | | | | | | * Document tokenize.generate_tokens() * Add news file * Add test for generate_tokens * Document behaviour around ENCODING token * Add generate_tokens to __all__
* bpo-30406: Make async and await proper keywords (#1669)Jelle Zijlstra2017-10-061-14/+14
| | | Per PEP 492, 'async' and 'await' should become proper keywords in 3.7.
* bpo-31029: test_tokenize Add missing import unittest (#2865)Stéphane Wirtel2017-07-251-0/+1
|
* bpo-25324: copy tok_name before changing it (#1608)Albert-Jan Nijburg2017-05-311-6/+6
| | | | | | | | | | | | | | | | | | | | | | | | * add test to check if were modifying token * copy list so import tokenize doesnt have side effects on token * shorten line * add tokenize tokens to token.h to get them to show up in token * move ERRORTOKEN back to its previous location, and fix nitpick * copy comments from token.h automatically * fix whitespace and make more pythonic * change to fix comments from @haypo * update token.rst and Misc/NEWS * change wording * some more wording changes
* bpo-30377: Simplify handling of COMMENT and NL in tokenize.py (#1607)Albert-Jan Nijburg2017-05-241-7/+9
|
* Add ELLIPSIS and RARROW. Add tests (#666)Jim Fasarakis-Hilliard2017-03-141-0/+21
|
* Issue #26331: Implement the parsing part of PEP 515.Brett Cannon2016-09-091-7/+23
| | | | Thanks to Georg Brandl for the patch.