Skip to content
This repository was archived by the owner on Jun 3, 2023. It is now read-only.

Commit d25e7df

Browse files
committed
Doc enhancement around new Boolean type.
1 parent b57553f commit d25e7df

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

README.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,6 @@ writer.write(TaggedValue("ints", [1,2,3]))
9595

9696
### Python's bool and int
9797

98-
All caveats of the Python language apply to decoding Transit data.
99-
10098
In Python, bools are subclasses of int (that is, `True` is actually `1`).
10199

102100
```python
@@ -108,7 +106,7 @@ In Python, bools are subclasses of int (that is, `True` is actually `1`).
108106
True
109107
```
110108

111-
This only becomes problematic when decoding a map that contains bool and
109+
This becomes problematic when decoding a map that contains bool and
112110
int keys. The bool keys may be overridden (ie: you'll only see the int key),
113111
and the value will be one of any possible bool/int keyed value.
114112

@@ -117,6 +115,14 @@ and the value will be one of any possible bool/int keyed value.
117115
{1: 'World'}
118116
```
119117

118+
To counter this problem, the latest version of Transit Python introduces a
119+
Boolean type with singleton (by convention of use) instances of "true" and
120+
"false." A Boolean can be converted to a native Python bool with bool(x) where
121+
x is the "true" or "false" instance. Logical evaluation works correctly with
122+
Booleans (that is, they override the __nonzero__ method and correctly evaluate
123+
as true and false in simple logical evaluation), but uses of a Boolean as an
124+
integer will fail.
125+
120126
### Default type mapping
121127

122128
|Transit type|Write accepts|Read returns|

0 commit comments

Comments
 (0)