1212
1313from dataclasses import asdict , dataclass , field
1414from pathlib import Path
15- from typing import Dict , List , Optional , Tuple , TypeVar , Union
15+ from typing import TypeVar , Union
1616
1717from ansible .errors import AnsibleActionFail
1818from ansible .parsing .dataloader import DataLoader
3737# pylint: enable=invalid-name
3838
3939# mypy disallow you from omitting parameters in generic types
40- JSONTypes = Union [bool , int , str , Dict , List ] # type:ignore
40+ JSONTypes = Union [bool , int , str , dict , list ] # type:ignore
4141
4242
4343@dataclass (frozen = False )
4444class Result (ResultBase ):
4545 """Data structure for the task result."""
4646
4747 branch_name : str = ""
48- branches : List [str ] = field (default_factory = list )
48+ branches : list [str ] = field (default_factory = list )
4949 name : str = ""
5050 path : str = ""
5151
@@ -62,7 +62,7 @@ class ActionModule(GitBase):
6262 _requires_connection = False
6363
6464 def __init__ ( # noqa: PLR0913
65- self : T ,
65+ self ,
6666 connection : Connection ,
6767 loader : DataLoader ,
6868 play_context : PlayContext ,
@@ -90,18 +90,18 @@ def __init__( # noqa: PLR0913
9090 ),
9191 )
9292
93- self ._base_command : Tuple [str , ...]
94- self ._branches : List [str ]
93+ self ._base_command : tuple [str , ...]
94+ self ._branches : list [str ]
9595 self ._branch_name : str
9696 self ._parent_directory : str
9797 self ._repo_path : str
9898 self ._play_name : str = ""
9999 self ._supports_async = True
100100 self ._result : Result = Result ()
101- self ._temp_ssh_key_path : Optional [ str ] = None
101+ self ._temp_ssh_key_path : str | None = None
102102 self ._ssh_command_str : str = "ssh"
103103
104- def _check_argspec (self : T ) -> None :
104+ def _check_argspec (self ) -> None :
105105 """Check the argspec for the action plugin.
106106
107107 :raises AnsibleActionFail: If the argspec is invalid
@@ -129,7 +129,7 @@ def _check_argspec(self: T) -> None:
129129 )
130130 raise AnsibleActionFail (msg )
131131
132- def _prepare_ssh_environment (self : T ) -> None :
132+ def _prepare_ssh_environment (self ) -> None :
133133 """Prepare the environment for SSH key authentication."""
134134 origin_args = self ._task .args .get ("origin" , {})
135135 key_content = origin_args .get ("ssh_key_content" )
@@ -151,20 +151,20 @@ def _prepare_ssh_environment(self: T) -> None:
151151 f"ssh -i { key_path } -o IdentitiesOnly=yes -o StrictHostKeyChecking=no"
152152 )
153153
154- def _cleanup_ssh_key (self : T ) -> None :
154+ def _cleanup_ssh_key (self ) -> None :
155155 """Remove the temporary SSH key file if it was created."""
156156 if self ._temp_ssh_key_path :
157157 Path (self ._temp_ssh_key_path ).unlink ()
158158
159159 @property
160- def _branch_exists (self : T ) -> bool :
160+ def _branch_exists (self ) -> bool :
161161 """Return True if the branch exists.
162162
163163 :returns: True if the branch exists
164164 """
165165 return self ._branch_name in self ._branches
166166
167- def _host_key_checking (self : T ) -> None :
167+ def _host_key_checking (self ) -> None :
168168 """Configure host key checking."""
169169 origin = self ._task .args ["origin" ]["url" ]
170170 upstream = self ._task .args ["upstream" ].get ("url" ) or ""
@@ -188,7 +188,7 @@ def _host_key_checking(self: T) -> None:
188188 )
189189 self ._run_command (command = command )
190190
191- def _clone (self : T ) -> None :
191+ def _clone (self ) -> None :
192192 """Clone the repository, creating a new subdirectory."""
193193 origin = self ._task .args ["origin" ]["url" ]
194194 upstream = self ._task .args ["upstream" ].get ("url" ) or ""
@@ -247,7 +247,7 @@ def _clone(self: T) -> None:
247247 self ._base_command = ("git" , "-C" , self ._repo_path )
248248 return
249249
250- def _get_branches (self : T ) -> None :
250+ def _get_branches (self ) -> None :
251251 """Get the branches."""
252252 command_parts = list (self ._base_command )
253253 command_parts .extend (["branch" , "-a" ])
@@ -294,14 +294,14 @@ def _get_branches(self: T) -> None:
294294 self ._result .branch_name = self ._branch_name
295295 return
296296
297- def _detect_duplicate_branch (self : T ) -> None :
297+ def _detect_duplicate_branch (self ) -> None :
298298 """Detect duplicate branch."""
299299 duplicate_detection = self ._task .args ["branch" ]["duplicate_detection" ]
300300 if duplicate_detection and self ._branch_exists :
301301 self ._result .failed = True
302302 self ._result .msg = f"Branch '{ self ._branch_name } ' already exists"
303303
304- def _switch_checkout (self : T ) -> None :
304+ def _switch_checkout (self ) -> None :
305305 """Switch to or checkout the branch."""
306306 command_parts = list (self ._base_command )
307307 branch = self ._branch_name
@@ -321,7 +321,7 @@ def _switch_checkout(self: T) -> None:
321321 )
322322 self ._run_command (command = command )
323323
324- def _add_upstream_remote (self : T ) -> None :
324+ def _add_upstream_remote (self ) -> None :
325325 """Add the upstream remote."""
326326 if not self ._task .args ["upstream" ].get ("url" ):
327327 return
@@ -336,7 +336,7 @@ def _add_upstream_remote(self: T) -> None:
336336 self ._run_command (command = command )
337337 return
338338
339- def _pull_upstream (self : T ) -> None :
339+ def _pull_upstream (self ) -> None :
340340 """Pull from upstream."""
341341 if not self ._task .args ["upstream" ].get ("url" ):
342342 return
@@ -363,10 +363,10 @@ def _pull_upstream(self: T) -> None:
363363 return
364364
365365 def run (
366- self : T ,
366+ self ,
367367 tmp : None = None ,
368- task_vars : Optional [ Dict [ str , JSONTypes ]] = None ,
369- ) -> Dict [str , JSONTypes ]:
368+ task_vars : dict [ str , JSONTypes ] | None = None ,
369+ ) -> dict [str , JSONTypes ]:
370370 """Run the action plugin.
371371
372372 :param tmp: The temporary directory
0 commit comments