From b37b8a9f6d69b46a5a4d3f7ea694c96b798697e6 Mon Sep 17 00:00:00 2001 From: Dmitry S Date: Thu, 6 Jan 2022 18:58:54 -0500 Subject: [PATCH] (core) A few tiny documentation tweaks. Summary: - Improve readability of documentation of CONTAINS. - Add leading underscore to Record._get_encodable_row_ids() to hide from public docs, and avoid interfering with user fields. - Fix up lint errors Test Plan: No behavior changes Reviewers: paulfitz Reviewed By: paulfitz Differential Revision: https://phab.getgrist.com/D3209 --- sandbox/grist/functions/lookup.py | 4 +++- sandbox/grist/functions/math.py | 2 ++ sandbox/grist/objtypes.py | 2 +- sandbox/grist/records.py | 4 +++- sandbox/grist/table.py | 8 +++++--- 5 files changed, 14 insertions(+), 6 deletions(-) diff --git a/sandbox/grist/functions/lookup.py b/sandbox/grist/functions/lookup.py index 7297e29b..d719850a 100644 --- a/sandbox/grist/functions/lookup.py +++ b/sandbox/grist/functions/lookup.py @@ -154,7 +154,9 @@ def VLOOKUP(table, **field_value_pairs): class _Contains(namedtuple("_Contains", "value")): """ Use this marker with [UserTable.lookupRecords](#lookuprecords) to find records - where a field of a list type (such as `Choice List` or `Reference List`) contains the given value, e.g: + where a field of a list type (such as `Choice List` or `Reference List`) contains the given value. + + For example: MoviesTable.lookupRecords(genre=CONTAINS("Drama")) diff --git a/sandbox/grist/functions/math.py b/sandbox/grist/functions/math.py index 9f205c31..97d7ac32 100644 --- a/sandbox/grist/functions/math.py +++ b/sandbox/grist/functions/math.py @@ -612,6 +612,8 @@ def ROUND(value, places=0): 2.0 >>> ROUND(2.5) 3.0 + >>> ROUND(-2.5) + -3.0 >>> ROUND(2.15, 1) 2.2 >>> ROUND(-1.475, 2) diff --git a/sandbox/grist/objtypes.py b/sandbox/grist/objtypes.py index 28248229..2124664b 100644 --- a/sandbox/grist/objtypes.py +++ b/sandbox/grist/objtypes.py @@ -190,7 +190,7 @@ def encode_object(value): elif isinstance(value, (list, tuple)): return ['L'] + [encode_object(item) for item in value] elif isinstance(value, records.RecordSet): - return ['r', value._table.table_id, value.get_encodable_row_ids()] + return ['r', value._table.table_id, value._get_encodable_row_ids()] elif isinstance(value, RecordSetStub): return ['r', value.table_id, value.row_ids] elif isinstance(value, dict): diff --git a/sandbox/grist/records.py b/sandbox/grist/records.py index 9c1e675b..5b244188 100644 --- a/sandbox/grist/records.py +++ b/sandbox/grist/records.py @@ -133,6 +133,8 @@ class RecordSet(object): You can get the number of records in a RecordSet using `len`, e.g. `len($group)`. """ + # Methods should be named with a leading underscore to avoid interfering with access to + # user-defined fields. def __init__(self, table, row_ids, relation=None, group_by=None, sort_by=None): """ group_by may be a dictionary mapping column names to values that are all the same for the given @@ -194,7 +196,7 @@ class RecordSet(object): group_by=self._group_by, sort_by=self._sort_by) - def get_encodable_row_ids(self): + def _get_encodable_row_ids(self): """ Returns stored rowIds as a simple list or tuple type, even if actually stored as RecordList. """ diff --git a/sandbox/grist/table.py b/sandbox/grist/table.py index 202c2aed..47e4ae04 100644 --- a/sandbox/grist/table.py +++ b/sandbox/grist/table.py @@ -89,9 +89,10 @@ class UserTable(object): ``` See [RecordSet](#recordset) for useful properties offered by the returned object. - - See [CONTAINS](#contains) for an example utilizing `UserTable.lookupRecords` to find records where - a field of a list type (such as `Choice List` or `Reference List`) contains the given value. + + See [CONTAINS](#contains) for an example utilizing `UserTable.lookupRecords` to find records + where a field of a list type (such as `Choice List` or `Reference List`) contains the given + value. """ return self.table.lookup_records(**field_value_pairs) @@ -356,6 +357,7 @@ class Table(object): col_id = summary_table._summary_helper_col_id if self.has_column(col_id): # If type changed between Reference/ReferenceList, replace completely. + # pylint: disable=unidiomatic-typecheck if type(self.get_column(col_id).type_obj) != type(_updateSummary.grist_type): self.delete_column(self.get_column(col_id)) col_obj = self._create_or_update_col(col_id, _updateSummary)