GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — docs(advanced): add hint on type narrowing · mkarthiatgithub/python-gitlab@a404152

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • docs
    • api-usage-advanced.rst
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎docs/api-usage-advanced.rst‎

Copy file name to clipboardExpand all lines: docs/api-usage-advanced.rst
+20Lines changed: 20 additions & 0 deletions
  • Display the source diff
  • Display the rich diff
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 (0)
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.