Skip to content

Commit

Permalink
feat: add function overloading
Browse files Browse the repository at this point in the history
  • Loading branch information
anancarv authored Mar 18, 2021
2 parents ab2db16 + 7491681 commit 37783f3
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
26 changes: 25 additions & 1 deletion pyartifactory/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import logging
import os
from os.path import isdir, join
from typing import List, Optional, Dict, Tuple, Union, Iterator
from typing import List, Optional, Dict, Tuple, Union, Iterator, overload

from pathlib import Path
import requests
Expand Down Expand Up @@ -453,6 +453,18 @@ def get_repo(self, repo_name: str) -> AnyRepositoryResponse:
)
raise ArtifactoryException from error

@overload
def create_repo(self, repo: LocalRepository) -> LocalRepositoryResponse:
...

@overload
def create_repo(self, repo: VirtualRepository) -> VirtualRepositoryResponse:
...

@overload
def create_repo(self, repo: RemoteRepository) -> RemoteRepositoryResponse:
...

def create_repo(self, repo: AnyRepository) -> AnyRepositoryResponse:
"""
Creates a local, virtual or remote repository
Expand All @@ -476,6 +488,18 @@ def create_repo(self, repo: AnyRepository) -> AnyRepositoryResponse:
logger.debug("Repository %s successfully created", repo_name)
return self.get_repo(repo_name)

@overload
def update_repo(self, repo: LocalRepository) -> LocalRepositoryResponse:
...

@overload
def update_repo(self, repo: VirtualRepository) -> VirtualRepositoryResponse:
...

@overload
def update_repo(self, repo: RemoteRepository) -> RemoteRepositoryResponse:
...

def update_repo(self, repo: AnyRepository) -> AnyRepositoryResponse:
"""
Updates a local, virtual or remote repository
Expand Down
2 changes: 2 additions & 0 deletions tests/test_repositories.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ def test_create_local_repository_using_create_repo_success(mocker):
mocker.spy(artifactory_repo, "get_repo")
local_repo = artifactory_repo.create_repo(LOCAL_REPOSITORY)

assert isinstance(local_repo, LocalRepositoryResponse)
assert local_repo == LOCAL_REPOSITORY_RESPONSE


Expand Down Expand Up @@ -582,6 +583,7 @@ def test_update_local_repository_using_update_repo_success(mocker):
mocker.spy(artifactory_repo, "get_repo")
updated_repo = artifactory_repo.update_repo(UPDATED_LOCAL_REPOSITORY)

assert isinstance(updated_repo, LocalRepositoryResponse)
assert updated_repo == UPDATED_LOCAL_REPOSITORY_RESPONSE


Expand Down

0 comments on commit 37783f3

Please sign in to comment.