Skip to content

Commit

Permalink
style: fix pylint and mypy issues
Browse files Browse the repository at this point in the history
- remove Python 2 bits as minimal supported version is Python 3.9
- silence linters for incomplete stub classes for failed imports
- minor type annotations fixes
  • Loading branch information
tomjelinek committed Jan 12, 2024
1 parent 9e282f1 commit ca44425
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 16 deletions.
14 changes: 10 additions & 4 deletions library/pcs_api_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@
"""

import traceback
from typing import Optional

from ansible.module_utils.basic import AnsibleModule

Expand All @@ -128,13 +129,18 @@
from pcs.common.async_tasks.dto import CommandDto, CommandOptionsDto
except ImportError:
HAS_PCS = False
PCS_IMPORT_ERROR = traceback.format_exc()
PCS_IMPORT_ERROR: Optional[str] = traceback.format_exc()

Check notice

Code scanning / CodeQL

Unused global variable Note

The global variable 'PCS_IMPORT_ERROR' is not used.

Check warning on line 132 in library/pcs_api_v2.py

View check run for this annotation

Codecov / codecov/patch

library/pcs_api_v2.py#L132

Added line #L132 was not covered by tests

class CommandOptionsDto(object):
def __init__(self, **kwargs):
# These classes need to be available and imported above to do linting
# properly, linters can be safely silenced for these stubs.

# pylint: disable=missing-class-docstring
# pylint: disable=too-few-public-methods
class CommandOptionsDto: # type: ignore
def __init__(self, **kwargs): # type: ignore

Check warning on line 140 in library/pcs_api_v2.py

View check run for this annotation

Codecov / codecov/patch

library/pcs_api_v2.py#L139-L140

Added lines #L139 - L140 were not covered by tests
pass

class CommandDto(object):
class CommandDto: # type: ignore

Check warning on line 143 in library/pcs_api_v2.py

View check run for this annotation

Codecov / codecov/patch

library/pcs_api_v2.py#L143

Added line #L143 was not covered by tests
pass

else:
Expand Down
14 changes: 10 additions & 4 deletions library/pcs_qdevice_certs.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@
"""

import traceback
from typing import Optional

from ansible.module_utils.basic import AnsibleModule

Expand All @@ -120,13 +121,18 @@
from pcs.common.async_tasks.dto import CommandDto, CommandOptionsDto
except ImportError:
HAS_PCS = False
PCS_IMPORT_ERROR = traceback.format_exc()
PCS_IMPORT_ERROR: Optional[str] = traceback.format_exc()

Check notice

Code scanning / CodeQL

Unused global variable Note

The global variable 'PCS_IMPORT_ERROR' is not used.

Check warning on line 124 in library/pcs_qdevice_certs.py

View check run for this annotation

Codecov / codecov/patch

library/pcs_qdevice_certs.py#L124

Added line #L124 was not covered by tests

class CommandOptionsDto(object):
def __init__(self, **kwargs):
# These classes need to be available and imported above to do linting
# properly, linters can be safely silenced for these stubs.

# pylint: disable=missing-class-docstring
# pylint: disable=too-few-public-methods
class CommandOptionsDto: # type: ignore
def __init__(self, **kwargs): # type: ignore

Check warning on line 132 in library/pcs_qdevice_certs.py

View check run for this annotation

Codecov / codecov/patch

library/pcs_qdevice_certs.py#L131-L132

Added lines #L131 - L132 were not covered by tests
pass

class CommandDto(object):
class CommandDto: # type: ignore

Check warning on line 135 in library/pcs_qdevice_certs.py

View check run for this annotation

Codecov / codecov/patch

library/pcs_qdevice_certs.py#L135

Added line #L135 was not covered by tests
pass

else:
Expand Down
21 changes: 13 additions & 8 deletions module_utils/ha_cluster_lsr/pcs_api_v2_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

from http.client import HTTPResponse
from json import JSONDecodeError
from typing import Any, Mapping, Union
from typing import Any, Mapping, Optional, Union

from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.urls import fetch_url
Expand All @@ -30,7 +30,7 @@
from dacite import DaciteError
except ImportError:
HAS_DACITE = False
DACITE_IMPORT_ERROR = traceback.format_exc()
DACITE_IMPORT_ERROR: Optional[str] = traceback.format_exc()
else:
HAS_DACITE = True
DACITE_IMPORT_ERROR = None
Expand All @@ -46,19 +46,24 @@
from pcs.common.reports import ReportItemDto, ReportItemSeverity
except ImportError:
HAS_PCS = False
PCS_IMPORT_ERROR = traceback.format_exc()
PCS_IMPORT_ERROR: Optional[str] = traceback.format_exc()

class CommandOptionsDto(object):
def __init__(self, **kwargs):
# These classes need to be available and imported above to do linting
# properly, linters can be safely silenced for these stubs.

# pylint: disable=missing-class-docstring
# pylint: disable=too-few-public-methods
class CommandOptionsDto: # type: ignore
def __init__(self, **kwargs): # type: ignore
pass

class ReportItemDto(object):
class ReportItemDto: # type: ignore
pass

class TaskResultDto(object):
class TaskResultDto: # type: ignore
pass

class CommandDto(object):
class CommandDto: # type: ignore
pass

else:
Expand Down

0 comments on commit ca44425

Please sign in to comment.