Use PY3 super() zero-argument syntax

This commit is contained in:
Ivan Kravets
2022-04-15 14:44:30 +03:00
parent eaff7f307c
commit 5a0a215bfc
35 changed files with 67 additions and 79 deletions

2
docs

Submodule docs updated: acdba4baec...c6172dcea4

View File

@ -632,7 +632,7 @@ class MbedLibBuilder(LibBuilderBase):
def process_extra_options(self):
self._process_mbed_lib_confs()
return super(MbedLibBuilder, self).process_extra_options()
return super().process_extra_options()
def _process_mbed_lib_confs(self):
mbed_lib_paths = [
@ -851,7 +851,7 @@ class ProjectAsLibBuilder(LibBuilderBase):
def __init__(self, env, *args, **kwargs):
# backup original value, will be reset in base.__init__
project_src_filter = env.get("SRC_FILTER")
super(ProjectAsLibBuilder, self).__init__(env, *args, **kwargs)
super().__init__(env, *args, **kwargs)
self.env["SRC_FILTER"] = project_src_filter
@property

View File

@ -40,7 +40,7 @@ class AccountClient(HTTPClient): # pylint:disable=too-many-public-methods
SUMMARY_CACHE_TTL = 60 * 60 * 24 * 7
def __init__(self):
super(AccountClient, self).__init__(__accounts_api__)
super().__init__(__accounts_api__)
@staticmethod
def get_refresh_token():
@ -63,7 +63,7 @@ class AccountClient(HTTPClient): # pylint:disable=too-many-public-methods
def fetch_json_data(self, *args, **kwargs):
try:
return super(AccountClient, self).fetch_json_data(*args, **kwargs)
return super().fetch_json_data(*args, **kwargs)
except HTTPClientError as exc:
raise AccountError(exc) from exc

View File

@ -28,7 +28,7 @@ from platformio.exception import PlatformioException, UserSideException
class HTTPClientError(PlatformioException):
def __init__(self, message, response=None):
super(HTTPClientError, self).__init__()
super().__init__()
self.message = message
self.response = response
@ -47,16 +47,14 @@ class InternetIsOffline(UserSideException):
class EndpointSession(requests.Session):
def __init__(self, base_url, *args, **kwargs):
super(EndpointSession, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)
self.base_url = base_url
def request( # pylint: disable=signature-differs,arguments-differ
self, method, url, *args, **kwargs
):
# print(self.base_url, method, url, args, kwargs)
return super(EndpointSession, self).request(
method, urljoin(self.base_url, url), *args, **kwargs
)
return super().request(method, urljoin(self.base_url, url), *args, **kwargs)
class EndpointSessionIterator(object):

View File

@ -21,7 +21,7 @@ from platformio.clients.http import HTTPClient, HTTPClientError
class RegistryClient(HTTPClient):
def __init__(self):
super(RegistryClient, self).__init__(__registry_api__)
super().__init__(__registry_api__)
@staticmethod
def allowed_private_packages():

View File

@ -22,7 +22,7 @@ class PlatformioCLI(click.MultiCommand):
leftover_args = []
def __init__(self, *args, **kwargs):
super(PlatformioCLI, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)
self._pio_cmds_dir = os.path.dirname(__file__)
@staticmethod
@ -41,7 +41,7 @@ class PlatformioCLI(click.MultiCommand):
PlatformioCLI.leftover_args = ctx.args
if hasattr(ctx, "protected_args"):
PlatformioCLI.leftover_args = ctx.protected_args + ctx.args
return super(PlatformioCLI, self).invoke(ctx)
return super().invoke(ctx)
def list_commands(self, ctx):
cmds = []

View File

@ -23,7 +23,7 @@ from platformio.commands.check.tools.base import CheckToolBase
class CppcheckCheckTool(CheckToolBase):
def __init__(self, *args, **kwargs):
super(CppcheckCheckTool, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)
self._field_delimiter = "<&PIO&>"
self._buffer = ""
self.defect_fields = [
@ -207,7 +207,7 @@ class CppcheckCheckTool(CheckToolBase):
return self._create_tmp_file("\n".join(result))
def clean_up(self):
super(CppcheckCheckTool, self).clean_up()
super().clean_up()
# delete temporary dump files generated by addons
if not self.is_flag_set("--addon", self.get_flags("cppcheck")):

View File

@ -27,7 +27,7 @@ from platformio.compat import IS_WINDOWS
class PvsStudioCheckTool(CheckToolBase): # pylint: disable=too-many-instance-attributes
def __init__(self, *args, **kwargs):
super(PvsStudioCheckTool, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)
self._tmp_dir = tempfile.mkdtemp(prefix="piocheck")
self._tmp_preprocessed_file = self._generate_tmp_file_path() + ".i"
self._tmp_output_file = self._generate_tmp_file_path() + ".pvs"
@ -208,7 +208,7 @@ class PvsStudioCheckTool(CheckToolBase): # pylint: disable=too-many-instance-at
self._bad_input = True
def clean_up(self):
super(PvsStudioCheckTool, self).clean_up()
super().clean_up()
if os.path.isdir(self._tmp_dir):
shutil.rmtree(self._tmp_dir)

View File

@ -21,7 +21,7 @@ class Hexlify(DeviceMonitorFilter):
NAME = "hexlify"
def __init__(self, *args, **kwargs):
super(Hexlify, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)
self._counter = 0
def rx(self, text):

View File

@ -23,7 +23,7 @@ class LogToFile(DeviceMonitorFilter):
NAME = "log2file"
def __init__(self, *args, **kwargs):
super(LogToFile, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)
self._log_fp = None
def __call__(self):

View File

@ -19,7 +19,7 @@ class SendOnEnter(DeviceMonitorFilter):
NAME = "send_on_enter"
def __init__(self, *args, **kwargs):
super(SendOnEnter, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)
self._buffer = ""
if self.options.get("eol") == "CR":

View File

@ -21,7 +21,7 @@ class Timestamp(DeviceMonitorFilter):
NAME = "time"
def __init__(self, *args, **kwargs):
super(Timestamp, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)
self._line_started = False
def rx(self, text):

View File

@ -26,7 +26,7 @@ class AsyncSession(requests.Session):
async def request( # pylint: disable=signature-differs,invalid-overridden-method
self, *args, **kwargs
):
func = super(AsyncSession, self).request
func = super().request
return await run_in_threadpool(func, *args, **kwargs)

View File

@ -25,7 +25,7 @@ class ProjectSyncAsyncCmd(AsyncCommandBase):
def __init__(self, *args, **kwargs):
self.psync = None
self._upstream = None
super(ProjectSyncAsyncCmd, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)
def start(self):
project_dir = os.path.join(

View File

@ -23,7 +23,7 @@ class SSLContextFactory(ssl.ClientContextFactory):
self.certificate_verified = False
def getContext(self):
ctx = super(SSLContextFactory, self).getContext()
ctx = super().getContext()
ctx.set_verify(
SSL.VERIFY_PEER | SSL.VERIFY_FAIL_IF_NO_PEER_CERT, self.verifyHostname
)

View File

@ -34,5 +34,5 @@ $INIT_BREAK
"""
def __init__(self, *args, **kwargs):
super(GenericDebugConfig, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)
self.port = ":3333"

View File

@ -38,11 +38,9 @@ $INIT_BREAK
"""
def __init__(self, *args, **kwargs):
super(JlinkDebugConfig, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)
self.port = ":2331"
@property
def server_ready_pattern(self):
return super(JlinkDebugConfig, self).server_ready_pattern or (
"Waiting for GDB connection"
)
return super().server_ready_pattern or ("Waiting for GDB connection")

View File

@ -32,5 +32,5 @@ $INIT_BREAK
"""
def __init__(self, *args, **kwargs):
super(MspdebugDebugConfig, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)
self.port = ":2000"

View File

@ -33,5 +33,5 @@ $INIT_BREAK
"""
def __init__(self, *args, **kwargs):
super(QemuDebugConfig, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)
self.port = ":1234"

View File

@ -35,11 +35,11 @@ monitor start
"""
def __init__(self, *args, **kwargs):
super(RenodeDebugConfig, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)
self.port = ":3333"
@property
def server_ready_pattern(self):
return super(RenodeDebugConfig, self).server_ready_pattern or (
return super().server_ready_pattern or (
"GDB server with all CPUs started on port"
)

View File

@ -27,7 +27,7 @@ from platformio.project.helpers import get_project_cache_dir
class DebugClientProcess(DebugBaseProcess):
def __init__(self, project_dir, debug_config):
super(DebugClientProcess, self).__init__()
super().__init__()
self.project_dir = project_dir
self.debug_config = debug_config
@ -55,7 +55,7 @@ class DebugClientProcess(DebugBaseProcess):
self.debug_config.port = await self._server_process.run()
def connection_made(self, transport):
super(DebugClientProcess, self).connection_made(transport)
super().connection_made(transport)
self._lock_session(transport.get_pid())
# Disable SIGINT and allow GDB's Ctrl+C interrupt
signal.signal(signal.SIGINT, lambda *args, **kwargs: None)
@ -64,7 +64,7 @@ class DebugClientProcess(DebugBaseProcess):
def process_exited(self):
if self._server_process:
self._server_process.terminate()
super(DebugClientProcess, self).process_exited()
super().process_exited()
def close(self):
self._unlock_session()

View File

@ -29,12 +29,12 @@ class GDBClientProcess(DebugClientProcess):
INIT_COMPLETED_BANNER = "PlatformIO: Initialization completed"
def __init__(self, *args, **kwargs):
super(GDBClientProcess, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)
self._target_is_running = False
self._errors_buffer = b""
async def run(self, extra_args): # pylint: disable=arguments-differ
await super(GDBClientProcess, self).run()
await super().run()
self.generate_init_script(os.path.join(self.working_dir, self.PIO_SRC_NAME))
gdb_path = self.debug_config.client_executable_path or "gdb"
@ -109,7 +109,7 @@ class GDBClientProcess(DebugClientProcess):
fp.write("\n".join(self.debug_config.reveal_patterns(commands)))
def stdin_data_received(self, data):
super(GDBClientProcess, self).stdin_data_received(data)
super().stdin_data_received(data)
if b"-exec-run" in data:
if self._target_is_running:
token, _ = data.split(b"-", 1)
@ -127,7 +127,7 @@ class GDBClientProcess(DebugClientProcess):
self.transport.get_pipe_transport(0).write(data)
def stdout_data_received(self, data):
super(GDBClientProcess, self).stdout_data_received(data)
super().stdout_data_received(data)
self._handle_error(data)
# go to init break automatically
if self.INIT_COMPLETED_BANNER.encode() in data:
@ -170,7 +170,7 @@ class GDBClientProcess(DebugClientProcess):
self._target_is_running = True
def stderr_data_received(self, data):
super(GDBClientProcess, self).stderr_data_received(data)
super().stderr_data_received(data)
self._handle_error(data)
def _handle_error(self, data):

View File

@ -30,7 +30,7 @@ class DebugServerProcess(DebugBaseProcess):
STD_BUFFER_SIZE = 1024
def __init__(self, debug_config):
super(DebugServerProcess, self).__init__()
super().__init__()
self.debug_config = debug_config
self._ready = False
self._std_buffer = {"out": b"", "err": b""}
@ -134,7 +134,7 @@ class DebugServerProcess(DebugBaseProcess):
return self._ready
def stdout_data_received(self, data):
super(DebugServerProcess, self).stdout_data_received(
super().stdout_data_received(
escape_gdbmi_stream("@", data) if is_gdbmi_mode() else data
)
self._std_buffer["out"] += data
@ -142,7 +142,7 @@ class DebugServerProcess(DebugBaseProcess):
self._std_buffer["out"] = self._std_buffer["out"][-1 * self.STD_BUFFER_SIZE :]
def stderr_data_received(self, data):
super(DebugServerProcess, self).stderr_data_received(data)
super().stderr_data_received(data)
self._std_buffer["err"] += data
self._check_ready_by_pattern(self._std_buffer["err"])
self._std_buffer["err"] = self._std_buffer["err"][-1 * self.STD_BUFFER_SIZE :]

View File

@ -22,7 +22,7 @@ class PlatformioException(Exception):
# pylint: disable=not-an-iterable
return self.MESSAGE.format(*self.args)
return super(PlatformioException, self).__str__()
return super().__str__()
class ReturnErrorCode(PlatformioException):

View File

@ -34,7 +34,7 @@ class ManifestParserError(ManifestException):
class ManifestValidationError(ManifestException):
def __init__(self, messages, data, valid_data):
super(ManifestValidationError, self).__init__()
super().__init__()
self.messages = messages
self.data = data
self.valid_data = valid_data

View File

@ -64,7 +64,7 @@ class PackageManagerInstallMixin(object):
# avoid circle dependencies
if not self._INSTALL_HISTORY:
self._INSTALL_HISTORY = {}
if spec in self._INSTALL_HISTORY:
if not force and spec in self._INSTALL_HISTORY:
return self._INSTALL_HISTORY[spec]
# check if package is already installed

View File

@ -24,7 +24,7 @@ from platformio.project.config import ProjectConfig
class LibraryPackageManager(BasePackageManager): # pylint: disable=too-many-ancestors
def __init__(self, package_dir=None):
super(LibraryPackageManager, self).__init__(
super().__init__(
PackageType.LIBRARY,
package_dir
or ProjectConfig.get_instance().get("platformio", "globallib_dir"),
@ -36,7 +36,7 @@ class LibraryPackageManager(BasePackageManager): # pylint: disable=too-many-anc
def find_pkg_root(self, path, spec):
try:
return super(LibraryPackageManager, self).find_pkg_root(path, spec)
return super().find_pkg_root(path, spec)
except MissingPackageManifestError:
pass
assert isinstance(spec, PackageSpec)
@ -86,5 +86,5 @@ class LibraryPackageManager(BasePackageManager): # pylint: disable=too-many-anc
if not any(not_builtin_conds):
not_builtin_conds.append(not is_builtin_lib(spec.name))
if any(not_builtin_conds):
return super(LibraryPackageManager, self).install_dependency(dependency)
return super().install_dependency(dependency)
return None

View File

@ -29,7 +29,7 @@ from platformio.project.config import ProjectConfig
class PlatformPackageManager(BasePackageManager): # pylint: disable=too-many-ancestors
def __init__(self, package_dir=None):
self.config = ProjectConfig.get_instance()
super(PlatformPackageManager, self).__init__(
super().__init__(
PackageType.PLATFORM,
package_dir or self.config.get("platformio", "platforms_dir"),
)
@ -47,16 +47,14 @@ class PlatformPackageManager(BasePackageManager): # pylint: disable=too-many-an
project_targets=None,
):
already_installed = self.get_package(spec)
pkg = super(PlatformPackageManager, self).install(
spec, force=force, skip_dependencies=True
)
pkg = super().install(spec, force=force, skip_dependencies=True)
try:
p = PlatformFactory.new(pkg)
# set logging level for underlying tool manager
p.pm.set_log_level(self.log.getEffectiveLevel())
p.ensure_engine_compatible()
except IncompatiblePlatform as e:
super(PlatformPackageManager, self).uninstall(pkg, skip_dependencies=True)
super().uninstall(pkg, skip_dependencies=True)
raise e
if project_env:
p.configure_project_packages(project_env, project_targets)
@ -79,9 +77,7 @@ class PlatformPackageManager(BasePackageManager): # pylint: disable=too-many-an
p.configure_project_packages(project_env)
if not skip_dependencies:
p.uninstall_packages()
assert super(PlatformPackageManager, self).uninstall(
pkg, skip_dependencies=True
)
assert super().uninstall(pkg, skip_dependencies=True)
p.on_uninstalled()
return pkg
@ -95,7 +91,7 @@ class PlatformPackageManager(BasePackageManager): # pylint: disable=too-many-an
pkg = self.get_package(from_spec)
if not pkg or not pkg.metadata:
raise UnknownPackageError(from_spec)
pkg = super(PlatformPackageManager, self).update(
pkg = super().update(
from_spec,
to_spec,
)

View File

@ -19,9 +19,11 @@ from platformio.project.config import ProjectConfig
class ToolPackageManager(BasePackageManager): # pylint: disable=too-many-ancestors
def __init__(self, package_dir=None):
if not package_dir:
package_dir = ProjectConfig.get_instance().get("platformio", "packages_dir")
super(ToolPackageManager, self).__init__(PackageType.TOOL, package_dir)
super().__init__(
PackageType.TOOL,
package_dir
or ProjectConfig.get_instance().get("platformio", "packages_dir"),
)
@property
def manifest_names(self):

View File

@ -59,9 +59,7 @@ class StrictListField(fields.List):
self, value, attr, data, **kwargs
):
try:
return super(StrictListField, self)._deserialize(
value, attr, data, **kwargs
)
return super()._deserialize(value, attr, data, **kwargs)
except ValidationError as exc:
if exc.data:
exc.data = [item for item in exc.data if item is not None]

View File

@ -91,7 +91,7 @@ class PackageOutdatedResult(object):
and not isinstance(value, semantic_version.Version)
):
value = cast_version_to_semver(str(value))
return super(PackageOutdatedResult, self).__setattr__(name, value)
return super().__setattr__(name, value)
@property
def update_increment_type(self):

View File

@ -57,9 +57,7 @@ class BaseArchiver(object):
class TARArchiver(BaseArchiver):
def __init__(self, archpath):
super(TARArchiver, self).__init__(
tarfile_open(archpath) # pylint: disable=consider-using-with
)
super().__init__(tarfile_open(archpath)) # pylint: disable=consider-using-with
def get_items(self):
return self._afo.getmembers()
@ -90,7 +88,7 @@ class TARArchiver(BaseArchiver):
self.is_link(item) and self.is_bad_link(item, dest_dir),
]
if not any(bad_conds):
super(TARArchiver, self).extract_item(item, dest_dir)
super().extract_item(item, dest_dir)
else:
click.secho(
"Blocked insecure item `%s` from TAR archive" % item.name,
@ -101,9 +99,7 @@ class TARArchiver(BaseArchiver):
class ZIPArchiver(BaseArchiver):
def __init__(self, archpath):
super(ZIPArchiver, self).__init__(
ZipFile(archpath) # pylint: disable=consider-using-with
)
super().__init__(ZipFile(archpath)) # pylint: disable=consider-using-with
@staticmethod
def preserve_permissions(item, dest_dir):

View File

@ -131,7 +131,7 @@ class GitClient(VCSClientBase):
def __init__(self, *args, **kwargs):
self.configure()
super(GitClient, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)
@classmethod
def configure(cls):

View File

@ -62,7 +62,7 @@ class BuildAsyncPipe(AsyncPipeBase):
def __init__(self, line_callback, data_callback):
self.line_callback = line_callback
self.data_callback = data_callback
super(BuildAsyncPipe, self).__init__()
super().__init__()
def do_reading(self):
line = ""
@ -95,7 +95,7 @@ class BuildAsyncPipe(AsyncPipeBase):
class LineBufferedAsyncPipe(AsyncPipeBase):
def __init__(self, line_callback):
self.line_callback = line_callback
super(LineBufferedAsyncPipe, self).__init__()
super().__init__()
def do_reading(self):
for line in iter(self._pipe_reader.readline, ""):

View File

@ -64,7 +64,7 @@ class MeasurementProtocol(TelemetryBase):
}
def __init__(self):
super(MeasurementProtocol, self).__init__()
super().__init__()
self["v"] = 1
self["tid"] = self.TID
self["cid"] = app.get_cid()
@ -82,12 +82,12 @@ class MeasurementProtocol(TelemetryBase):
def __getitem__(self, name):
if name in self.PARAMS_MAP:
name = self.PARAMS_MAP[name]
return super(MeasurementProtocol, self).__getitem__(name)
return super().__getitem__(name)
def __setitem__(self, name, value):
if name in self.PARAMS_MAP:
name = self.PARAMS_MAP[name]
super(MeasurementProtocol, self).__setitem__(name, value)
super().__setitem__(name, value)
def _prefill_appinfo(self):
self["av"] = __version__