Skip to content

[python-jenkins] Improve get_jobs and get_all_jobs return type #14547

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions stubs/python-jenkins/jenkins/__init__.pyi
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from _typeshed import Incomplete
from collections.abc import Mapping, MutableMapping, Sequence
from re import Pattern
from typing import Any, Final, Literal, overload
from typing_extensions import TypeAlias, deprecated
from typing import Any, Final, Literal, TypedDict, overload, type_check_only
from typing_extensions import Required, TypeAlias, deprecated

import requests
from requests.models import Request, Response
Expand Down Expand Up @@ -92,6 +92,15 @@ class WrappedSession(requests.Session):
_JSONValue: TypeAlias = Any # too many possibilities to express
_JSON: TypeAlias = dict[str, _JSONValue]

@type_check_only
class _Job(TypedDict, total=False):
_class: str
url: str
color: str
Comment on lines +98 to +99
Copy link
Member

@brianschubert brianschubert Aug 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Considering the docs say

Each job is a dictionary with ‘name’, ‘url’, ‘color’ and ‘fullname’ keys.

I think url and color can be made required as well?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that it could be true for url but I have seen many job objects in the response that does not have color attribute

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Besides, I also observe in my example that _class is always present. So, it could finally be:

@type_check_only
class _Job(TypedDict, total=False):
    _class: Required[str]
    url: Required[str]
    color: str
    name: Required[str]
    fullname: Required[str]
    jobs: list[_Job]

What do you think?

name: Required[str]
fullname: Required[str]
jobs: list[_Job]

class Jenkins:
server: str
auth: _Auth | None
Expand Down Expand Up @@ -128,10 +137,8 @@ class Jenkins:
def get_plugins_info(self, depth: int = 2) -> _JSON: ...
def get_plugin_info(self, name: str, depth: int = 2) -> _JSON: ...
def get_plugins(self, depth: int = 2) -> _JSON: ...
def get_jobs(
self, folder_depth: int = 0, folder_depth_per_request: int = 10, view_name: str | None = None
) -> list[dict[str, str]]: ...
def get_all_jobs(self, folder_depth: int | None = None, folder_depth_per_request: int = 10) -> list[dict[str, str]]: ...
def get_jobs(self, folder_depth: int = 0, folder_depth_per_request: int = 10, view_name: str | None = None) -> list[_Job]: ...
def get_all_jobs(self, folder_depth: int | None = None, folder_depth_per_request: int = 10) -> list[_Job]: ...
def copy_job(self, from_name: str, to_name: str) -> None: ...
def rename_job(self, from_name: str, to_name: str) -> None: ...
def delete_job(self, name: str) -> None: ...
Expand Down
Loading