Skip to content

Commit

Permalink
typing: add a bunch of -> None for obvious cases
Browse files Browse the repository at this point in the history
  • Loading branch information
bauen1 committed Jan 9, 2025
1 parent 2d3bb1e commit b9fa3a9
Show file tree
Hide file tree
Showing 17 changed files with 20 additions and 20 deletions.
2 changes: 1 addition & 1 deletion pyinfra/api/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ def execute(self, state: "State", host: "Host", connector_arguments: ConnectorAr
if "state" in argspec.args and "host" in argspec.args:
return self.function(state, host, *self.args, **self.kwargs)

def execute_function():
def execute_function() -> None:
with ctx_config.use(state.config.copy()):
with ctx_host.use(host):
self.function(*self.args, **self.kwargs)
Expand Down
4 changes: 2 additions & 2 deletions pyinfra/api/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,10 +224,10 @@ def set_current_state(self, config_state):
for key, value in config_state:
setattr(self, key, value)

def lock_current_state(self):
def lock_current_state(self) -> None:
self._locked_config = self.get_current_state()

def reset_locked_state(self):
def reset_locked_state(self) -> None:
self.set_current_state(self._locked_config)

def copy(self) -> "Config":
Expand Down
4 changes: 2 additions & 2 deletions pyinfra/api/host.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ def get_fact(self, name_or_cls, *args, **kwargs):
# Connector proxy
#

def _check_state(self):
def _check_state(self) -> None:
if not self.state:
raise TypeError("Cannot call this function with no state!")

Expand Down Expand Up @@ -403,7 +403,7 @@ def connect(self, reason=None, show_errors: bool = True, raise_exceptions: bool
self.state.trigger_callbacks("host_connect", self)
self.connected = True

def disconnect(self):
def disconnect(self) -> None:
"""
Disconnect from the host using it's configured connector.
"""
Expand Down
2 changes: 1 addition & 1 deletion pyinfra/api/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ class StateHostMeta:
ops_no_change = 0
op_hashes: set[str]

def __init__(self):
def __init__(self) -> None:
self.op_hashes = set()


Expand Down
2 changes: 1 addition & 1 deletion pyinfra/connectors/chroot.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@


@memoize
def show_warning():
def show_warning() -> None:
logger.warning("The @chroot connector is in beta!")


Expand Down
2 changes: 1 addition & 1 deletion pyinfra/connectors/docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def connect(self) -> None:
self.container_id = _start_docker_image(docker_identifier)

@override
def disconnect(self):
def disconnect(self) -> None:
container_id = self.container_id

if self.no_stop:
Expand Down
2 changes: 1 addition & 1 deletion pyinfra/connectors/dockerssh.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@


@memoize
def show_warning():
def show_warning() -> None:
logger.warning("The @dockerssh connector is in beta!")


Expand Down
2 changes: 1 addition & 1 deletion pyinfra/connectors/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ def get_file(
return True

@override
def check_can_rsync(self):
def check_can_rsync(self) -> None:
if not which("rsync"):
raise NotImplementedError("The `rsync` binary is not available on this system.")

Expand Down
2 changes: 1 addition & 1 deletion pyinfra/connectors/ssh.py
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@ def put_file(
return True

@override
def check_can_rsync(self):
def check_can_rsync(self) -> None:
if self.data["ssh_key_password"]:
raise NotImplementedError(
"Rsync does not currently work with SSH keys needing passwords."
Expand Down
2 changes: 1 addition & 1 deletion pyinfra/connectors/terraform.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@


@memoize
def show_warning():
def show_warning() -> None:
logger.warning("The @terraform connector is in beta!")


Expand Down
2 changes: 1 addition & 1 deletion pyinfra/connectors/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ def remove_any_sudo_askpass_file(host) -> None:


@memoize
def _show_use_su_login_warning():
def _show_use_su_login_warning() -> None:
logger.warning(
(
"Using `use_su_login` may not work: "
Expand Down
4 changes: 2 additions & 2 deletions pyinfra/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class ContextObject:
_container_cls = container
_base_cls: ModuleType

def __init__(self):
def __init__(self) -> None:
self._container = self._container_cls()
self._container.module = None

Expand Down Expand Up @@ -96,7 +96,7 @@ def set(self, module):
def set_base(self, module):
self.context._base_cls = module

def reset(self):
def reset(self) -> None:
self.context._container.module = None

def isset(self):
Expand Down
2 changes: 1 addition & 1 deletion pyinfra/facts/iptables.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def parse_iptables_rule(line):
args: list[str] = []
not_arg = False

def add_args():
def add_args() -> None:
arg_string = " ".join(args)

if key and key in IPTABLES_ARGS:
Expand Down
2 changes: 1 addition & 1 deletion pyinfra/operations/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,7 @@ def sync(


@memoize
def show_rsync_warning():
def show_rsync_warning() -> None:
logger.warning("The `files.rsync` operation is in alpha!")


Expand Down
2 changes: 1 addition & 1 deletion pyinfra_cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
from .virtualenv import init_virtualenv


def _exit():
def _exit() -> None:
if ctx_state.isset() and state.failed_hosts:
sys.exit(1)
sys.exit(0)
Expand Down
2 changes: 1 addition & 1 deletion pyinfra_cli/prints.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def print_facts(facts):
print_fact(data)


def print_support_info():
def print_support_info() -> None:
from importlib.metadata import PackageNotFoundError, requires, version

from packaging.requirements import Requirement
Expand Down
2 changes: 1 addition & 1 deletion pyinfra_cli/virtualenv.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from pyinfra import logger


def init_virtualenv():
def init_virtualenv() -> None:
"""
Add a virtualenv to sys.path so the user can import modules from it.
This isn't perfect: it doesn't use the Python interpreter with which the
Expand Down

0 comments on commit b9fa3a9

Please sign in to comment.