summaryrefslogtreecommitdiff
path: root/gitlab/base.py
Commit message (Collapse)AuthorAgeFilesLines
* chore: consolidate license and authorsNejc Habjan2022-08-041-17/+0
|
* chore: enable mypy check `warn_return_any`John L. Villalovos2022-07-281-3/+9
| | | | Update code so that the `warn_return_any` check passes.
* Merge pull request #1872 from python-gitlab/jlvillal/as_dictNejc Habjan2022-07-201-13/+19
|\ | | | | feat: add `asdict()` and `to_json()` methods to Gitlab Objects
| * feat: add `asdict()` and `to_json()` methods to Gitlab ObjectsJohn L. Villalovos2022-07-201-14/+18
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Add an `asdict()` method that returns a dictionary representation copy of the Gitlab Object. This is a copy and changes made to it will have no impact on the Gitlab Object. The `asdict()` method name was chosen as both the `dataclasses` and `attrs` libraries have an `asdict()` function which has the similar purpose of creating a dictionary represenation of an object. Also add a `to_json()` method that returns a JSON string representation of the object. Closes: #1116
| * fix: results returned by `attributes` property to show updatesJohn L. Villalovos2022-07-201-4/+6
| | | | | | | | | | | | | | | | | | Previously the `attributes` method would show the original values in a Gitlab Object even if they had been updated. Correct this so that the updated value will be returned. Also use copy.deepcopy() to ensure that modifying the dictionary returned can not also modify the object.
* | chore: add a `lazy` boolean attribute to `RESTObject`John L. Villalovos2022-07-201-0/+9
|/ | | | | | | | This can be used to tell if a `RESTObject` was created using `lazy=True`. Add a message to the `AttributeError` if attribute access fails for an instance created with `lazy=True`.
* Merge pull request #2114 from python-gitlab/jlvillal/remove_trysNejc Habjan2022-07-041-40/+36
|\ | | | | chore: simplify multi-nested try blocks
| * chore: simplify multi-nested try blocksJohn L. Villalovos2022-06-291-40/+36
| | | | | | | | | | Instead of have a multi-nested series of try blocks. Convert it to a more readable series of `if` statements.
* | fix: ensure path elements are escapedJohn L. Villalovos2022-07-031-4/+6
|/ | | | | | | Ensure the path elements that are passed to the server are escaped. For example a "/" will be changed to "%2F" Closes: #2116
* fix(base): do not fail repr() on lazy objectsNejc Habjan2022-06-201-4/+11
|
* chore: require f-stringsJohn L. Villalovos2022-06-011-3/+3
| | | | | We previously converted all string formatting to use f-strings. Enable pylint check to enforce this.
* chore: move `RequiredOptional` to the `gitlab.types` moduleJohn L. Villalovos2022-05-311-11/+3
| | | | | | By having `RequiredOptional` in the `gitlab.base` module it makes it difficult with circular imports. Move it to the `gitlab.types` module which has no dependencies on any other gitlab module.
* feat: display human-readable attribute in `repr()` if presentNejc Habjan2022-05-081-5/+18
|
* chore: correct type-hints for per_page attrbuteJohn L. Villalovos2022-02-051-1/+1
| | | | | | | There are occasions where a GitLab `list()` call does not return the `x-per-page` header. For example the listing of custom attributes. Update the type-hints to reflect that.
* chore: use dataclass for RequiredOptionalNejc Habjan2022-01-231-2/+4
|
* chore: don't explicitly pass args to super()Nejc Habjan2022-01-231-4/+4
|
* style: use literals to declare data structuresNejc Habjan2022-01-231-2/+2
|
* chore: remove old-style classesNejc Habjan2022-01-231-3/+3
|
* chore: create return type-hints for `get_id()` & `encoded_id`John L. Villalovos2022-01-141-3/+3
| | | | | | Create return type-hints for `RESTObject.get_id()` and `RESTObject.encoded_id`. Previously was saying they return Any. Be more precise in saying they can return either: None, str, or int.
* chore: replace usage of utils._url_encode() with utils.EncodedId()jlvillal/encoded_idJohn L. Villalovos2022-01-131-1/+1
| | | | | | utils.EncodedId() has basically the same functionalityy of using utils._url_encode(). So remove utils._url_encode() as we don't need it.
* fix: use url-encoded ID in all pathsJohn L. Villalovos2022-01-131-0/+9
| | | | | | | | | | | | Make sure all usage of the ID in the URL path is encoded. Normally it isn't an issue as most IDs are integers or strings which don't contain a slash ('/'). But when the ID is a string with a slash character it will break things. Add a test case that shows this fixes wikis issue with subpages which use the slash character. Closes: #1079
* fix: broken URL for FAQ about attribute-error-listJohn L. Villalovos2022-01-091-1/+1
| | | | | | | | | | | | | | The URL was missing a 'v' before the version number and thus the page did not exist. Previously the URL for python-gitlab 3.0.0 was: https://python-gitlab.readthedocs.io/en/3.0.0/faq.html#attribute-error-list Which does not exist. Change it to: https://python-gitlab.readthedocs.io/en/v3.0.0/faq.html#attribute-error-list add the 'v' --------------------------^
* chore: add `pprint()` and `pformat()` methods to RESTObjectJohn L. Villalovos2022-01-081-0/+9
| | | | | This is useful in debugging and testing. As can easily print out the values from an instance in a more human-readable form.
* fix: handle situation where GitLab does not return valuesjlvillal/paginationJohn L. Villalovos2021-12-301-2/+2
| | | | | | | | | | | | | | | | If a query returns more than 10,000 records than the following values are NOT returned: x.total_pages x.total Modify the code to allow no value to be set for these values. If there is not a value returned the functions will now return None. Update unit test so no longer `xfail` https://docs.gitlab.com/ee/user/gitlab_com/index.html#pagination-response-headers Closes #1686
* Merge pull request #1709 from python-gitlab/docs/sphinx-annotationsNejc Habjan2021-12-011-2/+1
|\ | | | | docs: only use type annotations for documentation
| * docs: only use type annotations for documentationNejc Habjan2021-11-281-2/+1
| |
* | chore: attempt to be more informative for missing attributesjlvillal/attribute_helpJohn L. Villalovos2021-11-301-4/+34
|/ | | | | | | | | | | | | | | | A commonly reported issue from users on Gitter is that they get an AttributeError for an attribute that should be present. This is often caused due to the fact that they used the `list()` method to retrieve the object and objects retrieved this way often only have a subset of the full data. Add more details in the AttributeError message that explains the situation to users. This will hopefully allow them to resolve the issue. Update the FAQ in the docs to add a section discussing the issue. Closes #1138
* chore: fix issue with adding type-hints to 'manager' attributeJohn L. Villalovos2021-11-211-0/+4
| | | | | | | | | | | | When attempting to add type-hints to the the 'manager' attribute into a RESTObject derived class it would break things. This was because our auto-manager creation code would automatically add the specified annotated manager to the 'manager' attribute. This breaks things. Now check in our auto-manager creation if our attribute is called 'manager'. If so we ignore it.
* refactor: use new-style formatting for named placeholdersNejc Habjan2021-11-081-1/+1
|
* refactor: use f-strings for string formattingNejc Habjan2021-11-051-7/+3
|
* docs: fix a few typosTim Gates2021-09-191-1/+1
| | | | | | | | | | | | | | | | | | | | | | | There are small typos in: - docs/gl_objects/deploy_tokens.rst - gitlab/base.py - gitlab/mixins.py - gitlab/v4/objects/features.py - gitlab/v4/objects/groups.py - gitlab/v4/objects/packages.py - gitlab/v4/objects/projects.py - gitlab/v4/objects/sidekiq.py - gitlab/v4/objects/todos.py Fixes: - Should read `treatment` rather than `reatment`. - Should read `transferred` rather than `transfered`. - Should read `registered` rather than `registred`. - Should read `occurred` rather than `occured`. - Should read `overridden` rather than `overriden`. - Should read `marked` rather than `maked`. - Should read `instantiate` rather than `instanciate`. - Should read `function` rather than `fonction`.
* chore: convert to using type-annotations for managersJohn L. Villalovos2021-09-081-5/+13
| | | | | | | | | | | | | Convert our manager usage to be done via type annotations. Now to define a manager to be used in a RESTObject subclass can simply do: class ExampleClass(CRUDMixin, RESTObject): my_manager: MyManager Any type-annotation that annotates it to be of type *Manager (with the exception of RESTManager) will cause the manager to be created on the object.
* chore: improve type-hinting for managersJohn L. Villalovos2021-09-071-2/+3
| | | | | | | | | | | | | | | The 'managers' are dynamically created. This unfortunately means that we don't have any type-hints for them and so editors which understand type-hints won't know that they are valid attributes. * Add the type-hints for the managers we define. * Add a unit test that makes sure that the type-hints and the '_managers' attribute are kept in sync with each other. * Add unit test that makes sure specified managers in '_managers' have a name ending in 'Managers' to keep with current convention. * Make RESTObject._managers always present with a default value of None. * Fix a type-issue revealed now that mypy knows what the type is
* fix: catch invalid type used to initialize RESTObjectJohn L. Villalovos2021-06-101-0/+7
| | | | | | | | Sometimes we have errors where we don't get a dictionary passed to RESTObject.__init__() method. This breaks things but in confusing ways. Check in the __init__() method and raise an exception if it occurs.
* chore: fix import ordering using isortJohn L. Villalovos2021-05-251-1/+2
| | | | | | Fix the import ordering using isort. https://pycqa.github.io/isort/
* chore: mypy: Disallow untyped definitionsJohn L. Villalovos2021-04-271-6/+6
| | | | | | | | | Be more strict and don't allow untyped definitions on the files we check. Also this adds type-hints for two of the decorators so that now functions/methods decorated by them will have their types be revealed correctly.
* chore: make RESTObject._short_print_attrs always presentJohn L. Villalovos2021-04-241-0/+1
| | | | | | | | Always create RESTObject._short_print_attrs with a default value of None. This way we don't need to use hasattr() and we will know the type of the attribute.
* Merge pull request #1383 from spyoungtech/dirfixNejc Habjan2021-04-211-1/+1
|\ | | | | fix(types): prevent __dir__ in RestObject from producing duplicates
| * fix(types): prevent __dir__ from producing duplicatesSpencer Young2021-03-231-1/+1
| |
* | chore: have _create_attrs & _update_attrs be a namedtupleJohn L. Villalovos2021-04-171-3/+9
|/ | | | | | Convert _create_attrs and _update_attrs to use a NamedTuple (RequiredOptional) to help with code readability. Update all code to use the NamedTuple.
* chore: add _create_attrs & _update_attrs to RESTManagerJohn L. Villalovos2021-03-101-1/+3
| | | | | | | Add the attributes: _create_attrs and _update_attrs to the RESTManager class. This is so that we stop using getattr() if we don't need to. This also helps with type-hints being available for these attributes.
* fix: checking if RESTManager._from_parent_attrs is setJohn L. Villalovos2021-03-071-2/+2
| | | | | | | | | | | | Prior to commit 3727cbd21fc40b312573ca8da56e0f6cf9577d08 RESTManager._from_parent_attrs did not exist unless it was explicitly set. But commit 3727cbd21fc40b312573ca8da56e0f6cf9577d08 set it to a default value of {}. So the checks using hasattr() were no longer valid. Update the checks to check if RESTManager._from_parent_attrs has a value.
* chore: make _types always present in RESTManagerJohn L. Villalovos2021-03-071-0/+2
| | | | | | | | | | We now create _types = {} in RESTManager class. By making _types always present in RESTManager it makes the code simpler. We no longer have to do: types = getattr(self, "_types", {}) And the type checker now understands the type.
* chore: add type hints to gitlab/base.py:RESTManagerJohn L. Villalovos2021-03-011-0/+5
| | | | Add some additional type hints to gitlab/base.py
* chore: disallow incomplete type defsJohn L. Villalovos2021-02-281-4/+8
| | | | | | | | | | Don't allow a partially annotated function definition. Either none of the function is annotated or all of it must be. Update code to ensure no-more partially annotated functions. Update gitlab/cli.py with better type-hints. Changed Tuple[Any, ...] to Tuple[str, ...]
* chore: add additional type-hints for gitlab/base.pyJohn L. Villalovos2021-02-271-1/+7
| | | | | | | Add type-hints for the variables which are set via self.__dict__ mypy doesn't see them when they are assigned via self.__dict__. So declare them in the class definition.
* Merge pull request #1339 from JohnVillalovos/jlvillal/mypy_client_pyMax Wittig2021-02-271-2/+2
|\ | | | | chore: add type-hints to gitlab/client.py
| * chore: add type-hints to gitlab/client.pyJohn L. Villalovos2021-02-261-2/+2
| | | | | | | | Adding some initial type-hints to gitlab/client.py
* | chore: improve type-hints for gitlab/base.pyJohn L. Villalovos2021-02-261-3/+5
|/ | | | Determined the base class for obj_cls and adding type-hints for it.
* chore: add type hints to gitlab/base.pyJohn L. Villalovos2021-02-221-29/+34
|