Skip to content

Commit a2519c2

Browse files
azure-sdkmsyyc
andauthored
[AutoRelease] t2-network-2023-06-26-52251(can only be merged by SDK owner) (Azure#30882)
* code and test * update * update --------- Co-authored-by: PythonSdkPipelines <PythonSdkPipelines> Co-authored-by: Yuchao Yan <yuchaoyan@microsoft.com>
1 parent 7738969 commit a2519c2

File tree

7 files changed

+721
-710
lines changed

7 files changed

+721
-710
lines changed

sdk/network/azure-mgmt-network/_meta.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"commit": "1b33e81bbdc28fcd6644a1315b8d7b1b6d030590",
2+
"commit": "02acc29a5618a6998469a7fcc750e301f130a19f",
33
"repository_url": "https://github.com/Azure/azure-rest-api-specs",
44
"autorest": "3.9.2",
55
"use": [

sdk/network/azure-mgmt-network/azure/mgmt/network/_client.py

Lines changed: 155 additions & 155 deletions
Large diffs are not rendered by default.
Lines changed: 25 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,49 @@
1-
2-
31
# --------------------------------------------------------------------------
42
# Copyright (c) Microsoft Corporation. All rights reserved.
53
# Licensed under the MIT License. See License.txt in the project root for license information.
64
# Code generated by Microsoft (R) Python Code Generator.
75
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
86
# --------------------------------------------------------------------------
9-
from typing import Optional, Dict, List
7+
import functools
108

119

12-
class api_version_validation:
13-
def __init__(
14-
self,
15-
*,
16-
api_versions: Optional[List[str]] = None,
17-
params: Optional[Dict[str, List[str]]] = None,
18-
):
19-
self.api_versions = api_versions or []
20-
self.params = params or {}
10+
def api_version_validation(**kwargs):
11+
params_valid_on = kwargs.pop("params_valid_on", {})
12+
method_valid_on = kwargs.pop("method_valid_on", {})
2113

22-
def __call__(self, func):
23-
api_versions = self.api_versions
24-
params = self.params
25-
def wrapper(self, *args, **kwargs):
14+
def decorator(func):
15+
@functools.wraps(func)
16+
def wrapper(*args, **kwargs):
2617
func_name = func.__name__
27-
if hasattr(self, "_get_api_version"):
28-
client_api_version = self._get_api_version(func_name)
29-
else:
30-
client_api_version = self._api_version
31-
if api_versions and client_api_version not in api_versions:
18+
try:
19+
client = args[0]
20+
client_api_version = client._get_api_version(func_name) # pylint: disable=protected-access
21+
except AttributeError:
22+
client_api_version = client._api_version # pylint: disable=protected-access
23+
24+
if method_valid_on and client_api_version not in method_valid_on:
3225
raise ValueError(
3326
f"'{func_name}' is not available in API version "
34-
f"{client_api_version}. Pass service API version {api_versions[0]} or newer to your client."
27+
f"{client_api_version}. All valid API version are {', '.join(method_valid_on)}."
3528
)
36-
unsupported = [
37-
parameter
38-
for parameter, api_versions in params.items()
29+
30+
unsupported = {
31+
parameter: ", ".join(api_versions)
32+
for parameter, api_versions in params_valid_on.items()
3933
if parameter in kwargs and client_api_version not in api_versions
40-
]
34+
}
4135
if unsupported:
4236
raise ValueError(
4337
"".join(
4438
[
4539
f"'{param}' is not available in API version {client_api_version}. "
46-
f"Use service API version {params[param][0]} or newer.\n"
47-
for param, version in unsupported
40+
f"All valid API version are {versions} \n"
41+
for param, versions in unsupported.items()
4842
]
4943
)
5044
)
51-
return func(self, *args, **kwargs)
45+
return func(*args, **kwargs)
5246

5347
return wrapper
48+
49+
return decorator

0 commit comments

Comments
 (0)