mirror of
https://github.com/django/django.git
synced 2025-10-31 09:41:08 +00:00
Refs #30116 -- Simplified regex match group access with Match.__getitem__().
The method has been available since Python 3.6. The shorter syntax is also marginally faster.
This commit is contained in:
committed by
Mariusz Felisiak
parent
23f6fbdd93
commit
d6aff369ad
@@ -17,7 +17,7 @@ field_size_re = _lazy_re_compile(r'^\s*(?:var)?char\s*\(\s*(\d+)\s*\)\s*$')
|
||||
def get_field_size(name):
|
||||
""" Extract the size number from a "varchar(11)" type name """
|
||||
m = field_size_re.search(name)
|
||||
return int(m.group(1)) if m else None
|
||||
return int(m[1]) if m else None
|
||||
|
||||
|
||||
# This light wrapper "fakes" a dictionary interface, because some SQLite data
|
||||
@@ -147,7 +147,7 @@ class DatabaseIntrospection(BaseDatabaseIntrospection):
|
||||
if field_desc.startswith("FOREIGN KEY"):
|
||||
# Find name of the target FK field
|
||||
m = re.match(r'FOREIGN KEY\s*\(([^\)]*)\).*', field_desc, re.I)
|
||||
field_name = m.groups()[0].strip('"')
|
||||
field_name = m[1].strip('"')
|
||||
else:
|
||||
field_name = field_desc.split()[0].strip('"')
|
||||
|
||||
@@ -218,7 +218,7 @@ class DatabaseIntrospection(BaseDatabaseIntrospection):
|
||||
field_desc = field_desc.strip()
|
||||
m = re.match(r'(?:(?:["`\[])(.*)(?:["`\]])|(\w+)).*PRIMARY KEY.*', field_desc)
|
||||
if m:
|
||||
return m.group(1) if m.group(1) else m.group(2)
|
||||
return m[1] if m[1] else m[2]
|
||||
return None
|
||||
|
||||
def _get_foreign_key_constraints(self, cursor, table_name):
|
||||
|
||||
@@ -1325,5 +1325,5 @@ class MigrationAutodetector:
|
||||
"""
|
||||
match = re.match(r'^\d+', name)
|
||||
if match:
|
||||
return int(match.group())
|
||||
return int(match[0])
|
||||
return None
|
||||
|
||||
@@ -383,7 +383,7 @@ class SQLCompiler:
|
||||
# not taken into account so we strip it. When this entire method
|
||||
# is refactored into expressions, then we can check each part as we
|
||||
# generate it.
|
||||
without_ordering = self.ordering_parts.search(sql).group(1)
|
||||
without_ordering = self.ordering_parts.search(sql)[1]
|
||||
params_hash = make_hashable(params)
|
||||
if (without_ordering, params_hash) in seen:
|
||||
continue
|
||||
@@ -396,7 +396,7 @@ class SQLCompiler:
|
||||
if self.query.distinct and not self.query.distinct_fields:
|
||||
select_sql = [t[1] for t in select]
|
||||
for expr, (sql, params, is_ref) in order_by:
|
||||
without_ordering = self.ordering_parts.search(sql).group(1)
|
||||
without_ordering = self.ordering_parts.search(sql)[1]
|
||||
if not is_ref and (without_ordering, params) not in select_sql:
|
||||
extra_select.append((expr, (without_ordering, params), None))
|
||||
return extra_select
|
||||
|
||||
Reference in New Issue
Block a user