1
0
mirror of https://github.com/django/django.git synced 2025-11-07 07:15:35 +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:
Jon Dufresne
2020-05-10 13:03:39 -07:00
committed by Mariusz Felisiak
parent 23f6fbdd93
commit d6aff369ad
36 changed files with 92 additions and 92 deletions

View File

@@ -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):