From 19485e60df45367c80411addfb34206304b598d0 Mon Sep 17 00:00:00 2001 From: Luke Kenneth Casson Leighton Date: Sun, 24 Mar 2019 10:57:17 +0000 Subject: [PATCH] document new Record spec: allow placeholder objects --- src/add/example_buf_pipe.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/add/example_buf_pipe.py b/src/add/example_buf_pipe.py index 005dbc17..8c4cae44 100644 --- a/src/add/example_buf_pipe.py +++ b/src/add/example_buf_pipe.py @@ -174,10 +174,12 @@ def eq(o, i): responsibility of further calling eq and returning a list of eq assignments - Record is a special (unusual, recursive) case, where the input - is specified as a dictionary (which may contain further dictionaries, + Record is a special (unusual, recursive) case, where the input may be + specified as a dictionary (which may contain further dictionaries, recursively), where the field names of the dictionary must match - the Record's field spec. + the Record's field spec. Alternatively, an object with the same + member names as the Record may be assigned: it does not have to + *be* a Record. """ if not isinstance(o, Sequence): o, i = [o], [i] @@ -190,10 +192,10 @@ def eq(o, i): val = ai.fields else: val = ai - if hasattr(val, field_name): + if hasattr(val, field_name): # check for attribute val = getattr(val, field_name) else: - val = val[field_name] + val = val[field_name] # dictionary-style specification rres = eq(ao.fields[field_name], val) res += rres else: -- 2.30.2