- Notifications
You must be signed in to change notification settings - Fork675
Commit91c4f18
feat(api): Make RESTManager generic on RESTObject class
Currently mixins like ListMixin are type hinted to return baseRESTObject instead of a specific class like `MergeRequest`.The GetMixin and GetWithoutIdMixin solve this problem by defininga new `get` method for every defined class. However, this createsa lot of duplicated code.Make RESTManager use `typing.Generic` as its base class and useand assign the declared TypeVar to the `_obj_cls` attribute asa type of the passed class.Make both `_obj_cls` and `_path` attributes an abstract propertiesso that type checkers can check that those attributes were properlydefined in subclasses. Mypy will only check then the class isinstantiated which makes non-final subclasses possible.Unfortunately pylint will check the declarations not instantiationsso add `# pylint: disable=abstract-method` comments to all non-finalsubclasses like ListMixin.Make `_path` attribute always be `str` instead of sometimes `None`.This eliminates unnecessary type checks.Change all mixins like ListMixin or GetMixin to a subclass. This makesthe attribute declarations much cleaner as for example `_list_filters`is now the only attribute defined by ListMixin.Change SidekiqManager to not inherit from RESTManager and onlycopy its `__init__` method. This is because SidekiqManager neverwas a real manager and does not define `_path` or `_obj_cls`.Delete `tests/unit/meta/test_ensure_type_hints.py` file as the `get`method is no required to be defined for every class.Signed-off-by: Igor Ponomarev <igor.ponomarev@collabora.com>1 parent46dfc50 commit91c4f18
File tree
88 files changed
+748
-536
lines changed- gitlab
- v4
- objects
- tests
- functional/api
- unit
- meta
- mixins
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
88 files changed
+748
-536
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
8 | 19 | | |
9 | 20 | | |
10 | 21 | | |
| |||
48 | 59 | | |
49 | 60 | | |
50 | 61 | | |
51 | | - | |
| 62 | + | |
52 | 63 | | |
53 | 64 | | |
54 | 65 | | |
55 | | - | |
| 66 | + | |
56 | 67 | | |
57 | 68 | | |
58 | 69 | | |
| |||
269 | 280 | | |
270 | 281 | | |
271 | 282 | | |
272 | | - | |
| 283 | + | |
273 | 284 | | |
274 | 285 | | |
275 | 286 | | |
| |||
335 | 346 | | |
336 | 347 | | |
337 | 348 | | |
338 | | - | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
339 | 353 | | |
340 | 354 | | |
341 | 355 | | |
| |||
346 | 360 | | |
347 | 361 | | |
348 | 362 | | |
349 | | - | |
350 | | - | |
| 363 | + | |
| 364 | + | |
351 | 365 | | |
352 | 366 | | |
353 | 367 | | |
354 | | - | |
| 368 | + | |
355 | 369 | | |
356 | 370 | | |
357 | 371 | | |
| |||
371 | 385 | | |
372 | 386 | | |
373 | 387 | | |
374 | | - | |
| 388 | + | |
375 | 389 | | |
376 | 390 | | |
377 | 391 | | |
378 | | - | |
379 | | - | |
380 | 392 | | |
381 | 393 | | |
382 | 394 | | |
| |||
390 | 402 | | |
391 | 403 | | |
392 | 404 | | |
393 | | - | |
| 405 | + | |
394 | 406 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
397 | 397 | | |
398 | 398 | | |
399 | 399 | | |
400 | | - | |
401 | | - | |
| 400 | + | |
402 | 401 | | |
403 | 402 | | |
404 | | - | |
| 403 | + | |
405 | 404 | | |
406 | 405 | | |
407 | 406 | | |
| |||
0 commit comments
Comments
(0)