Skip to content

Commit a404152

Browse files
nejchJohnVillalovos
authored andcommitted
docs(advanced): add hint on type narrowing
1 parent 5b642a5 commit a404152

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

docs/api-usage-advanced.rst

+20
Original file line numberDiff line numberDiff line change
@@ -161,3 +161,23 @@ parameter to that API invocation:
161161
162162
gl = gitlab.gitlab(url, token, api_version=4)
163163
gl.projects.import_github(ACCESS_TOKEN, 123456, "root", timeout=120.0)
164+
165+
Typing
166+
------
167+
168+
Generally, ``python-gitlab`` is a fully typed package. However, currently you may still
169+
need to do some
170+
`type narrowing <https://mypy.readthedocs.io/en/stable/type_narrowing.html#type-narrowing>`_
171+
on your own, such as for nested API responses and ``Union`` return types. For example:
172+
173+
.. code-block:: python
174+
175+
from typing import TYPE_CHECKING
176+
177+
import gitlab
178+
179+
gl = gitlab.gitlab(url, token, api_version=4)
180+
license = gl.get_license()
181+
182+
if TYPE_CHECKING:
183+
assert isinstance(license["plan"], str)

0 commit comments

Comments
 (0)