misc: change pyupgrade target version to 3.9 (#75442)

This commit is contained in:
Valentin Deniaud 2023-03-15 16:21:31 +01:00
parent 74a045f530
commit bfc3a65097
2 changed files with 4 additions and 17 deletions

View File

@ -2,10 +2,10 @@
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/asottile/pyupgrade
rev: v3.1.0
rev: v3.3.1
hooks:
- id: pyupgrade
args: ['--keep-percent-format', '--py37-plus']
args: ['--keep-percent-format', '--py39-plus']
- repo: https://github.com/adamchainz/django-upgrade
rev: 1.13.0
hooks:

View File

@ -17,7 +17,6 @@
import ast
import logging
import re
import sys
import dns.exception
import dns.resolver
@ -203,10 +202,7 @@ class BaseExpressionValidator(ast.NodeVisitor):
# python 3.8 introduced ast.Constant to replace Num, Str, Bytes and NameConstant (True, False, None)
if sys.version_info < (3, 8):
CONSTANT_CLASSES = (ast.Num, ast.Str, ast.Bytes)
else:
CONSTANT_CLASSES = (ast.Constant,)
CONSTANT_CLASSES = (ast.Constant,)
class ConditionValidator(BaseExpressionValidator):
@ -272,16 +268,7 @@ class ConditionValidator(BaseExpressionValidator):
def check_Subscript(self, node):
# check subscript are constant number or strings
ok = True
if sys.version_info >= (3, 9):
ok = isinstance(node.slice, CONSTANT_CLASSES)
elif sys.version_info >= (3, 8):
ok = (
isinstance(node.slice, ast.Index)
and isinstance(node.slice.value, CONSTANT_CLASSES)
and isinstance(node.slice.value.value, (int, str, bytes))
)
else:
ok = isinstance(node.slice, ast.Index) and isinstance(node.slice.value, CONSTANT_CLASSES)
ok = isinstance(node.slice, CONSTANT_CLASSES)
if not ok:
raise ExpressionError(
_('subscript index MUST be a constant'), code='invalid-subscript', node=node