summaryrefslogtreecommitdiff
path: root/pygments/lexers/python.py
Commit message (Collapse)AuthorAgeFilesLines
* Refactor PythonConsoleLexer as a DelegatingLexer (#2412)Jean Abou-Samra2023-04-171-62/+55
| | | | | This is simpler and more reliable than hand-coding the state machine. Fixes #2411
* Python console: do not require output that looks like a traceback to be ↵Georg Brandl2023-04-121-1/+2
| | | | valid (#2410)
* PythonTracebackLexer: minor tweak in docstringJean Abou Samra2023-04-121-1/+1
|
* Change token of None after from keywordrdbende2023-04-081-1/+1
|
* Update copyright year to 2023.Matthäus G. Chajdas2023-03-291-1/+1
|
* Add missing built-in functions for Python (#2334)P. Talley2023-02-121-10/+10
| | | callable and aiter.
* Python console: make traceback handling more robustGeorg Brandl2023-02-031-12/+12
| | | | | Fixes #2329 Fixes #2226
* Improve whitespace handling in Python.Matthäus G. Chajdas2022-12-111-20/+20
| | | | | | | | | This triggers a new case in the HtmlFormatter, which emits an empty span at the end of the line for a new line, as those are removed by the split-by-parts code. This requires separate post-processing. Doesn't fix all whitespace issues with Python either, but we're done to 360 failing examples with that, from previously >400.
* Improve whitespace handling in PythonTracebackLexer.Matthäus G. Chajdas2022-12-041-8/+8
|
* all: move often-used "line_re" to pygments.lexerGeorg Brandl2022-10-271-3/+1
|
* all: style fixesGeorg Brandl2022-10-271-1/+1
|
* Add `.pyi` file to `python` lexer filenames (#2231)Nikita Sobolev2022-09-151-0/+2
|
* Disable highlighting of some escape codes for python bytes literals (#2204)LaurenceWarne2022-08-151-7/+20
| | | | | | | | Disable highlighting of unicode escape codes in python bytes literals, as described in https://docs.python.org/3/reference/lexical_analysis.html#string-and-bytes-literals. So escape codes of the form "\N{name}", "\uxxxx" and "\Uxxxxxxxx" will no longer be highlighted within bytes literals. Add tests for escape code highlighting in string and bytes literals.
* Highlight python 3.10's EncodingWarning (#2106)Kevin Stock2022-04-061-1/+2
| | | EncodingWarning was added in 3.10: https://docs.python.org/3/library/exceptions.html#EncodingWarning
* Rework URL information in lexers.Matthäus G. Chajdas2022-03-201-4/+8
| | | | | | | | This commit adds a new url field to a lexer, which can be used to link to the language website, instead of relying on having the link in either languages.rst or the docstring of the lexer. Additionally, it changes the languages.rst file to auto-generate the list of lexers from the actual source code, using the provided URL.
* Remove now redundant re.UNICODE and (?u) (#2058)Jean Abou-Samra2022-01-311-3/+1
|
* Happy new year.Georg Brandl2022-01-251-1/+1
|
* Merge pull request #1994 from amitkummer/python-pattern-matchingMatthäus G. Chajdas2021-12-291-1/+17
|\ | | | | Python: lex soft keywords
| * Python: lex soft keywordsamitkummer2021-12-201-1/+17
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Some notes: - This approach is not perfect, but it's rather simple and I can't think of an edge case. - I did not use the `words` function to create the regex matching the keywords list, because it returns a capturing group (`()`) and it needs to be non-capturing here (because of `bygroups` usage). - I chose to go to the 'soft-keywords-inner' state after both `match` and `case`, even though it's unnecessary for `match` (the inner state catches the `_` wildcard keyword which appears only after a `case`). This is mostly harmless and saves us from writing the 'soft-keywords' regex twice each for `match` and `case` with the extra inner state just for `case`. The only piece of code this will lex incorrectly is `match _:` (`_` will be lexed as keyword). I doubt though that pattern mathcing will be used like this.
* | Update for new Python traceback locations (#2004)Jean-Abou-Samra2021-12-291-1/+1
|/ | | | Since https://github.com/python/cpython/pull/27037, they can include tildes in addition to the carets.
* Python: add "breakpoint" builtin.Georg Brandl2021-10-171-1/+1
| | | | Fixes #1918
* Support error locations in Python tracebacks (#1852)Jean-Abou-Samra2021-07-061-2/+16
| | | | | | | | | | Support both single carets for syntax errors (Python 2 and 3) and fine-grained error locations with several carets (Python 3.11+). Previously, the carets were highlighted as operators. This uses a new token, Token.Punctuation.Marker. For now, no style supports it specifically. In the future, styles might start differentiating it from Token.Punctuation. [Closes #1850.]
* Fix python lexer parsing floats incorrectly (#1768)Liam Stevens2021-04-101-1/+1
| | | | | | | | | * lexers: python: add test cases for floats * lexers: python: fix float lexing * lexer:python:fixed test syntax Co-authored-by: Aidan Do <giahuydo99@gmail.com>
* Fix #853.Matthäus G. Chajdas2021-03-051-2/+2
| | | | Add bint, Py_ssize_t.
* Run pyupgrade across codebase to modernize syntax and patterns (#1622)Jon Dufresne2021-01-171-1/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | pyupgrade is a tool to automatically upgrade syntax for newer versions of the Python language. The project has been Python 3 only since 35544e2fc6eed0ce4a27ec7285aac71ff0ddc473, allowing for several cleanups: - Remove unnecessary "-*- coding: utf-8 -*-" cookie. Python 3 reads all source files as utf-8 by default. - Replace IOError/EnvironmentError with OSError. Python 3 unified these exceptions. The old names are aliases only. - Use the Python 3 shorter super() syntax. - Remove "utf8" argument form encode/decode. In Python 3, this value is the default. - Remove "r" from open() calls. In Python 3, this value is the default. - Remove u prefix from Unicode strings. In Python 3, all strings are Unicode. - Replace io.open() with builtin open(). In Python 3, these functions are functionally equivalent. Co-authored-by: Matthäus G. Chajdas <Anteru@users.noreply.github.com>
* Fix for lexing Python raw f-strings with backslashes (#1683)Jeppe Dakin2021-01-171-5/+12
| | | | | | | | | * introduce and apply rfstringescape * add unit test for raw f-strings * add further tests * fix comment
* Make guessing prefer Python 3 lexerGeorg Brandl2021-01-171-5/+6
|
* Bump copyright year.Matthäus G. Chajdas2021-01-031-1/+1
|
* python traceback lexer: fix custom exceptions without messageGeorg Brandl2020-09-191-1/+1
| | | | fixes #1548
* all: remove "u" string prefix (#1536)Georg Brandl2020-09-081-6/+6
| | | | | | | | | | | * all: remove "u" string prefix * util: remove unirange Since Python 3.3, all builds are wide unicode compatible. * unistring: remove support for narrow-unicode builds which stopped being relevant with Python 3.3
* all: use yield from (#1537)Georg Brandl2020-09-061-6/+4
|
* all: fixup remaining regexlint warningsGeorg Brandl2020-09-061-5/+5
|
* Update copyright year (fixes #1514.)Matthäus G. Chajdas2020-08-221-1/+1
|
* Add async and await keywords (#1507)Marius Hegele2020-08-171-1/+1
|
* Python 3: remove "cmp" builtinGeorg Brandl2020-05-081-1/+1
| | | | fixes #1444
* Merge pull request #1385 from tomerv/python-fstringMatthäus G. Chajdas2020-02-291-15/+106
|\ | | | | Python f-strings: highlight expressions in curly braces
| * Python f-strings: highlight expressions in curly bracesTomer Vromen2020-02-041-15/+106
| | | | | | | | Fixes #1228
* | Move Python 3-only exceptions into Python3LexerБорис Верховский2020-02-261-3/+3
|/
* Adds the walrus operator to the Python3 lexer.Brett Slatkin2020-02-021-1/+1
| | | | | | | - The walrus operator, also known as assignment expressions, was introduced in Python 3.8 - Moves the Token.Operator matching root above Token.Punctuation so the walrus operator takes precedence - Includes a test to make sure this behavior doesn't regress since it's sensitive to the order of expressions - Fixes #1381
* Python: recognize "f" string prefixGeorg Brandl2019-11-261-8/+10
| | | | Fixes #1156
* Python: make Python3 rules standaloneGeorg Brandl2019-11-261-231/+303
| | | | | As the language develops further, having to override more and more of the Python 2 lexer tokens makes no sense anymore.
* Python: make "python" shebang match Python 3Georg Brandl2019-11-261-2/+2
|
* Update project to use modern Python features and idiomsJon Dufresne2019-11-251-2/+2
| | | | | | | | | | Run the pyupgrade tool across the project to use modern language features. - Use set literals - Use dict comprehension - Remove unnecessary numeric indexes in format string - Remove unnecessary extra parentheses
* Python lexer: accept .jy filenamesGeorg Brandl2019-11-241-0/+2
| | | | Fixes #976
* Python lexers: make Python 3 the defaultGeorg Brandl2019-11-241-51/+78
|
* Python 3: add StopAsyncIteration exception (bitbucket PR #701)Georg Brandl2019-11-241-2/+3
|
* fixup! Treat Skylark/Starlark files as PythonRyan Beasley2019-11-221-0/+1
|
* Treat Skylark/Starlark files as PythonRyan Beasley2019-11-221-1/+17
| | | | | | | | Closes #1183. Testing Done: - `pygmentize -f html -O full foo.bzl > foo.html`; opened foo.html in a browser
* python3: make "import" in the "fromimport" context match the python2 behaviorKlaas van Schelven2019-11-151-1/+1
| | | | i.e. make it Keyword.Namespace
* Fixup all headers and some more minor problems.2.4.2Georg Brandl2019-05-281-2/+3
|