Skip to content
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

[Typing][A-70,A-71] Add type annotations for hub and sysconfig #65238

Merged
merged 1 commit into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
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
37 changes: 30 additions & 7 deletions python/paddle/hapi/hub.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,27 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import annotations

import os
import shutil
import sys
import zipfile
from typing import Any, List, Literal

from typing_extensions import TypeAlias

import paddle
from paddle.utils.download import get_path_from_url

__all__ = []

DEFAULT_CACHE_DIR = '~/.cache'
VAR_DEPENDENCY = 'dependencies'
MODULE_HUBCONF = 'hubconf.py'
HUB_DIR = os.path.expanduser(os.path.join('~', '.cache', 'paddle', 'hub'))
_Source: TypeAlias = Literal["github", "gitee", "local"]

DEFAULT_CACHE_DIR: str = '~/.cache'
VAR_DEPENDENCY: str = 'dependencies'
MODULE_HUBCONF: str = 'hubconf.py'
HUB_DIR: str = os.path.expanduser(os.path.join('~', '.cache', 'paddle', 'hub'))


def _remove_if_exists(path):
Expand Down Expand Up @@ -169,7 +177,11 @@ def _check_dependencies(m):
)


def list(repo_dir, source='github', force_reload=False):
def list(
repo_dir: str,
source: _Source = 'github',
force_reload: bool = False,
) -> List[str]: # noqa: UP006
r"""
List all entrypoints available in `github` hubconf.

Expand Down Expand Up @@ -215,7 +227,12 @@ def list(repo_dir, source='github', force_reload=False):
return entrypoints


def help(repo_dir, model, source='github', force_reload=False):
def help(
repo_dir: str,
model,
source: _Source = 'github',
force_reload: bool = False,
) -> str:
"""
Show help information of model

Expand Down Expand Up @@ -258,7 +275,13 @@ def help(repo_dir, model, source='github', force_reload=False):
return entry.__doc__


def load(repo_dir, model, source='github', force_reload=False, **kwargs):
def load(
repo_dir: str,
model: str,
source: _Source = 'github',
force_reload: bool = False,
**kwargs: Any,
) -> paddle.nn.Layer:
"""
Load model

Expand Down
6 changes: 4 additions & 2 deletions python/paddle/sysconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import annotations

import os

__all__ = ['get_include', 'get_lib']


def get_include():
def get_include() -> str:
"""
Get the directory containing the PaddlePaddle C++ header files.

Expand All @@ -36,7 +38,7 @@ def get_include():
return os.path.join(os.path.dirname(paddle.__file__), 'include')


def get_lib():
def get_lib() -> str:
"""
Get the directory containing the libpaddle_framework.

Expand Down