summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDavid Lord <davidism@gmail.com>2022-02-17 17:04:40 -0800
committerDavid Lord <davidism@gmail.com>2022-02-17 17:04:40 -0800
commit80e6c4bb5644817a5dd272a0d7655b5a0e30b015 (patch)
tree7f0ff42ad99448a1b0ca72f544dd84deb779771b /src
parent077b7918a7642ff6742fe48a32e54d7875140894 (diff)
parenta8ee08141b03e39ea926d85ef5a4ed565f3b1e2b (diff)
downloadjinja2-80e6c4bb5644817a5dd272a0d7655b5a0e30b015.tar.gz
Merge branch '3.0.x'
Diffstat (limited to 'src')
-rw-r--r--src/jinja2/filters.py2
-rw-r--r--src/jinja2/lexer.py24
-rw-r--r--src/jinja2/parser.py34
3 files changed, 26 insertions, 34 deletions
diff --git a/src/jinja2/filters.py b/src/jinja2/filters.py
index b67c801..9ebd991 100644
--- a/src/jinja2/filters.py
+++ b/src/jinja2/filters.py
@@ -1111,7 +1111,7 @@ def do_round(
return round(value, precision)
func = getattr(math, method)
- return t.cast(float, func(value * (10 ** precision)) / (10 ** precision))
+ return t.cast(float, func(value * (10**precision)) / (10**precision))
class _GroupTuple(t.NamedTuple):
diff --git a/src/jinja2/lexer.py b/src/jinja2/lexer.py
index b46a7e1..a2eaa8d 100644
--- a/src/jinja2/lexer.py
+++ b/src/jinja2/lexer.py
@@ -515,11 +515,11 @@ class Lexer:
self.keep_trailing_newline = environment.keep_trailing_newline
root_raw_re = (
- fr"(?P<raw_begin>{block_start_re}(\-|\+|)\s*raw\s*"
- fr"(?:\-{block_end_re}\s*|{block_end_re}))"
+ rf"(?P<raw_begin>{block_start_re}(\-|\+|)\s*raw\s*"
+ rf"(?:\-{block_end_re}\s*|{block_end_re}))"
)
root_parts_re = "|".join(
- [root_raw_re] + [fr"(?P<{n}>{r}(\-|\+|))" for n, r in root_tag_rules]
+ [root_raw_re] + [rf"(?P<{n}>{r}(\-|\+|))" for n, r in root_tag_rules]
)
# global lexing rules
@@ -527,7 +527,7 @@ class Lexer:
"root": [
# directives
_Rule(
- c(fr"(.*?)(?:{root_parts_re})"),
+ c(rf"(.*?)(?:{root_parts_re})"),
OptionalLStrip(TOKEN_DATA, "#bygroup"), # type: ignore
"#bygroup",
),
@@ -538,8 +538,8 @@ class Lexer:
TOKEN_COMMENT_BEGIN: [
_Rule(
c(
- fr"(.*?)((?:\+{comment_end_re}|\-{comment_end_re}\s*"
- fr"|{comment_end_re}{block_suffix_re}))"
+ rf"(.*?)((?:\+{comment_end_re}|\-{comment_end_re}\s*"
+ rf"|{comment_end_re}{block_suffix_re}))"
),
(TOKEN_COMMENT, TOKEN_COMMENT_END),
"#pop",
@@ -550,8 +550,8 @@ class Lexer:
TOKEN_BLOCK_BEGIN: [
_Rule(
c(
- fr"(?:\+{block_end_re}|\-{block_end_re}\s*"
- fr"|{block_end_re}{block_suffix_re})"
+ rf"(?:\+{block_end_re}|\-{block_end_re}\s*"
+ rf"|{block_end_re}{block_suffix_re})"
),
TOKEN_BLOCK_END,
"#pop",
@@ -561,7 +561,7 @@ class Lexer:
# variables
TOKEN_VARIABLE_BEGIN: [
_Rule(
- c(fr"\-{variable_end_re}\s*|{variable_end_re}"),
+ c(rf"\-{variable_end_re}\s*|{variable_end_re}"),
TOKEN_VARIABLE_END,
"#pop",
)
@@ -571,9 +571,9 @@ class Lexer:
TOKEN_RAW_BEGIN: [
_Rule(
c(
- fr"(.*?)((?:{block_start_re}(\-|\+|))\s*endraw\s*"
- fr"(?:\+{block_end_re}|\-{block_end_re}\s*"
- fr"|{block_end_re}{block_suffix_re}))"
+ rf"(.*?)((?:{block_start_re}(\-|\+|))\s*endraw\s*"
+ rf"(?:\+{block_end_re}|\-{block_end_re}\s*"
+ rf"|{block_end_re}{block_suffix_re}))"
),
OptionalLStrip(TOKEN_DATA, TOKEN_RAW_END), # type: ignore
"#pop",
diff --git a/src/jinja2/parser.py b/src/jinja2/parser.py
index 4447396..cefce2d 100644
--- a/src/jinja2/parser.py
+++ b/src/jinja2/parser.py
@@ -364,14 +364,10 @@ class Parser:
node.names = []
def parse_context() -> bool:
- if (
- self.stream.current.value
- in {
- "with",
- "without",
- }
- and self.stream.look().test("name:context")
- ):
+ if self.stream.current.value in {
+ "with",
+ "without",
+ } and self.stream.look().test("name:context"):
node.with_context = next(self.stream).value == "with"
self.stream.skip()
return True
@@ -957,19 +953,15 @@ class Parser:
kwargs = []
if self.stream.current.type == "lparen":
args, kwargs, dyn_args, dyn_kwargs = self.parse_call_args()
- elif (
- self.stream.current.type
- in {
- "name",
- "string",
- "integer",
- "float",
- "lparen",
- "lbracket",
- "lbrace",
- }
- and not self.stream.current.test_any("name:else", "name:or", "name:and")
- ):
+ elif self.stream.current.type in {
+ "name",
+ "string",
+ "integer",
+ "float",
+ "lparen",
+ "lbracket",
+ "lbrace",
+ } and not self.stream.current.test_any("name:else", "name:or", "name:and"):
if self.stream.current.test("name:is"):
self.fail("You cannot chain multiple tests with is")
arg_node = self.parse_primary()