Commit 4e3fe18
committed
feat(api): Make RESTManager generic on RESTObject class
Currently mixins like ListMixin are type hinted to return base
RESTObject instead of a specific class like `MergeRequest`.
The GetMixin and GetWithoutIdMixin solve this problem by defining
a new `get` method for every defined class. However, this creates
a lot of duplicated code.
Make RESTManager use `typing.Generic` as its base class and use
and assign the declared TypeVar to the `_obj_cls` attribute as
a type of the passed class.
Make both `_obj_cls` and `_path` attributes an abstract properties
so that type checkers can check that those attributes were properly
defined in subclasses. Mypy will only check then the class is
instantiated which makes non-final subclasses possible.
Unfortunately pylint will check the declarations not instantiations
so add `# pylint: disable=abstract-method` comments to all non-final
subclasses 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 makes
the 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 only
copy its `__init__` method. This is because SidekiqManager never
was 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 <[email protected]>1 parent 0c1af08 commit 4e3fe18
File tree
87 files changed
+775
-1473
lines changed- gitlab
- v4
- objects
- tests/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.
87 files changed
+775
-1473
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
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 | | - | |
351 | 363 | | |
352 | 364 | | |
353 | 365 | | |
354 | | - | |
| 366 | + | |
355 | 367 | | |
356 | 368 | | |
357 | 369 | | |
358 | 370 | | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
359 | 379 | | |
360 | 380 | | |
361 | 381 | | |
| |||
371 | 391 | | |
372 | 392 | | |
373 | 393 | | |
374 | | - | |
| 394 | + | |
375 | 395 | | |
376 | 396 | | |
377 | 397 | | |
378 | | - | |
379 | | - | |
380 | 398 | | |
381 | 399 | | |
382 | 400 | | |
| |||
390 | 408 | | |
391 | 409 | | |
392 | 410 | | |
393 | | - | |
| 411 | + | |
394 | 412 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
397 | 397 | | |
398 | 398 | | |
399 | 399 | | |
400 | | - | |
| 400 | + | |
| 401 | + | |
401 | 402 | | |
402 | | - | |
403 | | - | |
| 403 | + | |
| 404 | + | |
404 | 405 | | |
405 | 406 | | |
406 | 407 | | |
| |||
0 commit comments