Skip to content

Commit e6eb2d8

Browse files
committed
fix any type issue
1 parent ea5e7f8 commit e6eb2d8

10 files changed

Lines changed: 27 additions & 24 deletions

File tree

src/pysonar_scanner/__main__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
1919
#
2020

21+
from typing import Any
2122
from pysonar_scanner import app_logging
2223
from pysonar_scanner import cache
2324
from pysonar_scanner.api import get_base_urls, SonarQubeApi, BaseUrls, MIN_SUPPORTED_SQ_VERSION
@@ -58,7 +59,7 @@ def set_logging_options(config):
5859
app_logging.configure_logging_level(verbose=config.get(SONAR_VERBOSE, False))
5960

6061

61-
def build_api(config: dict[str, any]) -> SonarQubeApi:
62+
def build_api(config: dict[str, Any]) -> SonarQubeApi:
6263
token = configuration_loader.get_token(config)
6364
base_urls = get_base_urls(config)
6465
return SonarQubeApi(base_urls, token)
@@ -90,7 +91,7 @@ def create_scanner_engine(api, cache_manager, config):
9091
return scanner
9192

9293

93-
def create_jre(api, cache, config: dict[str, any]) -> JREResolvedPath:
94+
def create_jre(api, cache, config: dict[str, Any]) -> JREResolvedPath:
9495
jre_provisioner = JREProvisioner(api, cache, config[SONAR_SCANNER_OS], config[SONAR_SCANNER_ARCH])
9596
jre_resolver = JREResolver(JREResolverConfiguration.from_dict(config), jre_provisioner)
9697
return jre_resolver.resolve_jre()

src/pysonar_scanner/api.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
#
2020
import typing
2121
from dataclasses import dataclass
22-
from typing import Optional, TypedDict
22+
from typing import Any, Optional, TypedDict
2323

2424
import requests
2525
import requests.auth
@@ -118,7 +118,7 @@ def from_dict(dict: dict) -> "JRE":
118118
)
119119

120120

121-
def to_api_configuration(config_dict: dict[Key, any]) -> ApiConfiguration:
121+
def to_api_configuration(config_dict: dict[Key, Any]) -> ApiConfiguration:
122122
return {
123123
SONAR_HOST_URL: config_dict.get(SONAR_HOST_URL, ""),
124124
SONAR_SCANNER_SONARCLOUD_URL: config_dict.get(SONAR_SCANNER_SONARCLOUD_URL, ""),
@@ -127,7 +127,7 @@ def to_api_configuration(config_dict: dict[Key, any]) -> ApiConfiguration:
127127
}
128128

129129

130-
def get_base_urls(config_dict: dict[Key, any]) -> BaseUrls:
130+
def get_base_urls(config_dict: dict[Key, Any]) -> BaseUrls:
131131
def is_sq_cloud_url(api_config: ApiConfiguration, sonar_host_url: str) -> bool:
132132
sq_cloud_url = api_config[SONAR_SCANNER_SONARCLOUD_URL] or GLOBAL_SONARCLOUD_URL
133133
return remove_trailing_slash(sonar_host_url) in [remove_trailing_slash(sq_cloud_url), US_SONARCLOUD_URL]

src/pysonar_scanner/configuration/cli.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
1919
#
2020
import argparse
21+
from typing import Any
2122

2223
from pysonar_scanner.configuration import properties
2324
from pysonar_scanner.exceptions import UnexpectedCliArgument
@@ -26,7 +27,7 @@
2627
class CliConfigurationLoader:
2728

2829
@classmethod
29-
def load(cls) -> dict[str, any]:
30+
def load(cls) -> dict[str, Any]:
3031
args, unknown_args = cls.__parse_cli_args()
3132
config = {}
3233
for prop in properties.PROPERTIES:

src/pysonar_scanner/configuration/configuration_loader.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
1919
#
2020
from pathlib import Path
21+
from typing import Any
2122

2223
from pysonar_scanner.configuration.cli import CliConfigurationLoader
2324
from pysonar_scanner.configuration.pyproject_toml import TomlConfigurationLoader
@@ -28,13 +29,13 @@
2829
from pysonar_scanner.exceptions import MissingKeyException
2930

3031

31-
def get_static_default_properties() -> dict[Key, any]:
32+
def get_static_default_properties() -> dict[Key, Any]:
3233
return {prop.name: prop.default_value for prop in PROPERTIES if prop.default_value is not None}
3334

3435

3536
class ConfigurationLoader:
3637
@staticmethod
37-
def load() -> dict[Key, any]:
38+
def load() -> dict[Key, Any]:
3839
# each property loader is required to return NO default values.
3940
# E.g. if no property has been set, an empty dict must be returned.
4041
# Default values should be set through the get_static_default_properties() method
@@ -57,7 +58,7 @@ def load() -> dict[Key, any]:
5758
return resolved_properties
5859

5960

60-
def get_token(config: dict[Key, any]) -> str:
61+
def get_token(config: dict[Key, Any]) -> str:
6162
if SONAR_TOKEN not in config:
6263
raise MissingKeyException(f'Missing property "{SONAR_TOKEN}"')
6364
return config[SONAR_TOKEN]

src/pysonar_scanner/configuration/dynamic_defaults_loader.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@
1818
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
1919
#
2020
import os
21-
from typing import Dict
21+
from typing import Any, Dict
2222

2323
from pysonar_scanner.configuration.properties import Key, SONAR_SCANNER_OS, SONAR_SCANNER_ARCH, SONAR_PROJECT_BASE_DIR
2424
from pysonar_scanner import utils
2525

2626

27-
def load() -> Dict[Key, any]:
27+
def load() -> Dict[Key, Any]:
2828
"""
2929
Load dynamically computed default properties
3030
"""

src/pysonar_scanner/configuration/properties.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import time
2121
import argparse
2222
from dataclasses import dataclass
23-
from typing import Callable, Optional
23+
from typing import Any, Callable, Optional
2424

2525
Key = str
2626

@@ -101,10 +101,10 @@ class Property:
101101
name: Key
102102
"""name in the format of `sonar.scanner.appVersion`"""
103103

104-
default_value: Optional[any]
104+
default_value: Optional[Any]
105105
"""default value for the property; if None, no default value is set"""
106106

107-
cli_getter: Optional[Callable[[argparse.Namespace], any]] = None
107+
cli_getter: Optional[Callable[[argparse.Namespace], Any]] = None
108108
"""function to get the value from the CLI arguments namespace. If None, the property is not settable via CLI"""
109109

110110
def python_name(self) -> str:

src/pysonar_scanner/configuration/pyproject_toml.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
1919
#
2020
from pathlib import Path
21-
from typing import Dict
21+
from typing import Any, Dict
2222
import os
2323
import tomli
2424

@@ -84,7 +84,7 @@ def __read_project_properties(toml_dict) -> Dict[str, str]:
8484
return project_properties
8585

8686
@staticmethod
87-
def __flatten_config_dict(config: dict[str, any], prefix: str) -> dict[str, any]:
87+
def __flatten_config_dict(config: dict[str, Any], prefix: str) -> dict[str, Any]:
8888
"""Flatten nested dictionaries into dot notation keys"""
8989
result = {}
9090
for key, value in config.items():

src/pysonar_scanner/jre.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import tarfile
2323
import zipfile
2424
from dataclasses import dataclass
25-
from typing import Optional
25+
from typing import Any, Optional
2626

2727
from pysonar_scanner import utils
2828
from pysonar_scanner.api import JRE, SonarQubeApi
@@ -139,7 +139,7 @@ class JREResolverConfiguration:
139139
sonar_scanner_os: Optional[str]
140140

141141
@staticmethod
142-
def from_dict(config_dict: dict[Key, any]) -> "JREResolverConfiguration":
142+
def from_dict(config_dict: dict[Key, Any]) -> "JREResolverConfiguration":
143143
return JREResolverConfiguration(
144144
sonar_scanner_java_exe_path=config_dict.get(SONAR_SCANNER_JAVA_EXE_PATH, None),
145145
sonar_scanner_skip_jre_provisioning=config_dict.get(SONAR_SCANNER_SKIP_JRE_PROVISIONING, False),

src/pysonar_scanner/scannerengine.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
from dataclasses import dataclass
2424
from subprocess import Popen, PIPE
2525
from threading import Thread
26-
from typing import IO, Callable, Optional
26+
from typing import IO, Any, Callable, Optional
2727

2828
from pysonar_scanner.api import SonarQubeApi
2929
from pysonar_scanner.cache import Cache, CacheFile
@@ -138,7 +138,7 @@ def __init__(self, jre_path: JREResolvedPath, scanner_engine_path: pathlib.Path)
138138
self.jre_path = jre_path
139139
self.scanner_engine_path = scanner_engine_path
140140

141-
def run(self, config: dict[str, any]):
141+
def run(self, config: dict[str, Any]):
142142
cmd = self.__build_command(self.jre_path, self.scanner_engine_path)
143143
properties_str = self.__config_to_json(config)
144144
return CmdExecutor(cmd, properties_str).execute()
@@ -150,6 +150,6 @@ def __build_command(self, jre_path: JREResolvedPath, scanner_engine_path: pathli
150150
cmd.append(scanner_engine_path)
151151
return cmd
152152

153-
def __config_to_json(self, config: dict[str, any]) -> str:
153+
def __config_to_json(self, config: dict[str, Any]) -> str:
154154
scanner_properties = [{"key": k, "value": v} for k, v in config.items()]
155155
return json.dumps({"scannerProperties": scanner_properties})

tests/unit/test_api.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
# along with this program; if not, write to the Free Software Foundation,
1818
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
1919
#
20-
from typing import TypedDict
20+
from typing import Any, TypedDict
2121

2222
import io
2323

@@ -73,7 +73,7 @@ def test_BaseUrls_normalization(self):
7373
def test_get_base_urls(self):
7474
class TestCaseDict(TypedDict):
7575
name: str
76-
config: dict[Key, any]
76+
config: dict[Key, Any]
7777
expected: BaseUrls
7878

7979
cases: list[TestCaseDict] = [
@@ -204,7 +204,7 @@ class TestCaseDict(TypedDict):
204204
def test_inconsistent_urls_raises_exception(self):
205205
class TestCaseDict(TypedDict):
206206
name: str
207-
config: dict[Key, any]
207+
config: dict[Key, Any]
208208
expected: str
209209

210210
cases: list[TestCaseDict] = [

0 commit comments

Comments
 (0)