Skip to content

Commit b973600

Browse files
authored
Merge pull request #282 from 15r10nk/declare-unmanaged
feat: exposed declare_unmanaged
2 parents 2eb3719 + 201579a commit b973600

File tree

3 files changed

+68
-0
lines changed

3 files changed

+68
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<!--
2+
A new scriv changelog fragment.
3+
4+
Uncomment the section that is right (remove the HTML comment wrapper).
5+
For top level release notes, leave all the headers commented out.
6+
-->
7+
8+
<!--
9+
### Removed
10+
11+
- A bullet item for the Removed category.
12+
13+
-->
14+
### Added
15+
16+
- exposed `@declare_unmanaged` which allows you to create your own unmanaged types.
17+
18+
<!--
19+
### Changed
20+
21+
- A bullet item for the Changed category.
22+
23+
-->
24+
<!--
25+
### Deprecated
26+
27+
- A bullet item for the Deprecated category.
28+
29+
-->
30+
<!--
31+
### Fixed
32+
33+
- A bullet item for the Fixed category.
34+
35+
-->
36+
<!--
37+
### Security
38+
39+
- A bullet item for the Security category.
40+
41+
-->

docs/eq_snapshot.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,31 @@ These types are:
5858
* [snapshots](#inner-snapshots) inside snapshots and
5959
* [f-strings](#f-strings).
6060

61+
You can also create your own unmanaged types with `@declare_unmanaged`
62+
63+
<!-- inline-snapshot: create fix first_block outcome-passed=1 -->
64+
``` python
65+
from inline_snapshot import declare_unmanaged, snapshot
66+
67+
68+
@declare_unmanaged
69+
class AllEqual:
70+
def __init__(self, value):
71+
self.value = value
72+
73+
def __eq__(self, other):
74+
return all(o == self.value for o in other)
75+
76+
77+
def test_all_equal():
78+
assert {"text": "hello", "values": [1, 1, 1]} == snapshot(
79+
{"text": "hello", "values": AllEqual(snapshot(1))}
80+
)
81+
```
82+
83+
You have to put `AllEqual` manually into the snapshot and inline-snapshot will not touch it in the future when it has to fix the code, but it will change the value in the snapshot argument of `AllEqual`, because this is another snapshot.
84+
This allows you to specify what should be under your control and which code should be controlled and changed by inline-snapshot.
85+
6186
inline-snapshot is able to handle these types within the following containers:
6287

6388
* list

src/inline_snapshot/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from ._is import Is
1515
from ._types import Category
1616
from ._types import Snapshot
17+
from ._unmanaged import declare_unmanaged
1718

1819
__all__ = [
1920
"snapshot",
@@ -31,6 +32,7 @@
3132
"TextDiff",
3233
"BinaryDiff",
3334
"external_file",
35+
"declare_unmanaged",
3436
]
3537

3638
__version__ = "0.26.0"

0 commit comments

Comments
 (0)