Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork939
Commit04eb09c
committed
Have USE_SHELL warn but work like normal via super()
This reimplements Git.USE_SHELL with no properties or descriptors.The metaclass is still needed, but instad of defining properties itdefines __getattribute__ and __setattr__, which check for USE_SHELLand warn, then invoke the default attribute access via super().Likewise, in the Git class itself, a __getatttribute__ override isintroduced (not to be confused with __getattr__, which was alreadypresent and handles attribute access when an attribute is otherwiseabsent, unlike __getattribute__ which is always used). This checksfor reading USE_SHELL on an instance and warns, then invokes thedefault attribute access via super().Advantages:- Git.USE_SHELL is again unittest.mock.patch patchable.- AttributeError messages are automatically as before.- It effectively is a simple attribute, yet with warning, so other unanticipated ways of accessing it may be less likely to break.- The code is simpler, cleaner, and clearer. There is some overhead, but it is small, especially compared to a subprocess invocation as is done for performing most git operations.However, this does introduce disadvantages that must be addressed:- Although attribute access on Git instances was already highly dynamic, as "methods" are synthesized for git subcommands, this was and is not the case for the Git class itself, whose attributes remain exactly those that can be inferred without considering the existence of __getattribute__ and __setattr__ on the metaclass. So static type checkers need to be prevented from accounting for those metaclass methods in a way that causes them to infer that arbitrary class attribute access is allowed.- The occurrence of Git.USE_SHELL in the Git.execute method (where the USE_SHELL attribute is actually examined) should be changed so it does not itself issue DeprecationWarning (it is not enough that by default a DeprecationWarning from there isn't displayed).1 parent05de5c0 commit04eb09c
1 file changed
+15
-18
lines changedLines changed: 15 additions & 18 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
55 | 55 |
| |
56 | 56 |
| |
57 | 57 |
| |
58 |
| - | |
59 | 58 |
| |
60 | 59 |
| |
61 | 60 |
| |
| |||
336 | 335 |
| |
337 | 336 |
| |
338 | 337 |
| |
339 |
| - | |
340 |
| - | |
341 |
| - | |
342 |
| - | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
343 | 342 |
| |
344 |
| - | |
345 |
| - | |
346 |
| - | |
347 |
| - | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
348 | 347 |
| |
349 | 348 |
| |
350 | 349 |
| |
| |||
397 | 396 |
| |
398 | 397 |
| |
399 | 398 |
| |
400 |
| - | |
401 |
| - | |
402 |
| - | |
| 399 | + | |
403 | 400 |
| |
404 | 401 |
| |
405 | 402 |
| |
| |||
909 | 906 |
| |
910 | 907 |
| |
911 | 908 |
| |
| 909 | + | |
| 910 | + | |
| 911 | + | |
| 912 | + | |
| 913 | + | |
912 | 914 |
| |
913 | 915 |
| |
914 | 916 |
| |
| |||
918 | 920 |
| |
919 | 921 |
| |
920 | 922 |
| |
921 |
| - | |
922 |
| - | |
923 |
| - | |
924 |
| - | |
925 |
| - | |
926 | 923 |
| |
927 | 924 |
| |
928 | 925 |
| |
| |||
1184 | 1181 |
| |
1185 | 1182 |
| |
1186 | 1183 |
| |
1187 |
| - | |
| 1184 | + | |
1188 | 1185 |
| |
1189 | 1186 |
| |
1190 | 1187 |
| |
|
0 commit comments
Comments
(0)