Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Type hinting RESTObject attributes #3086

Open
Labels
@igorp-collabora

Description

@igorp-collabora

Currently the all of RESTObject attributes are typed asAny by the__getattr__ method. This means there is no type hinting of any REST API objects such as Project:

fromgitlab.v4.objectsimportProjectfromtypingimportreveal_typedeftest(proj:Project)->None:reveal_type(proj.description)
$ mypy --follow-imports=silent typing_objects.pytyping_objects.py:6: note: Revealed type is "Any"

This also means accessing a non-existent attribute will also pass type checking:

fromgitlab.v4.objectsimportProjectfromtypingimportreveal_typedeftest(proj:Project)->None:reveal_type(proj.foobar_does_not_exist)
$ mypy --follow-imports=silent typing_objects.pytyping_objects.py:6: note: Revealed type is "Any"

One solution can be adding extra type annotation to the RESTObject subclass body:

classProject(RefreshMixin,SaveMixin,ObjectDeleteMixin,RepositoryMixin,UploadMixin,RESTObject):description:str
typing_objects.py:6: note: Revealed type is "builtins.str"

This does not fix the non-existent attribute issue but in a lot cases using Any will raise warning by type checker. (for example, returning Any)

Another question is having a source of information on the available attributes.The official documentation only provides examples of the JSON objects but does not document attributes in detail.There is an OpenAPI schema which can be used.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp