Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork941
Commit65863a2
committed
Make NULL_TREE and Index precisely annotatable
This creates a git.diff.DiffConstants enumeration and makes thegit.diff.NULL_TREE and git.diff.Diffable.Index objects constants init. This allows them (including as an alternative in a union) to beannotated as literals:- Literal[DiffConstants.NULL_TREE]- Literal[DIffConstants.INDEX]Although the enumeration type must unfortunately be included in theannotations as shown above (at least mypy requires this), using theobjects/values themselves does not require any code to change. Sothis shouldn't break anything at runtime for code using GitPython,unless it has relied on NULL_TREE being a direct instance of object,or relied on Diffable.Index (all useful uses of which were also asan opaque constant) being defined as a class.More specifically, all the ways that NULL_TREE and Index could be*accessed* before are still working, because:- NULL_TREE is aliased at module level, where it was before. It is also aliased at class level in Diffable, for consistency.- INDEX is aliased at class level in Diffable, as Index, where it was before. This way, Diffable.Index can still be used. It is also aliased, in the same scope, as INDEX. Because it is, and in effect has always been, a constant, the new INDEX spelling is preferable. But there is no major disadvantage of the old Index spelling, so in docstrings I have made no effort at this time to discourage its use. (If GitPython ever uses all-caps identifiers strictly as constants, then the clarity benefit of ensuring only the INDEX version is used will be greater, and then it might make sense to deprecate Index. However, this seems unlikely to happen as it would be a breaking change, due to the way functions like git.reset rebind Git.GIT_PYTHON_GIT_EXECUTABLE.) INDEX is also aliased at module level, for consistency.- NULL_TREE is still included in git.diff.__all__, causing it to be recognized as public in git.diff and also to be accessible as an attribute of the top-level git module (which currently uses wildcard imports). For consistency, I have also included INDEX in __all__.- Because there is a benefit to being able to freely referene the new DiffConstants enumeration in annotations (though in practice this may mostly be to implementers of new Diffable subclasses), I have also included DiffConstants in __all__. In addition, the name DiffConstants (rather than, e.g., Constants) should avoid confusion even if it ends up in another scope unexpectedly.To avoid a situation where users/developers may erroneously thinkthese aliases are different from each other, I have documented thesituation in the docstrings for each, referring to the others.(Sphinx does not automatically use the original docstring for analiased name introduced in this way, and there is also arguably aclarity benefit to their differing wording, such as how each refers*only* to the others.) Other docstings are also updated.This commit completes the change begun in2f5e258 before this,resolving the one mypy error it added. But this does not completethe larger change begun in0e1df29:- One of the effects of this change is to make it possible to annotate precisely for NULL_TREE, either by using Literal[DiffConstants.NULL_TREE] or consolidating it with the Literal[DiffConstants.INDEX] alternative by including DiffConstants in the union instead of either/both of them.- But that is not yet done here, and when it is done for Diffable.diff, the LSP issue in IndexFile.diff, which does not currently accommodate NULL_TREE, will resurface (or, rather, be rightly revealed by mypy, in a way that is specifically clear).1 parent2f5e258 commit65863a2
3 files changed
+81
-28
lines changedLines changed: 79 additions & 23 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
3 | 3 |
| |
4 | 4 |
| |
5 | 5 |
| |
| 6 | + | |
6 | 7 |
| |
7 | 8 |
| |
8 | 9 |
| |
| |||
22 | 23 |
| |
23 | 24 |
| |
24 | 25 |
| |
25 |
| - | |
26 | 26 |
| |
27 | 27 |
| |
28 | 28 |
| |
29 | 29 |
| |
30 | 30 |
| |
31 |
| - | |
| 31 | + | |
32 | 32 |
| |
33 | 33 |
| |
34 | 34 |
| |
| |||
48 | 48 |
| |
49 | 49 |
| |
50 | 50 |
| |
51 |
| - | |
| 51 | + | |
52 | 52 |
| |
53 |
| - | |
54 |
| - | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
55 | 100 |
| |
56 | 101 |
| |
57 | 102 |
| |
| |||
84 | 129 |
| |
85 | 130 |
| |
86 | 131 |
| |
87 |
| - | |
| 132 | + | |
88 | 133 |
| |
89 | 134 |
| |
90 | 135 |
| |
| |||
94 | 139 |
| |
95 | 140 |
| |
96 | 141 |
| |
97 |
| - | |
98 |
| - | |
99 |
| - | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
100 | 161 |
| |
101 | 162 |
| |
102 | 163 |
| |
| |||
112 | 173 |
| |
113 | 174 |
| |
114 | 175 |
| |
115 |
| - | |
| 176 | + | |
116 | 177 |
| |
117 | 178 |
| |
118 | 179 |
| |
| |||
125 | 186 |
| |
126 | 187 |
| |
127 | 188 |
| |
128 |
| - | |
129 |
| - | |
130 |
| - | |
| 189 | + | |
| 190 | + | |
131 | 191 |
| |
132 |
| - | |
133 |
| - | |
134 |
| - | |
135 |
| - | |
| 192 | + | |
136 | 193 |
| |
137 |
| - | |
138 |
| - | |
| 194 | + | |
139 | 195 |
| |
140 |
| - | |
141 |
| - | |
| 196 | + | |
| 197 | + | |
142 | 198 |
| |
143 | 199 |
| |
144 | 200 |
| |
| |||
185 | 241 |
| |
186 | 242 |
| |
187 | 243 |
| |
188 |
| - | |
| 244 | + | |
189 | 245 |
| |
190 | 246 |
| |
191 | 247 |
| |
| |||
218 | 274 |
| |
219 | 275 |
| |
220 | 276 |
| |
221 |
| - | |
| 277 | + | |
222 | 278 |
| |
223 | 279 |
| |
224 | 280 |
| |
|
Lines changed: 2 additions & 3 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
76 | 76 |
| |
77 | 77 |
| |
78 | 78 |
| |
79 |
| - | |
80 | 79 |
| |
81 | 80 |
| |
82 | 81 |
| |
83 |
| - | |
| 82 | + | |
84 | 83 |
| |
85 | 84 |
| |
86 | 85 |
| |
| |||
1479 | 1478 |
| |
1480 | 1479 |
| |
1481 | 1480 |
| |
1482 |
| - | |
| 1481 | + | |
1483 | 1482 |
| |
1484 | 1483 |
| |
1485 | 1484 |
| |
|
Lines changed: 0 additions & 2 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
22 | 22 |
| |
23 | 23 |
| |
24 | 24 |
| |
25 |
| - | |
26 | 25 |
| |
27 | 26 |
| |
28 | 27 |
| |
| |||
31 | 30 |
| |
32 | 31 |
| |
33 | 32 |
| |
34 |
| - | |
35 | 33 |
| |
36 | 34 |
| |
37 | 35 |
| |
|
0 commit comments
Comments
(0)