From 8668a57db56415696862c1cdbd6a25e33f4060a3 Mon Sep 17 00:00:00 2001 From: Sorin Sbarnea Date: Sat, 24 Aug 2024 11:46:27 +0100 Subject: [PATCH] Fix several bugs reported by linters (#1882) --- .config/dictionary.txt | 1 + .github/release-drafter.yml | 4 +- .github/workflows/ack.yml | 4 +- .github/workflows/push.yml | 4 +- .pre-commit-config.yaml | 11 +-- jira/client.py | 133 +++++++++++++++++++--------------- jira/config.py | 3 +- jira/exceptions.py | 10 +-- jira/resources.py | 118 ++++++++++++++++-------------- pyproject.toml | 10 +++ tests/resources/test_epic.py | 2 +- tests/resources/test_issue.py | 8 +- tests/test_exceptions.py | 4 +- tests/tests.py | 2 +- 14 files changed, 173 insertions(+), 141 deletions(-) create mode 100644 .config/dictionary.txt diff --git a/.config/dictionary.txt b/.config/dictionary.txt new file mode 100644 index 000000000..bf52b4c93 --- /dev/null +++ b/.config/dictionary.txt @@ -0,0 +1 @@ +assertIn diff --git a/.github/release-drafter.yml b/.github/release-drafter.yml index 114b5fc80..dd5152eea 100644 --- a/.github/release-drafter.yml +++ b/.github/release-drafter.yml @@ -1,2 +1,2 @@ -# see https://github.com/ansible-community/devtools -_extends: ansible-community/devtools +# see https://github.com/ansible/team-devtools +_extends: ansible/team-devtools diff --git a/.github/workflows/ack.yml b/.github/workflows/ack.yml index 5880addda..958b0b647 100644 --- a/.github/workflows/ack.yml +++ b/.github/workflows/ack.yml @@ -1,4 +1,4 @@ -# See https://github.com/ansible-community/devtools/blob/main/.github/workflows/ack.yml +# See https://github.com/ansible/team-devtools/blob/main/.github/workflows/ack.yml name: ack on: pull_request_target: @@ -6,4 +6,4 @@ on: jobs: ack: - uses: ansible-community/devtools/.github/workflows/ack.yml@main + uses: ansible/team-devtools/.github/workflows/ack.yml@main diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml index e8239f701..7fa9d2a58 100644 --- a/.github/workflows/push.yml +++ b/.github/workflows/push.yml @@ -1,4 +1,4 @@ -# See https://github.com/ansible-community/devtools/blob/main/.github/workflows/push.yml +# See https://github.com/ansible/team-devtools/blob/main/.github/workflows/push.yml name: push on: push: @@ -9,4 +9,4 @@ on: jobs: ack: - uses: ansible-community/devtools/.github/workflows/push.yml@main + uses: ansible/team-devtools/.github/workflows/push.yml@main diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 67f50e68e..96be8bad6 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,7 +1,7 @@ --- repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.5.0 + rev: v4.6.0 hooks: - id: end-of-file-fixer - id: trailing-whitespace @@ -15,7 +15,7 @@ repos: - id: check-yaml files: .*\.(yaml|yml)$ - repo: https://github.com/codespell-project/codespell - rev: v2.2.6 + rev: v2.3.0 hooks: - id: codespell name: codespell @@ -27,7 +27,7 @@ repos: require_serial: false additional_dependencies: [] - repo: https://github.com/astral-sh/ruff-pre-commit - rev: "v0.3.4" + rev: "v0.6.2" hooks: - id: ruff args: [--fix, --exit-non-zero-on-fix] @@ -39,11 +39,8 @@ repos: - id: yamllint files: \.(yaml|yml)$ - repo: https://github.com/pre-commit/mirrors-mypy - rev: v1.9.0 + rev: v1.11.1 hooks: - id: mypy additional_dependencies: - types-requests - - types-pkg_resources - args: - [--no-strict-optional, --ignore-missing-imports, --show-error-codes] diff --git a/jira/client.py b/jira/client.py index ff311bcd6..aefae7cd1 100644 --- a/jira/client.py +++ b/jira/client.py @@ -208,7 +208,7 @@ def wrapper(*args: Any, **kwargs: Any) -> Any: def _field_worker( - fields: dict[str, Any] = None, **fieldargs: Any + fields: dict[str, Any] | None = None, **fieldargs: Any ) -> dict[str, dict[str, Any]] | dict[str, dict[str, str]]: if fields is not None: return {"fields": fields} @@ -221,7 +221,7 @@ def _field_worker( class ResultList(list, Generic[ResourceType]): def __init__( self, - iterable: Iterable = None, + iterable: Iterable | None = None, _startAt: int = 0, _maxResults: int = 0, _total: int | None = None, @@ -464,23 +464,23 @@ class JIRA: def __init__( self, - server: str = None, - options: dict[str, str | bool | Any] = None, + server: str | None = None, + options: dict[str, str | bool | Any] | None = None, basic_auth: tuple[str, str] | None = None, token_auth: str | None = None, - oauth: dict[str, Any] = None, - jwt: dict[str, Any] = None, + oauth: dict[str, Any] | None = None, + jwt: dict[str, Any] | None = None, kerberos=False, - kerberos_options: dict[str, Any] = None, + kerberos_options: dict[str, Any] | None = None, validate=False, get_server_info: bool = True, async_: bool = False, async_workers: int = 5, logging: bool = True, max_retries: int = 3, - proxies: Any = None, + proxies: Any | None = None, timeout: None | float | tuple[float, float] | tuple[float, None] | None = None, - auth: tuple[str, str] = None, + auth: tuple[str, str] | None = None, default_batch_sizes: dict[type[Resource], int | None] | None = None, ): """Construct a Jira client instance. @@ -559,7 +559,6 @@ def __init__( """ # force a copy of the tuple to be used in __del__() because # sys.version_info could have already been deleted in __del__() - self.sys_version_info = tuple(sys.version_info) if options is None: options = {} @@ -745,7 +744,8 @@ def close(self): # because other references are also in the process to be torn down, # see warning section in https://docs.python.org/2/reference/datamodel.html#object.__del__ pass - self._session = None + # TODO: https://github.com/pycontribs/jira/issues/1881 + self._session = None # type: ignore[arg-type,assignment] def _check_for_html_error(self, content: str): # Jira has the bad habit of returning errors in pages with 200 and embedding the @@ -771,7 +771,7 @@ def _fetch_pages( request_path: str, startAt: int = 0, maxResults: int = 50, - params: dict[str, Any] = None, + params: dict[str, Any] | None = None, base: str = JIRA_BASE_URL, use_post: bool = False, ) -> ResultList[ResourceType]: @@ -991,7 +991,7 @@ def async_do(self, size: int = 10): # non-resource def application_properties( - self, key: str = None + self, key: str | None = None ) -> dict[str, str] | list[dict[str, str]]: """Return the mutable server application properties. @@ -1065,7 +1065,7 @@ def add_attachment( self, issue: str | int, attachment: str | BufferedReader, - filename: str = None, + filename: str | None = None, ) -> Attachment: """Attach an attachment to an issue and returns a Resource for it. @@ -1089,8 +1089,7 @@ def add_attachment( attachment_io = attachment if isinstance(attachment, BufferedReader) and attachment.mode != "rb": self.log.warning( - "%s was not opened in 'rb' mode, attaching file may fail." - % attachment.name + f"{attachment.name} was not opened in 'rb' mode, attaching file may fail." ) fname = filename @@ -1570,10 +1569,10 @@ def favourite_filters(self) -> list[Filter]: def create_filter( self, - name: str = None, - description: str = None, - jql: str = None, - favourite: bool = None, + name: str | None = None, + description: str | None = None, + jql: str | None = None, + favourite: bool | None = None, ) -> Filter: """Create a new filter and return a filter Resource for it. @@ -1604,10 +1603,10 @@ def create_filter( def update_filter( self, filter_id, - name: str = None, - description: str = None, - jql: str = None, - favourite: bool = None, + name: str | None = None, + description: str | None = None, + jql: str | None = None, + favourite: bool | None = None, ): """Update a filter and return a filter Resource for it. @@ -1637,7 +1636,7 @@ def update_filter( # Groups - def group(self, id: str, expand: Any = None) -> Group: + def group(self, id: str, expand: Any | None = None) -> Group: """Get a group Resource from the server. Args: @@ -2010,7 +2009,10 @@ def service_desk(self, id: str) -> ServiceDesk: @no_type_check # FIXME: This function does not do what it wants to with fieldargs def create_customer_request( - self, fields: dict[str, Any] = None, prefetch: bool = True, **fieldargs + self, + fields: dict[str, Any] | None = None, + prefetch: bool = True, + **fieldargs, ) -> Issue: """Create a new customer request and return an issue Resource for it. @@ -3262,7 +3264,7 @@ def create_temp_project_avatar( filename: str, size: int, avatar_img: bytes, - contentType: str = None, + contentType: str | None = None, auto_confirm: bool = False, ): """Register an image file as a project avatar. @@ -3808,7 +3810,7 @@ def create_temp_user_avatar( filename: str, size: int, avatar_img: bytes, - contentType: Any = None, + contentType: Any | None = None, auto_confirm: bool = False, ): """Register an image file as a user avatar. @@ -3981,8 +3983,8 @@ def search_users( def search_allowed_users_for_issue( self, user: str, - issueKey: str = None, - projectKey: str = None, + issueKey: str | None = None, + projectKey: str | None = None, startAt: int = 0, maxResults: int = 50, ) -> ResultList: @@ -4014,9 +4016,9 @@ def create_version( self, name: str, project: str, - description: str = None, - releaseDate: Any = None, - startDate: Any = None, + description: str | None = None, + releaseDate: Any | None = None, + startDate: Any | None = None, archived: bool = False, released: bool = False, ) -> Version: @@ -4054,7 +4056,9 @@ def create_version( version = Version(self._options, self._session, raw=json_loads(r)) return version - def move_version(self, id: str, after: str = None, position: str = None) -> Version: + def move_version( + self, id: str, after: str | None = None, position: str | None = None + ) -> Version: """Move a version within a project's ordered version list and return a new version Resource for it. One, but not both, of ``after`` and ``position`` must be specified. @@ -4079,7 +4083,7 @@ def move_version(self, id: str, after: str = None, position: str = None) -> Vers version = Version(self._options, self._session, raw=json_loads(r)) return version - def version(self, id: str, expand: Any = None) -> Version: + def version(self, id: str, expand: Any | None = None) -> Version: """Get a version Resource. Args: @@ -4203,7 +4207,7 @@ def _create_oauth_session(self, oauth: dict[str, Any]): def _create_kerberos_session( self, - kerberos_options: dict[str, Any] = None, + kerberos_options: dict[str, Any] | None = None, ): if kerberos_options is None: kerberos_options = {} @@ -4216,8 +4220,9 @@ def _create_kerberos_session( mutual_authentication = DISABLED else: raise ValueError( - "Unknown value for mutual_authentication: %s" - % kerberos_options["mutual_authentication"] + "Unknown value for mutual_authentication: {}".format( + kerberos_options["mutual_authentication"] + ) ) self._session.auth = HTTPKerberosAuth( @@ -4249,7 +4254,7 @@ def _add_ssl_cert_verif_strategy_to_session(self): self._session.verify = ssl_cert @staticmethod - def _timestamp(dt: datetime.timedelta = None): + def _timestamp(dt: datetime.timedelta | None = None): t = datetime.datetime.utcnow() if dt is not None: t += dt @@ -4336,7 +4341,7 @@ def _get_latest_url(self, path: str, base: str = JIRA_BASE_URL) -> str: def _get_json( self, path: str, - params: dict[str, Any] = None, + params: dict[str, Any] | None = None, base: str = JIRA_BASE_URL, use_post: bool = False, ): @@ -4657,6 +4662,8 @@ def backup_complete(self) -> bool | None: self.log.warning("This functionality is not available in Server version") return None status = self.backup_progress() + if not status: + raise RuntimeError("Failed to retrieve backup progress.") perc_search = re.search(r"\s([0-9]*)\s", status["alternativePercentage"]) perc_complete = int( perc_search.group(1) # type: ignore # ignore that re.search can return None @@ -4664,12 +4671,15 @@ def backup_complete(self) -> bool | None: file_size = int(status["size"]) return perc_complete >= 100 and file_size > 0 - def backup_download(self, filename: str = None): + def backup_download(self, filename: str | None = None): """Download backup file from WebDAV (cloud only).""" if not self._is_cloud: self.log.warning("This functionality is not available in Server version") return None - remote_file = self.backup_progress()["fileName"] + progress = self.backup_progress() + if not progress: + raise RuntimeError("Unable to retrieve backup progress.") + remote_file = progress["fileName"] local_file = filename or remote_file url = self.server_url + "/webdav/backupmanager/" + remote_file try: @@ -4904,16 +4914,16 @@ def get_issue_type_scheme_associations(self, id: str) -> list[Project]: def create_project( self, key: str, - name: str = None, - assignee: str = None, + name: str | None = None, + assignee: str | None = None, ptype: str = "software", - template_name: str = None, - avatarId: int = None, - issueSecurityScheme: int = None, - permissionScheme: int = None, - projectCategory: int = None, + template_name: str | None = None, + avatarId: int | None = None, + issueSecurityScheme: int | None = None, + permissionScheme: int | None = None, + projectCategory: int | None = None, notificationScheme: int = 10000, - categoryId: int = None, + categoryId: int | None = None, url: str = "", ): """Create a project with the specified parameters. @@ -4956,6 +4966,8 @@ def create_project( break if permissionScheme is None and ps_list: permissionScheme = ps_list[0]["id"] + if permissionScheme is None: + raise RuntimeError("Unable to identify valid permissionScheme") if issueSecurityScheme is None: ps_list = self.issuesecurityschemes() @@ -4965,6 +4977,8 @@ def create_project( break if issueSecurityScheme is None and ps_list: issueSecurityScheme = ps_list[0]["id"] + if issueSecurityScheme is None: + raise RuntimeError("Unable to identify valid issueSecurityScheme") # If categoryId provided instead of projectCategory, attribute the categoryId value # to the projectCategory variable @@ -5080,8 +5094,8 @@ def add_user( username: str, email: str, directoryId: int = 1, - password: str = None, - fullname: str = None, + password: str | None = None, + fullname: str | None = None, notify: bool = False, active: bool = True, ignore_existing: bool = False, @@ -5217,8 +5231,8 @@ def boards( self, startAt: int = 0, maxResults: int = 50, - type: str = None, - name: str = None, + type: str | None = None, + name: str | None = None, projectKeyOrID=None, ) -> ResultList[Board]: """Get a list of board resources. @@ -5258,7 +5272,7 @@ def sprints( extended: bool | None = None, startAt: int = 0, maxResults: int = 50, - state: str = None, + state: str | None = None, ) -> ResultList[Sprint]: """Get a list of sprint Resources. @@ -5291,7 +5305,7 @@ def sprints( ) def sprints_by_name( - self, id: str | int, extended: bool = False, state: str = None + self, id: str | int, extended: bool = False, state: str | None = None ) -> dict[str, dict[str, Any]]: """Get a dictionary of sprint Resources where the name of the sprint is the key. @@ -5425,7 +5439,7 @@ def create_board( self, name: str, filter_id: str, - project_ids: str = None, + project_ids: str | None = None, preset: str = "scrum", location_type: Literal["user", "project"] = "user", location_id: str | None = None, @@ -5529,7 +5543,10 @@ def add_issues_to_sprint(self, sprint_id: int, issue_keys: list[str]) -> Respons return self._session.post(url, data=json.dumps(payload)) def add_issues_to_epic( - self, epic_id: str, issue_keys: str | list[str], ignore_epics: bool = None + self, + epic_id: str, + issue_keys: str | list[str], + ignore_epics: bool | None = None, ) -> Response: """Add the issues in ``issue_keys`` to the ``epic_id``. diff --git a/jira/config.py b/jira/config.py index 8216c3119..2c6974297 100644 --- a/jira/config.py +++ b/jira/config.py @@ -118,8 +118,7 @@ def findfile(path): verify = config.get(profile, "verify") else: raise OSError( - "%s was not able to locate the config.ini file in current directory, user home directory or PYTHONPATH." - % __name__ + f"{__name__} was not able to locate the config.ini file in current directory, user home directory or PYTHONPATH." ) options = JIRA.DEFAULT_OPTIONS diff --git a/jira/exceptions.py b/jira/exceptions.py index 0047133e5..ff9a0a138 100644 --- a/jira/exceptions.py +++ b/jira/exceptions.py @@ -12,11 +12,11 @@ class JIRAError(Exception): def __init__( self, - text: str = None, - status_code: int = None, - url: str = None, - request: Response = None, - response: Response = None, + text: str | None = None, + status_code: int | None = None, + url: str | None = None, + request: Response | None = None, + response: Response | None = None, **kwargs, ): """Creates a JIRAError. diff --git a/jira/resources.py b/jira/resources.py index 5922d5087..523a54324 100644 --- a/jira/resources.py +++ b/jira/resources.py @@ -295,7 +295,7 @@ def update( self, fields: dict[str, Any] | None = None, async_: bool | None = None, - jira: JIRA = None, + jira: JIRA | None = None, notify: bool = True, **kwargs: Any, ): @@ -335,8 +335,9 @@ def update( and "reporter" not in data["fields"] ): logging.warning( - "autofix: setting reporter to '%s' and retrying the update." - % self._options["autofix"] + "autofix: setting reporter to '{}' and retrying the update.".format( + self._options["autofix"] + ) ) data["fields"]["reporter"] = {"name": self._options["autofix"]} @@ -385,8 +386,7 @@ def update( if user and jira: logging.warning( - "Trying to add missing orphan user '%s' in order to complete the previous failed operation." - % user + f"Trying to add missing orphan user '{user}' in order to complete the previous failed operation." ) jira.add_user(user, "noreply@example.com", 10100, active=False) # if 'assignee' not in data['fields']: @@ -484,7 +484,7 @@ def __init__( self, options: dict[str, str], session: ResilientSession, - raw: dict[str, Any] = None, + raw: dict[str, Any] | None = None, ): Resource.__init__(self, "attachment/{0}", options, session) if raw: @@ -509,7 +509,7 @@ def __init__( self, options: dict[str, str], session: ResilientSession, - raw: dict[str, Any] = None, + raw: dict[str, Any] | None = None, ): Resource.__init__(self, "component/{0}", options, session) if raw: @@ -536,7 +536,7 @@ def __init__( self, options: dict[str, str], session: ResilientSession, - raw: dict[str, Any] = None, + raw: dict[str, Any] | None = None, ): Resource.__init__(self, "customFieldOption/{0}", options, session) if raw: @@ -551,7 +551,7 @@ def __init__( self, options: dict[str, str], session: ResilientSession, - raw: dict[str, Any] = None, + raw: dict[str, Any] | None = None, ): Resource.__init__(self, "dashboard/{0}", options, session) if raw: @@ -567,7 +567,7 @@ def __init__( self, options: dict[str, str], session: ResilientSession, - raw: dict[str, Any] = None, + raw: dict[str, Any] | None = None, ): Resource.__init__(self, "dashboard/{0}/items/{1}/properties", options, session) if raw: @@ -582,7 +582,7 @@ def __init__( self, options: dict[str, str], session: ResilientSession, - raw: dict[str, Any] = None, + raw: dict[str, Any] | None = None, ): Resource.__init__( self, "dashboard/{0}/items/{1}/properties/{2}", options, session @@ -642,7 +642,7 @@ def __init__( self, options: dict[str, str], session: ResilientSession, - raw: dict[str, Any] = None, + raw: dict[str, Any] | None = None, ): Resource.__init__(self, "dashboard/{0}/gadget/{1}", options, session) if raw: @@ -718,7 +718,7 @@ def __init__( self, options: dict[str, str], session: ResilientSession, - raw: dict[str, Any] = None, + raw: dict[str, Any] | None = None, ): Resource.__init__(self, "field/{0}", options, session) if raw: @@ -733,7 +733,7 @@ def __init__( self, options: dict[str, str], session: ResilientSession, - raw: dict[str, Any] = None, + raw: dict[str, Any] | None = None, ): Resource.__init__(self, "filter/{0}", options, session) if raw: @@ -781,7 +781,7 @@ def __init__( self, options: dict[str, str], session: ResilientSession, - raw: dict[str, Any] = None, + raw: dict[str, Any] | None = None, ): Resource.__init__(self, "issue/{0}", options, session) @@ -794,10 +794,10 @@ def __init__( def update( # type: ignore[override] # incompatible supertype ignored self, - fields: dict[str, Any] = None, - update: dict[str, Any] = None, - async_: bool = None, - jira: JIRA = None, + fields: dict[str, Any] | None = None, + update: dict[str, Any] | None = None, + async_: bool | None = None, + jira: JIRA | None = None, notify: bool = True, **fieldargs, ): @@ -906,7 +906,7 @@ def __init__( self, options: dict[str, str], session: ResilientSession, - raw: dict[str, Any] = None, + raw: dict[str, Any] | None = None, ): Resource.__init__(self, "issue/{0}/comment/{1}", options, session) if raw: @@ -920,7 +920,7 @@ def update( # type: ignore[override] self, fields: dict[str, Any] | None = None, async_: bool | None = None, - jira: JIRA = None, + jira: JIRA | None = None, body: str = "", visibility: dict[str, str] | None = None, is_internal: bool = False, @@ -962,14 +962,20 @@ def __init__( self, options: dict[str, str], session: ResilientSession, - raw: dict[str, Any] = None, + raw: dict[str, Any] | None = None, ): Resource.__init__(self, "issue/{0}/remotelink/{1}", options, session) if raw: self._parse_raw(raw) self.raw: dict[str, Any] = cast(Dict[str, Any], self.raw) - def update(self, object, globalId=None, application=None, relationship=None): + def update( # type: ignore[override] + self, + object: dict[str, Any] | None, + globalId=None, + application=None, + relationship=None, + ): """Update a RemoteLink. 'object' is required. For definitions of the allowable fields for 'object' and the keyword arguments 'globalId', 'application' and 'relationship', @@ -989,7 +995,8 @@ def update(self, object, globalId=None, application=None, relationship=None): if relationship is not None: data["relationship"] = relationship - super().update(**data) + # https://github.com/pycontribs/jira/issues/1881 + super().update(**data) # type: ignore[arg-type] class Votes(Resource): @@ -999,7 +1006,7 @@ def __init__( self, options: dict[str, str], session: ResilientSession, - raw: dict[str, Any] = None, + raw: dict[str, Any] | None = None, ): Resource.__init__(self, "issue/{0}/votes", options, session) if raw: @@ -1084,14 +1091,14 @@ def __init__( self, options: dict[str, str], session: ResilientSession, - raw: dict[str, Any] = None, + raw: dict[str, Any] | None = None, ): Resource.__init__(self, "issue/{0}/watchers", options, session) if raw: self._parse_raw(raw) self.raw: dict[str, Any] = cast(Dict[str, Any], self.raw) - def delete(self, username): + def delete(self, username): # type: ignore[override] """Remove the specified user from the watchers list.""" super().delete(params={"username": username}) @@ -1101,7 +1108,7 @@ def __init__( self, options: dict[str, str], session: ResilientSession, - raw: dict[str, Any] = None, + raw: dict[str, Any] | None = None, ): Resource.__init__(self, "issue/{0}/worklog/{1}", options, session) self.remainingEstimate = None @@ -1117,7 +1124,7 @@ def __init__( self, options: dict[str, str], session: ResilientSession, - raw: dict[str, Any] = None, + raw: dict[str, Any] | None = None, ): Resource.__init__(self, "issue/{0}/worklog/{1}", options, session) if raw: @@ -1154,7 +1161,7 @@ def __init__( self, options: dict[str, str], session: ResilientSession, - raw: dict[str, Any] = None, + raw: dict[str, Any] | None = None, ): Resource.__init__(self, "issue/{0}/properties/{1}", options, session) if raw: @@ -1178,7 +1185,7 @@ def __init__( self, options: dict[str, str], session: ResilientSession, - raw: dict[str, Any] = None, + raw: dict[str, Any] | None = None, ): Resource.__init__(self, "issueLink/{0}", options, session) if raw: @@ -1193,7 +1200,7 @@ def __init__( self, options: dict[str, str], session: ResilientSession, - raw: dict[str, Any] = None, + raw: dict[str, Any] | None = None, ): Resource.__init__(self, "issueLinkType/{0}", options, session) if raw: @@ -1208,7 +1215,7 @@ def __init__( self, options: dict[str, str], session: ResilientSession, - raw: dict[str, Any] = None, + raw: dict[str, Any] | None = None, ): Resource.__init__(self, "issuetype/{0}", options, session) if raw: @@ -1223,7 +1230,7 @@ def __init__( self, options: dict[str, str], session: ResilientSession, - raw: dict[str, Any] = None, + raw: dict[str, Any] | None = None, ): Resource.__init__(self, "priority/{0}", options, session) if raw: @@ -1238,7 +1245,7 @@ def __init__( self, options: dict[str, str], session: ResilientSession, - raw: dict[str, Any] = None, + raw: dict[str, Any] | None = None, ): Resource.__init__(self, "project/{0}", options, session) if raw: @@ -1253,7 +1260,7 @@ def __init__( self, options: dict[str, str], session: ResilientSession, - raw: dict[str, Any] = None, + raw: dict[str, Any] | None = None, ): Resource.__init__(self, "project/{0}/role/{1}", options, session) if raw: @@ -1262,8 +1269,8 @@ def __init__( def update( # type: ignore[override] self, - users: str | list | tuple = None, - groups: str | list | tuple = None, + users: str | list | tuple | None = None, + groups: str | list | tuple | None = None, ): """Add the specified users or groups to this project role. One of ``users`` or ``groups`` must be specified. @@ -1288,8 +1295,8 @@ def update( # type: ignore[override] def add_user( self, - users: str | list | tuple = None, - groups: str | list | tuple = None, + users: str | list | tuple | None = None, + groups: str | list | tuple | None = None, ): """Add the specified users or groups to this project role. One of ``users`` or ``groups`` must be specified. @@ -1313,7 +1320,7 @@ def __init__( self, options: dict[str, str], session: ResilientSession, - raw: dict[str, Any] = None, + raw: dict[str, Any] | None = None, ): Resource.__init__(self, "resolution/{0}", options, session) if raw: @@ -1328,7 +1335,7 @@ def __init__( self, options: dict[str, str], session: ResilientSession, - raw: dict[str, Any] = None, + raw: dict[str, Any] | None = None, ): Resource.__init__(self, "securitylevel/{0}", options, session) if raw: @@ -1343,7 +1350,7 @@ def __init__( self, options: dict[str, str], session: ResilientSession, - raw: dict[str, Any] = None, + raw: dict[str, Any] | None = None, ): Resource.__init__(self, "status/{0}", options, session) if raw: @@ -1358,7 +1365,7 @@ def __init__( self, options: dict[str, str], session: ResilientSession, - raw: dict[str, Any] = None, + raw: dict[str, Any] | None = None, ): Resource.__init__(self, "statuscategory/{0}", options, session) if raw: @@ -1373,7 +1380,7 @@ def __init__( self, options: dict[str, str], session: ResilientSession, - raw: dict[str, Any] = None, + raw: dict[str, Any] | None = None, *, _query_param: str = "username", ): @@ -1394,7 +1401,7 @@ def __init__( self, options: dict[str, str], session: ResilientSession, - raw: dict[str, Any] = None, + raw: dict[str, Any] | None = None, ): Resource.__init__(self, "group?groupname={0}", options, session) if raw: @@ -1409,7 +1416,7 @@ def __init__( self, options: dict[str, str], session: ResilientSession, - raw: dict[str, Any] = None, + raw: dict[str, Any] | None = None, ): Resource.__init__(self, "version/{0}", options, session) if raw: @@ -1433,7 +1440,8 @@ def delete(self, moveFixIssuesTo=None, moveAffectedIssuesTo=None): return super().delete(params) - def update(self, **kwargs): + # TODO: https://github.com/pycontribs/jira/issues/1881 + def update(self, **kwargs): # type: ignore[override] """Update this project version from the server. It is prior used to archive versions. Refer to Atlassian REST API `documentation`_. @@ -1478,7 +1486,7 @@ def __init__( path: str, options: dict[str, str], session: ResilientSession, - raw: dict[str, Any] = None, + raw: dict[str, Any] | None = None, ): self.self = None @@ -1495,7 +1503,7 @@ def __init__( self, options: dict[str, str], session: ResilientSession, - raw: dict[str, Any] = None, + raw: dict[str, Any] | None = None, ): AgileResource.__init__(self, "sprint/{0}", options, session, raw) @@ -1507,7 +1515,7 @@ def __init__( self, options: dict[str, str], session: ResilientSession, - raw: dict[str, Any] = None, + raw: dict[str, Any] | None = None, ): AgileResource.__init__(self, "board/{id}", options, session, raw) @@ -1522,7 +1530,7 @@ def __init__( self, options: dict[str, str], session: ResilientSession, - raw: dict[str, Any] = None, + raw: dict[str, Any] | None = None, ): Resource.__init__( self, "customer", options, session, "{server}/rest/servicedeskapi/{path}" @@ -1539,7 +1547,7 @@ def __init__( self, options: dict[str, str], session: ResilientSession, - raw: dict[str, Any] = None, + raw: dict[str, Any] | None = None, ): Resource.__init__( self, @@ -1560,7 +1568,7 @@ def __init__( self, options: dict[str, str], session: ResilientSession, - raw: dict[str, Any] = None, + raw: dict[str, Any] | None = None, ): Resource.__init__( self, @@ -1687,7 +1695,7 @@ def __init__( self, options: dict[str, str], session: ResilientSession, - raw: dict[str, Any] = None, + raw: dict[str, Any] | None = None, ): Resource.__init__(self, "unknown{0}", options, session) if raw: diff --git a/pyproject.toml b/pyproject.toml index 133e1bf3d..8dc146aad 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -92,6 +92,16 @@ test = [ [project.scripts] jirashell = "jira.jirashell:main" +[tool.codespell] +skip = [ + "./build", + "./docs/build", + "./node_modules", + "AUTHORS", + "ChangeLog" +] +ignore-words = ".config/dictionary.txt" + [tool.files] packages = """ jira""" diff --git a/tests/resources/test_epic.py b/tests/resources/test_epic.py index 42885cee2..e38e42c07 100644 --- a/tests/resources/test_epic.py +++ b/tests/resources/test_epic.py @@ -59,5 +59,5 @@ def test_add_issues_to_epic(self, name: str, input_type): with self.make_epic() as new_epic: self.jira.add_issues_to_epic( new_epic.id, - ",".join(issue_list) if input_type == str else issue_list, + ",".join(issue_list) if input_type == str else issue_list, # noqa: E721 ) diff --git a/tests/resources/test_issue.py b/tests/resources/test_issue.py index bd30c95a3..a496edb2e 100644 --- a/tests/resources/test_issue.py +++ b/tests/resources/test_issue.py @@ -21,18 +21,18 @@ def test_issue(self): self.assertEqual(issue.fields.summary, f"issue 1 from {self.project_b}") def test_issue_search_finds_issue(self): - issues = self.jira.search_issues("key=%s" % self.issue_1) + issues = self.jira.search_issues(f"key={self.issue_1}") self.assertEqual(self.issue_1, issues[0].key) def test_issue_search_return_type(self): - issues = self.jira.search_issues("key=%s" % self.issue_1) + issues = self.jira.search_issues(f"key={self.issue_1}") self.assertIsInstance(issues, list) - issues = self.jira.search_issues("key=%s" % self.issue_1, json_result=True) + issues = self.jira.search_issues(f"key={self.issue_1}", json_result=True) self.assertIsInstance(issues, dict) def test_issue_search_only_includes_provided_fields(self): issues = self.jira.search_issues( - "key=%s" % self.issue_1, fields="comment,assignee" + f"key={self.issue_1}", fields="comment,assignee" ) self.assertTrue(hasattr(issues[0].fields, "comment")) self.assertTrue(hasattr(issues[0].fields, "assignee")) diff --git a/tests/test_exceptions.py b/tests/test_exceptions.py index 09f6c59e2..191c6614b 100644 --- a/tests/test_exceptions.py +++ b/tests/test_exceptions.py @@ -21,7 +21,7 @@ class ExceptionsTests(unittest.TestCase): class MockResponse(Response): def __init__( self, - headers: dict = None, + headers: dict | None = None, text: str = "", status_code: int = DUMMY_STATUS_CODE, url: str = DUMMY_URL, @@ -43,7 +43,7 @@ def text(self, new_text): class MalformedMockResponse: def __init__( self, - headers: dict = None, + headers: dict | None = None, text: str = "", status_code: int = DUMMY_STATUS_CODE, url: str = DUMMY_URL, diff --git a/tests/tests.py b/tests/tests.py index f040150fa..bbc16c722 100755 --- a/tests/tests.py +++ b/tests/tests.py @@ -482,7 +482,7 @@ def _calculate_calls_for_fetch_pages( total: int, max_results: int, batch_size: int | None, - default: int | None = 10, + default: int = 10, ): """Returns expected query parameters for specified search-issues arguments.""" if not max_results: