diff options
| author | Anton Samarchyan <anton.samarchyan@savoirfairelinux.com> | 2017-01-24 18:04:12 -0500 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2017-02-28 09:17:27 -0500 |
| commit | 60e52a047e55bc4cd5a93a8bd4d07baed27e9a22 (patch) | |
| tree | 010a363968b1ed41adf2e64c98d572d7148a2a5e /django/db/backends/sqlite3 | |
| parent | d6e26e5b7c8063c2cc5aa045edea6555bf358fc2 (diff) | |
Refs #27656 -- Updated django.db docstring verbs according to PEP 257.
Diffstat (limited to 'django/db/backends/sqlite3')
| -rw-r--r-- | django/db/backends/sqlite3/base.py | 17 | ||||
| -rw-r--r-- | django/db/backends/sqlite3/creation.py | 2 | ||||
| -rw-r--r-- | django/db/backends/sqlite3/features.py | 6 | ||||
| -rw-r--r-- | django/db/backends/sqlite3/introspection.py | 20 | ||||
| -rw-r--r-- | django/db/backends/sqlite3/operations.py | 25 | ||||
| -rw-r--r-- | django/db/backends/sqlite3/schema.py | 15 |
6 files changed, 34 insertions, 51 deletions
diff --git a/django/db/backends/sqlite3/base.py b/django/db/backends/sqlite3/base.py index 97ddaa084d..c234a382ca 100644 --- a/django/db/backends/sqlite3/base.py +++ b/django/db/backends/sqlite3/base.py @@ -27,9 +27,8 @@ from .schema import DatabaseSchemaEditor # isort:skip def decoder(conv_func): - """ The Python sqlite3 interface returns always byte strings. - This function converts the received value to a regular string before - passing it to the receiver function. + """ + Convert bytestrings from Python's sqlite3 interface to a regular string. """ return lambda s: conv_func(s.decode()) @@ -215,14 +214,14 @@ class DatabaseWrapper(BaseDatabaseWrapper): def check_constraints(self, table_names=None): """ - Checks each table name in `table_names` for rows with invalid foreign + Check each table name in `table_names` for rows with invalid foreign key references. This method is intended to be used in conjunction with `disable_constraint_checking()` and `enable_constraint_checking()`, to determine if rows with invalid references were entered while constraint checks were off. - Raises an IntegrityError on the first invalid foreign key reference - encountered (if any) and provides detailed information about the + Raise an IntegrityError on the first invalid foreign key reference + encountered (if any) and provide detailed information about the invalid reference in the error message. Backends can override this method if they can more directly apply @@ -409,9 +408,9 @@ def _sqlite_time_extract(lookup_type, dt): def _sqlite_format_dtdelta(conn, lhs, rhs): """ LHS and RHS can be either: - - An integer number of microseconds - - A string representing a timedelta object - - A string representing a datetime + - An integer number of microseconds + - A string representing a timedelta object + - A string representing a datetime """ try: if isinstance(lhs, int): diff --git a/django/db/backends/sqlite3/creation.py b/django/db/backends/sqlite3/creation.py index e58a1303a7..5dc7d5831b 100644 --- a/django/db/backends/sqlite3/creation.py +++ b/django/db/backends/sqlite3/creation.py @@ -99,7 +99,7 @@ class DatabaseCreation(BaseDatabaseCreation): def test_db_signature(self): """ - Returns a tuple that uniquely identifies a test database. + Return a tuple that uniquely identifies a test database. This takes into account the special cases of ":memory:" and "" for SQLite since the databases will be distinct despite having the same diff --git a/django/db/backends/sqlite3/features.py b/django/db/backends/sqlite3/features.py index 5bf1997b4c..d67cab6cd0 100644 --- a/django/db/backends/sqlite3/features.py +++ b/django/db/backends/sqlite3/features.py @@ -53,12 +53,12 @@ class DatabaseFeatures(BaseDatabaseFeatures): @cached_property def supports_stddev(self): - """Confirm support for STDDEV and related stats functions + """ + Confirm support for STDDEV and related stats functions. SQLite supports STDDEV as an extension package; so connection.ops.check_expression_support() can't unilaterally - rule out support for STDDEV. We need to manually check - whether the call works. + rule out support for STDDEV. Manually check whether the call works. """ with self.connection.cursor() as cursor: cursor.execute('CREATE TABLE STDDEV_TEST (X INT)') diff --git a/django/db/backends/sqlite3/introspection.py b/django/db/backends/sqlite3/introspection.py index eb15fdb612..0e87dcf0c6 100644 --- a/django/db/backends/sqlite3/introspection.py +++ b/django/db/backends/sqlite3/introspection.py @@ -58,9 +58,7 @@ class DatabaseIntrospection(BaseDatabaseIntrospection): data_types_reverse = FlexibleFieldLookupDict() def get_table_list(self, cursor): - """ - Returns a list of table and view names in the current database. - """ + """Return a list of table and view names in the current database.""" # Skip the sqlite_sequence system table used for autoincrement key # generation. cursor.execute(""" @@ -70,7 +68,10 @@ class DatabaseIntrospection(BaseDatabaseIntrospection): return [TableInfo(row[0], row[1][0]) for row in cursor.fetchall()] def get_table_description(self, cursor, table_name): - "Returns a description of the table, with the DB-API cursor.description interface." + """ + Return a description of the table with the DB-API cursor.description + interface. + """ return [ FieldInfo( info['name'], @@ -156,8 +157,8 @@ class DatabaseIntrospection(BaseDatabaseIntrospection): def get_key_columns(self, cursor, table_name): """ - Returns a list of (column_name, referenced_table_name, referenced_column_name) for all - key columns in given table. + Return a list of (column_name, referenced_table_name, referenced_column_name) + for all key columns in given table. """ key_columns = [] @@ -207,9 +208,7 @@ class DatabaseIntrospection(BaseDatabaseIntrospection): return indexes def get_primary_key_column(self, cursor, table_name): - """ - Get the column name of the primary key for the given table. - """ + """Return the column name of the primary key for the given table.""" # Don't use PRAGMA because that causes issues with some transactions cursor.execute("SELECT sql FROM sqlite_master WHERE tbl_name = %s AND type = %s", [table_name, "table"]) row = cursor.fetchone() @@ -238,7 +237,8 @@ class DatabaseIntrospection(BaseDatabaseIntrospection): def get_constraints(self, cursor, table_name): """ - Retrieves any constraints or keys (unique, pk, fk, check, index) across one or more columns. + Retrieve any constraints or keys (unique, pk, fk, check, index) across + one or more columns. """ constraints = {} # Get the index info diff --git a/django/db/backends/sqlite3/operations.py b/django/db/backends/sqlite3/operations.py index dd9669d02d..95b17db3e8 100644 --- a/django/db/backends/sqlite3/operations.py +++ b/django/db/backends/sqlite3/operations.py @@ -43,31 +43,24 @@ class DatabaseOperations(BaseDatabaseOperations): pass def date_extract_sql(self, lookup_type, field_name): - # sqlite doesn't support extract, so we fake it with the user-defined - # function django_date_extract that's registered in connect(). Note that - # single quotes are used because this is a string (and could otherwise - # cause a collision with a field name). + """ + Support EXTRACT with a user-defined function django_date_extract() + that's registered in connect(). Use single quotes because this is a + string and could otherwise cause a collision with a field name. + """ return "django_date_extract('%s', %s)" % (lookup_type.lower(), field_name) def date_interval_sql(self, timedelta): return "'%s'" % duration_string(timedelta), [] def format_for_duration_arithmetic(self, sql): - """Do nothing here, we will handle it in the custom function.""" + """Do nothing since formatting is handled in the custom function.""" return sql def date_trunc_sql(self, lookup_type, field_name): - # sqlite doesn't support DATE_TRUNC, so we fake it with a user-defined - # function django_date_trunc that's registered in connect(). Note that - # single quotes are used because this is a string (and could otherwise - # cause a collision with a field name). return "django_date_trunc('%s', %s)" % (lookup_type.lower(), field_name) def time_trunc_sql(self, lookup_type, field_name): - # sqlite doesn't support DATE_TRUNC, so we fake it with a user-defined - # function django_date_trunc that's registered in connect(). Note that - # single quotes are used because this is a string (and could otherwise - # cause a collision with a field name). return "django_time_trunc('%s', %s)" % (lookup_type.lower(), field_name) def _convert_tzname_to_sql(self, tzname): @@ -84,22 +77,16 @@ class DatabaseOperations(BaseDatabaseOperations): ) def datetime_extract_sql(self, lookup_type, field_name, tzname): - # Same comment as in date_extract_sql. return "django_datetime_extract('%s', %s, %s)" % ( lookup_type.lower(), field_name, self._convert_tzname_to_sql(tzname), ) def datetime_trunc_sql(self, lookup_type, field_name, tzname): - # Same comment as in date_trunc_sql. return "django_datetime_trunc('%s', %s, %s)" % ( lookup_type.lower(), field_name, self._convert_tzname_to_sql(tzname), ) def time_extract_sql(self, lookup_type, field_name): - # sqlite doesn't support extract, so we fake it with the user-defined - # function django_time_extract that's registered in connect(). Note that - # single quotes are used because this is a string (and could otherwise - # cause a collision with a field name). return "django_time_extract('%s', %s)" % (lookup_type.lower(), field_name) def pk_default_value(self): diff --git a/django/db/backends/sqlite3/schema.py b/django/db/backends/sqlite3/schema.py index bf2824aa1f..edc6331cb7 100644 --- a/django/db/backends/sqlite3/schema.py +++ b/django/db/backends/sqlite3/schema.py @@ -19,7 +19,7 @@ class DatabaseSchemaEditor(BaseDatabaseSchemaEditor): # Some SQLite schema alterations need foreign key constraints to be # disabled. This is the default in SQLite but can be changed with a # build flag and might change in future, so can't be relied upon. - # We enforce it here for the duration of the transaction. + # Enforce it here for the duration of the transaction. c.execute('PRAGMA foreign_keys') self._initial_pragma_fk = c.fetchone()[0] c.execute('PRAGMA foreign_keys = 0') @@ -225,9 +225,8 @@ class DatabaseSchemaEditor(BaseDatabaseSchemaEditor): def add_field(self, model, field): """ - Creates a field on a model. - Usually involves adding a column, but may involve adding a - table instead (for M2M fields) + Create a field on a model. Usually involves adding a column, but may + involve adding a table instead (for M2M fields). """ # Special-case implicit M2M tables if field.many_to_many and field.remote_field.through._meta.auto_created: @@ -236,7 +235,7 @@ class DatabaseSchemaEditor(BaseDatabaseSchemaEditor): def remove_field(self, model, field): """ - Removes a field from a model. Usually involves deleting a column, + Remove a field from a model. Usually involves deleting a column, but for M2Ms may involve deleting a table. """ # M2M fields are a special case @@ -254,14 +253,12 @@ class DatabaseSchemaEditor(BaseDatabaseSchemaEditor): def _alter_field(self, model, old_field, new_field, old_type, new_type, old_db_params, new_db_params, strict=False): - """Actually perform a "physical" (non-ManyToMany) field update.""" + """Perform a "physical" (non-ManyToMany) field update.""" # Alter by remaking table self._remake_table(model, alter_field=(old_field, new_field)) def _alter_many_to_many(self, model, old_field, new_field, strict): - """ - Alters M2Ms to repoint their to= endpoints. - """ + """Alter M2Ms to repoint their to= endpoints.""" if old_field.remote_field.through._meta.db_table == new_field.remote_field.through._meta.db_table: # The field name didn't change, but some options did; we have to propagate this altering. self._remake_table( |
