summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorNejc Habjan <nejc.habjan@siemens.com>2022-10-22 16:02:45 +0200
committerJohn Villalovos <john@sodarock.com>2022-10-27 08:06:52 -0700
commita40415290923d69d087dd292af902efbdfb5c258 (patch)
tree87b5c59f9ac04cbb7d1b2072405e3f6cbd0520ab /docs
parent5b642a5d4c934f0680fa99079484176d36641861 (diff)
downloadgitlab-a40415290923d69d087dd292af902efbdfb5c258.tar.gz
docs(advanced): add hint on type narrowing
Diffstat (limited to 'docs')
-rw-r--r--docs/api-usage-advanced.rst20
1 files changed, 20 insertions, 0 deletions
diff --git a/docs/api-usage-advanced.rst b/docs/api-usage-advanced.rst
index db65c66..2382b49 100644
--- a/docs/api-usage-advanced.rst
+++ b/docs/api-usage-advanced.rst
@@ -161,3 +161,23 @@ parameter to that API invocation:
gl = gitlab.gitlab(url, token, api_version=4)
gl.projects.import_github(ACCESS_TOKEN, 123456, "root", timeout=120.0)
+
+Typing
+------
+
+Generally, ``python-gitlab`` is a fully typed package. However, currently you may still
+need to do some
+`type narrowing <https://mypy.readthedocs.io/en/stable/type_narrowing.html#type-narrowing>`_
+on your own, such as for nested API responses and ``Union`` return types. For example:
+
+.. code-block:: python
+
+ from typing import TYPE_CHECKING
+
+ import gitlab
+
+ gl = gitlab.gitlab(url, token, api_version=4)
+ license = gl.get_license()
+
+ if TYPE_CHECKING:
+ assert isinstance(license["plan"], str)