Fix issues reported by mypy (#83413)

pull/81452/merge
Matt Clay 6 months ago committed by GitHub
parent 6ab26707de
commit 531bc9891f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -1914,7 +1914,7 @@ def _resolve_depenency_map(
for req in dep_exc.criterion.iter_requirement(): for req in dep_exc.criterion.iter_requirement():
error_msg_lines.append( error_msg_lines.append(
'* {req.fqcn!s}:{req.ver!s}'.format(req=req) f'* {req.fqcn!s}:{req.ver!s}'
) )
error_msg_lines.append(pre_release_hint) error_msg_lines.append(pre_release_hint)

@ -413,7 +413,7 @@ def _extract_collection_from_git(repo_url, coll_ver, b_path):
b_checkout_path = mkdtemp( b_checkout_path = mkdtemp(
dir=b_path, dir=b_path,
prefix=to_bytes(name, errors='surrogate_or_strict'), prefix=to_bytes(name, errors='surrogate_or_strict'),
) # type: bytes )
try: try:
git_executable = get_bin_path('git') git_executable = get_bin_path('git')

@ -12,20 +12,14 @@ import contextlib
import inspect import inspect
import os import os
import subprocess import subprocess
import sys
import typing as t import typing as t
from dataclasses import dataclass, fields as dc_fields from dataclasses import dataclass, fields as dc_fields
from functools import partial
from urllib.error import HTTPError, URLError from urllib.error import HTTPError, URLError
if t.TYPE_CHECKING: if t.TYPE_CHECKING:
from ansible.utils.display import Display from ansible.utils.display import Display
IS_PY310_PLUS = sys.version_info[:2] >= (3, 10)
frozen_dataclass = partial(dataclass, frozen=True, **({'slots': True} if IS_PY310_PLUS else {}))
def get_signature_from_source(source, display=None): # type: (str, t.Optional[Display]) -> str def get_signature_from_source(source, display=None): # type: (str, t.Optional[Display]) -> str
if display is not None: if display is not None:
@ -128,7 +122,7 @@ def parse_gpg_errors(status_out): # type: (str) -> t.Iterator[GpgBaseError]
yield cls(*fields) yield cls(*fields)
@frozen_dataclass @dataclass(frozen=True, slots=True)
class GpgBaseError(Exception): class GpgBaseError(Exception):
status: str status: str
@ -142,35 +136,35 @@ class GpgBaseError(Exception):
super(GpgBaseError, self).__setattr__(field_name, field_type(getattr(self, field_name))) super(GpgBaseError, self).__setattr__(field_name, field_type(getattr(self, field_name)))
@frozen_dataclass @dataclass(frozen=True, slots=True)
class GpgExpSig(GpgBaseError): class GpgExpSig(GpgBaseError):
"""The signature with the keyid is good, but the signature is expired.""" """The signature with the keyid is good, but the signature is expired."""
keyid: str keyid: str
username: str username: str
@frozen_dataclass @dataclass(frozen=True, slots=True)
class GpgExpKeySig(GpgBaseError): class GpgExpKeySig(GpgBaseError):
"""The signature with the keyid is good, but the signature was made by an expired key.""" """The signature with the keyid is good, but the signature was made by an expired key."""
keyid: str keyid: str
username: str username: str
@frozen_dataclass @dataclass(frozen=True, slots=True)
class GpgRevKeySig(GpgBaseError): class GpgRevKeySig(GpgBaseError):
"""The signature with the keyid is good, but the signature was made by a revoked key.""" """The signature with the keyid is good, but the signature was made by a revoked key."""
keyid: str keyid: str
username: str username: str
@frozen_dataclass @dataclass(frozen=True, slots=True)
class GpgBadSig(GpgBaseError): class GpgBadSig(GpgBaseError):
"""The signature with the keyid has not been verified okay.""" """The signature with the keyid has not been verified okay."""
keyid: str keyid: str
username: str username: str
@frozen_dataclass @dataclass(frozen=True, slots=True)
class GpgErrSig(GpgBaseError): class GpgErrSig(GpgBaseError):
""""It was not possible to check the signature. This may be caused by """"It was not possible to check the signature. This may be caused by
a missing public key or an unsupported algorithm. A RC of 4 a missing public key or an unsupported algorithm. A RC of 4
@ -186,24 +180,24 @@ class GpgErrSig(GpgBaseError):
fpr: str fpr: str
@frozen_dataclass @dataclass(frozen=True, slots=True)
class GpgNoPubkey(GpgBaseError): class GpgNoPubkey(GpgBaseError):
"""The public key is not available.""" """The public key is not available."""
keyid: str keyid: str
@frozen_dataclass @dataclass(frozen=True, slots=True)
class GpgMissingPassPhrase(GpgBaseError): class GpgMissingPassPhrase(GpgBaseError):
"""No passphrase was supplied.""" """No passphrase was supplied."""
@frozen_dataclass @dataclass(frozen=True, slots=True)
class GpgBadPassphrase(GpgBaseError): class GpgBadPassphrase(GpgBaseError):
"""The supplied passphrase was wrong or not given.""" """The supplied passphrase was wrong or not given."""
keyid: str keyid: str
@frozen_dataclass @dataclass(frozen=True, slots=True)
class GpgNoData(GpgBaseError): class GpgNoData(GpgBaseError):
"""No data has been found. Codes for WHAT are: """No data has been found. Codes for WHAT are:
- 1 :: No armored data. - 1 :: No armored data.
@ -215,7 +209,7 @@ class GpgNoData(GpgBaseError):
what: str what: str
@frozen_dataclass @dataclass(frozen=True, slots=True)
class GpgUnexpected(GpgBaseError): class GpgUnexpected(GpgBaseError):
"""No data has been found. Codes for WHAT are: """No data has been found. Codes for WHAT are:
- 1 :: No armored data. - 1 :: No armored data.
@ -227,7 +221,7 @@ class GpgUnexpected(GpgBaseError):
what: str what: str
@frozen_dataclass @dataclass(frozen=True, slots=True)
class GpgError(GpgBaseError): class GpgError(GpgBaseError):
"""This is a generic error status message, it might be followed by error location specific data.""" """This is a generic error status message, it might be followed by error location specific data."""
location: str location: str
@ -235,30 +229,30 @@ class GpgError(GpgBaseError):
more: str = "" more: str = ""
@frozen_dataclass @dataclass(frozen=True, slots=True)
class GpgFailure(GpgBaseError): class GpgFailure(GpgBaseError):
"""This is the counterpart to SUCCESS and used to indicate a program failure.""" """This is the counterpart to SUCCESS and used to indicate a program failure."""
location: str location: str
code: int code: int
@frozen_dataclass @dataclass(frozen=True, slots=True)
class GpgBadArmor(GpgBaseError): class GpgBadArmor(GpgBaseError):
"""The ASCII armor is corrupted.""" """The ASCII armor is corrupted."""
@frozen_dataclass @dataclass(frozen=True, slots=True)
class GpgKeyExpired(GpgBaseError): class GpgKeyExpired(GpgBaseError):
"""The key has expired.""" """The key has expired."""
timestamp: int timestamp: int
@frozen_dataclass @dataclass(frozen=True, slots=True)
class GpgKeyRevoked(GpgBaseError): class GpgKeyRevoked(GpgBaseError):
"""The used key has been revoked by its owner.""" """The used key has been revoked by its owner."""
@frozen_dataclass @dataclass(frozen=True, slots=True)
class GpgNoSecKey(GpgBaseError): class GpgNoSecKey(GpgBaseError):
"""The secret key is not available.""" """The secret key is not available."""
keyid: str keyid: str

@ -147,30 +147,32 @@ class AnsibleConstructor(SafeConstructor):
AnsibleConstructor.add_constructor( AnsibleConstructor.add_constructor(
u'tag:yaml.org,2002:map', u'tag:yaml.org,2002:map',
AnsibleConstructor.construct_yaml_map) AnsibleConstructor.construct_yaml_map) # type: ignore[type-var]
AnsibleConstructor.add_constructor( AnsibleConstructor.add_constructor(
u'tag:yaml.org,2002:python/dict', u'tag:yaml.org,2002:python/dict',
AnsibleConstructor.construct_yaml_map) AnsibleConstructor.construct_yaml_map) # type: ignore[type-var]
AnsibleConstructor.add_constructor( AnsibleConstructor.add_constructor(
u'tag:yaml.org,2002:str', u'tag:yaml.org,2002:str',
AnsibleConstructor.construct_yaml_str) AnsibleConstructor.construct_yaml_str) # type: ignore[type-var]
AnsibleConstructor.add_constructor( AnsibleConstructor.add_constructor(
u'tag:yaml.org,2002:python/unicode', u'tag:yaml.org,2002:python/unicode',
AnsibleConstructor.construct_yaml_str) AnsibleConstructor.construct_yaml_str) # type: ignore[type-var]
AnsibleConstructor.add_constructor( AnsibleConstructor.add_constructor(
u'tag:yaml.org,2002:seq', u'tag:yaml.org,2002:seq',
AnsibleConstructor.construct_yaml_seq) AnsibleConstructor.construct_yaml_seq) # type: ignore[type-var]
AnsibleConstructor.add_constructor( AnsibleConstructor.add_constructor(
u'!unsafe', u'!unsafe',
AnsibleConstructor.construct_yaml_unsafe) AnsibleConstructor.construct_yaml_unsafe) # type: ignore[type-var]
AnsibleConstructor.add_constructor( AnsibleConstructor.add_constructor(
u'!vault', u'!vault',
AnsibleConstructor.construct_vault_encrypted_unicode) AnsibleConstructor.construct_vault_encrypted_unicode) # type: ignore[type-var]
AnsibleConstructor.add_constructor(u'!vault-encrypted', AnsibleConstructor.construct_vault_encrypted_unicode) AnsibleConstructor.add_constructor(
u'!vault-encrypted',
AnsibleConstructor.construct_vault_encrypted_unicode) # type: ignore[type-var]

@ -2,15 +2,6 @@ lib/ansible/config/base.yml no-unwanted-files
lib/ansible/executor/powershell/async_watchdog.ps1 pslint:PSCustomUseLiteralPath lib/ansible/executor/powershell/async_watchdog.ps1 pslint:PSCustomUseLiteralPath
lib/ansible/executor/powershell/async_wrapper.ps1 pslint:PSCustomUseLiteralPath lib/ansible/executor/powershell/async_wrapper.ps1 pslint:PSCustomUseLiteralPath
lib/ansible/executor/powershell/exec_wrapper.ps1 pslint:PSCustomUseLiteralPath lib/ansible/executor/powershell/exec_wrapper.ps1 pslint:PSCustomUseLiteralPath
lib/ansible/galaxy/collection/__init__.py mypy-3.10:attr-defined # inline ignore has no effect
lib/ansible/galaxy/collection/__init__.py mypy-3.11:attr-defined # inline ignore has no effect
lib/ansible/galaxy/collection/__init__.py mypy-3.12:attr-defined # inline ignore has no effect
lib/ansible/galaxy/collection/gpg.py mypy-3.10:arg-type
lib/ansible/galaxy/collection/gpg.py mypy-3.11:arg-type
lib/ansible/galaxy/collection/gpg.py mypy-3.12:arg-type
lib/ansible/parsing/yaml/constructor.py mypy-3.10:type-var # too many occurrences to ignore inline
lib/ansible/parsing/yaml/constructor.py mypy-3.11:type-var # too many occurrences to ignore inline
lib/ansible/parsing/yaml/constructor.py mypy-3.12:type-var # too many occurrences to ignore inline
lib/ansible/keyword_desc.yml no-unwanted-files lib/ansible/keyword_desc.yml no-unwanted-files
lib/ansible/modules/apt.py validate-modules:parameter-invalid lib/ansible/modules/apt.py validate-modules:parameter-invalid
lib/ansible/modules/apt_repository.py validate-modules:parameter-invalid lib/ansible/modules/apt_repository.py validate-modules:parameter-invalid

Loading…
Cancel
Save