Skip to content

Commit e80f4e8

Browse files
authored
Fix: Improve README
1 parent a1caab1 commit e80f4e8

1 file changed

Lines changed: 18 additions & 18 deletions

File tree

README.md

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class Dummy:
1717
pass
1818
```
1919

20-
Normal Python code
20+
Normal Python code:
2121

2222
```python
2323
o = Dummy()
@@ -42,29 +42,29 @@ if value is not undefined:
4242
print("accessed")
4343
```
4444

45-
## Documentation
45+
# Documentation
4646

47-
### Basics
47+
## Basics
4848

4949
There are 5 values importable in nullsafe root:
5050

51-
#### class `NullSafeProxy: (o: T)`
51+
### class `NullSafeProxy: (o: T)`
5252

5353
Receives an object `o` on instantiation.
5454

5555
Proxy class for granting nullsafe abilities to an object.
5656

57-
#### class `NullSafe: ()`
57+
### class `NullSafe: ()`
5858

5959
No argument needed.
6060

6161
Nullish class with with nullsafe abilities. Instances will have a falsy boolean evaluation, equity comparison (`==`) to `None` and instance of `NullSafe` returns `True`, otherwise `False`. Identity comparison (`is`) to `None` will return `False`.
6262

63-
#### variable `undefined: NullSafe`
63+
### variable `undefined: NullSafe`
6464

6565
Instance of `Nullsafe`, this instance will be returned for all nullish access in a proxied object, enabling identity comparison `value is undefined` for code clarity.
6666

67-
#### function `nullsafe: (o: T) -> T`
67+
### function `nullsafe: (o: T) -> T`
6868

6969
Receives an object `o` as argument.
7070

@@ -74,27 +74,27 @@ return `undefined` if `o` is `None` or `undefined`, otherwise return the proxied
7474

7575
This function is **generic typed** (`(o: T) -> T`), code autocompletions and linters functionalities will remain. Disclaimer: If the object was not typed before proxy, it obviously won't come out typed out of the blue.
7676

77-
#### function `_: (o: T) -> T` (alias to `nullsafe`)
77+
### function `_: (o: T) -> T` (alias to `nullsafe`)
7878

79-
Alias to nullsafe, used for better code clarity.
79+
Alias to `nullsafe`, used for better code clarity.
8080

8181
The examples shown will be using `_` instead of `nullsafe` for code clarity. For better understanding, the Javascript equivalents will be shown as comments.
8282

83-
### Implementation
83+
## Implementation
8484

8585
Nullsafe abilities are granted after proxying an object through `NullSafeProxy`. To proxy an object pass it through `_()` or `nullsafe()`. Due to language limitation, the implementation does not follow the "return the first nullish value in chain", instead it "extend the a custom nullish value until the end of chain". Inexistent values of a proxied object and its subsequent values in chain will return `undefined`.
8686

87-
### Import
87+
## Import
8888

8989
```python
9090
from nullsafe import undefined, _
9191
```
9292

93-
### Usage
93+
## Usage
9494

9595
There are various way to get a nullsafe proxied object.
9696

97-
#### Null safe attribute access
97+
### Null safe attribute access
9898

9999
Proxied object doing a possibly `AttributeError` access.
100100

@@ -138,7 +138,7 @@ assert _(o["existent"])["inexistent"]["nested"] is undefined
138138
assert _(_(o)["maybe"])["inexistent"]["nested"] is undefined
139139
```
140140

141-
#### Null safe post evaluation
141+
### Null safe post evaluation
142142

143143
Possibly `None` or `undefined` object doing possibly `AttributeError` or `KeyError` access.
144144

@@ -170,19 +170,19 @@ assert _(o["nay"])["inexistent"]["nested"] is undefined
170170
assert not _(o["nay"])["inexistent"]["nested"]
171171
```
172172

173-
#### Combined usage
173+
### Combined usage
174174

175175
Of course you can combine different styles.
176176

177177
```python
178178
assert _(o).inexistent["inexistent"].inexistent.inexistent["inexistent"]["inexistent"] is undefined
179179
```
180180

181-
### Limitations
181+
## Limitations
182182

183183
List of limitations that you may encounter.
184184

185-
#### `undefined` behavior
185+
### `undefined` behavior
186186

187187
`undefined` is actually an instance of `NullSafe`, the actual mechanism used for nullsafe chaining, it cannot self rip the nullsafe functionality when the chain ends (because it doesn't know), so this following actually possible and probably not the wanted behavior.
188188

@@ -192,7 +192,7 @@ val = _(o).inexistent
192192
assert val.another_inexistent is undefined
193193
```
194194

195-
#### Post evaluation
195+
### Post evaluation
196196

197197
In other languages like Javascript, it checks for each item in the chain and return `undefined` on the first nullish value, which in fact is post-evaluated. This is not possible in python because it raises an `AttributeError` or `KeyError` on access attempt, unless it returns `None` (see [one of the available usage](#null-safe-post-evaluation)), so it must proxy the instance that may contain the attr or key before accessing.
198198

0 commit comments

Comments
 (0)