Skip to content

Commit

Permalink
Remove all pylint ignore annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
unkcpz committed Dec 1, 2024
1 parent d72fcd2 commit 9c8fd54
Show file tree
Hide file tree
Showing 19 changed files with 76 additions and 97 deletions.
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ docs = [
pre-commit = [
'mypy==1.13.0',
'pre-commit~=2.2',
'pylint==2.15.8',
'types-pyyaml'
]
tests = [
Expand Down
1 change: 0 additions & 1 deletion src/plumpy/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# -*- coding: utf-8 -*-
# mypy: disable-error-code=name-defined
# pylint: disable=undefined-variable
__version__ = '0.22.3'

import logging
Expand Down
4 changes: 1 addition & 3 deletions src/plumpy/base/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# -*- coding: utf-8 -*-
# pylint: disable=undefined-variable
# type: ignore
from .state_machine import *
from .utils import *

__all__ = state_machine.__all__ + utils.__all__
__all__ = state_machine.__all__ + utils.__all__ # type: ignore[name-defined]
26 changes: 13 additions & 13 deletions src/plumpy/base/state_machine.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@

_LOGGER = logging.getLogger(__name__)

LABEL_TYPE = Union[None, enum.Enum, str] # pylint: disable=invalid-name
EVENT_CALLBACK_TYPE = Callable[['StateMachine', Hashable, Optional['State']], None] # pylint: disable=invalid-name
LABEL_TYPE = Union[None, enum.Enum, str]
EVENT_CALLBACK_TYPE = Callable[['StateMachine', Hashable, Optional['State']], None]


class StateMachineError(Exception):
Expand All @@ -31,7 +31,7 @@ class StateEntryFailed(Exception): # noqa: N818
Failed to enter a state, can provide the next state to go to via this exception
"""

def __init__(self, state: Hashable = None, *args: Any, **kwargs: Any) -> None: # pylint: disable=keyword-arg-before-vararg
def __init__(self, state: Hashable = None, *args: Any, **kwargs: Any) -> None:
super().__init__('failed to enter state')
self.state = state
self.args = args
Expand Down Expand Up @@ -123,7 +123,7 @@ class State:
def is_terminal(cls) -> bool:
return not cls.ALLOWED

def __init__(self, state_machine: 'StateMachine', *args: Any, **kwargs: Any): # pylint: disable=unused-argument
def __init__(self, state_machine: 'StateMachine', *args: Any, **kwargs: Any):
"""
:param state_machine: The process this state belongs to
"""
Expand Down Expand Up @@ -217,13 +217,13 @@ def get_states(cls) -> Sequence[Type[State]]:
def initial_state_label(cls) -> LABEL_TYPE:
cls.__ensure_built()
assert cls.STATES is not None
return cls.STATES[0].LABEL # pylint: disable=unsubscriptable-object
return cls.STATES[0].LABEL

@classmethod
def get_state_class(cls, label: LABEL_TYPE) -> Type[State]:
cls.__ensure_built()
assert cls._STATES_MAP is not None
return cls._STATES_MAP[label] # pylint: disable=unsubscriptable-object
return cls._STATES_MAP[label]

@classmethod
def __ensure_built(cls) -> None:
Expand All @@ -235,15 +235,15 @@ def __ensure_built(cls) -> None:
pass

cls.STATES = cls.get_states()
assert isinstance(cls.STATES, Iterable) # pylint: disable=isinstance-second-argument-not-valid-type
assert isinstance(cls.STATES, Iterable)

# Build the states map
cls._STATES_MAP = {}
for state_cls in cls.STATES: # pylint: disable=not-an-iterable
for state_cls in cls.STATES:
assert issubclass(state_cls, State)
label = state_cls.LABEL
assert label not in cls._STATES_MAP, f"Duplicate label '{label}'" # pylint: disable=unsupported-membership-test
cls._STATES_MAP[label] = state_cls # pylint: disable=unsupported-assignment-operation
assert label not in cls._STATES_MAP, f"Duplicate label '{label}'"
cls._STATES_MAP[label] = state_cls

# should class initialise sealed = False?
cls.sealed = True # type: ignore
Expand Down Expand Up @@ -327,7 +327,7 @@ def transition_to(self, new_state: Union[Hashable, State, Type[State]], *args: A

if self._state is not None and self._state.is_terminal():
call_with_super_check(self.on_terminated)
except Exception: # pylint: disable=broad-except
except Exception:
self._transitioning = False
if self._transition_failing:
raise
Expand Down Expand Up @@ -356,7 +356,7 @@ def set_debug(self, enabled: bool) -> None:

def create_state(self, state_label: Hashable, *args: Any, **kwargs: Any) -> State:
try:
return self.get_states_map()[state_label](self, *args, **kwargs) # pylint: disable=unsubscriptable-object
return self.get_states_map()[state_label](self, *args, **kwargs)
except KeyError:
raise ValueError(f'{state_label} is not a valid state')

Expand Down Expand Up @@ -397,6 +397,6 @@ def _ensure_state_class(self, state: Union[Hashable, Type[State]]) -> Type[State
return state

try:
return self.get_states_map()[cast(Hashable, state)] # pylint: disable=unsubscriptable-object
return self.get_states_map()[cast(Hashable, state)]
except KeyError:
raise ValueError(f'{state} is not a valid state')
4 changes: 2 additions & 2 deletions src/plumpy/communications.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

if TYPE_CHECKING:
# identifiers for subscribers
ID_TYPE = Hashable # pylint: disable=invalid-name
ID_TYPE = Hashable
Subscriber = Callable[..., Any]
# RPC subscriber params: communicator, msg
RpcSubscriber = Callable[[kiwipy.Communicator, Any], Any]
Expand Down Expand Up @@ -84,7 +84,7 @@ def _passthrough(*args: Any, **kwargs: Any) -> bool:
return callback.is_filtered(sender, subject)
else:

def _passthrough(*args: Any, **kwargs: Any) -> bool: # pylint: disable=unused-argument
def _passthrough(*args: Any, **kwargs: Any) -> bool:
return False

coro = ensure_coroutine(callback)
Expand Down
4 changes: 2 additions & 2 deletions src/plumpy/event_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
if TYPE_CHECKING:
from typing import Set, Type

from .process_listener import ProcessListener # pylint: disable=cyclic-import
from .process_listener import ProcessListener

_LOGGER = logging.getLogger(__name__)

Expand Down Expand Up @@ -49,5 +49,5 @@ def fire_event(self, event_function: Callable[..., Any], *args: Any, **kwargs: A
for listener in list(self.listeners):
try:
getattr(listener, event_function.__name__)(*args, **kwargs)
except Exception as exception: # pylint: disable=broad-except
except Exception as exception:
_LOGGER.error("Listener '%s' produced an exception:\n%s", listener, exception)
8 changes: 3 additions & 5 deletions src/plumpy/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
]

if TYPE_CHECKING:
from .processes import Process # pylint: disable=cyclic-import
from .processes import Process

get_event_loop = asyncio.get_event_loop # pylint: disable=invalid-name
get_event_loop = asyncio.get_event_loop


def set_event_loop(*args: Any, **kwargs: Any) -> None:
Expand Down Expand Up @@ -57,12 +57,10 @@ def reset_event_loop_policy() -> None:
"""Reset the event loop policy to the default."""
loop = get_event_loop()

# pylint: disable=protected-access
cls = loop.__class__

del cls._check_running # type: ignore
del cls._nest_patched # type: ignore
# pylint: enable=protected-access

asyncio.set_event_loop_policy(None)

Expand Down Expand Up @@ -99,7 +97,7 @@ async def run(self) -> None:
if not self._cancelled:
try:
await self._callback(*self._args, **self._kwargs)
except Exception: # pylint: disable=broad-except
except Exception:
exc_info = sys.exc_info()
self._process.callback_excepted(self._callback, exc_info[1], exc_info[2])
finally:
Expand Down
8 changes: 4 additions & 4 deletions src/plumpy/futures.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ class InvalidStateError(Exception):
"""Exception for when a future or action is in an invalid state"""


copy_future = kiwipy.copy_future # pylint: disable=invalid-name
chain = kiwipy.chain # pylint: disable=invalid-name
gather = asyncio.gather # pylint: disable=invalid-name
copy_future = kiwipy.copy_future
chain = kiwipy.chain
gather = asyncio.gather

Future = asyncio.Future # pylint: disable=invalid-name
Future = asyncio.Future


class CancellableAction(Future):
Expand Down
12 changes: 5 additions & 7 deletions src/plumpy/persistence.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
PersistedCheckpoint = collections.namedtuple('PersistedCheckpoint', ['pid', 'tag'])

if TYPE_CHECKING:
from .processes import Process # pylint: disable=cyclic-import
from .processes import Process


class Bundle(dict):
Expand Down Expand Up @@ -350,7 +350,6 @@ def delete_process_checkpoints(self, pid: PID_TYPE) -> None:

def auto_persist(*members: str) -> Callable[[SavableClsType], SavableClsType]:
def wrapped(savable: SavableClsType) -> SavableClsType:
# pylint: disable=protected-access
if savable._auto_persist is None:
savable._auto_persist = set()
else:
Expand Down Expand Up @@ -488,7 +487,7 @@ def load_instance_state(self, saved_state: SAVED_STATE_TYPE, load_context: Optio
self.load_members(self._auto_persist, saved_state, load_context)

@super_check
def save_instance_state(self, out_state: SAVED_STATE_TYPE, save_context: Optional[LoadSaveContext]) -> None: # pylint: disable=unused-argument
def save_instance_state(self, out_state: SAVED_STATE_TYPE, save_context: Optional[LoadSaveContext]) -> None:
self._ensure_persist_configured()
if self._auto_persist is not None:
self.save_members(self._auto_persist, out_state)
Expand Down Expand Up @@ -627,10 +626,10 @@ def recreate_from(cls, saved_state: SAVED_STATE_TYPE, load_context: Optional[Loa

state = saved_state['_state']

if state == asyncio.futures._PENDING: # type: ignore # pylint: disable=protected-access
if state == asyncio.futures._PENDING: # type: ignore
obj = cls(loop=loop)

if state == asyncio.futures._FINISHED: # type: ignore # pylint: disable=protected-access
if state == asyncio.futures._FINISHED: # type: ignore
obj = cls(loop=loop)
result = saved_state['_result']

Expand All @@ -640,14 +639,13 @@ def recreate_from(cls, saved_state: SAVED_STATE_TYPE, load_context: Optional[Loa
except KeyError:
obj.set_result(result)

if state == asyncio.futures._CANCELLED: # type: ignore # pylint: disable=protected-access
if state == asyncio.futures._CANCELLED: # type: ignore
obj = cls(loop=loop)
obj.cancel()

return obj

def load_instance_state(self, saved_state: SAVED_STATE_TYPE, load_context: LoadSaveContext) -> None:
# pylint: disable=attribute-defined-outside-init
super().load_instance_state(saved_state, load_context)
if self._callbacks:
# typing says asyncio.Future._callbacks needs to be called, but in the python 3.7 code it is a simple list
Expand Down
32 changes: 16 additions & 16 deletions src/plumpy/ports.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
This has been deprecated and the new signature is `validator(value, port)` where the `port` argument will be the
port instance to which the validator has been assigned."""

VALIDATOR_TYPE = Callable[[Any, 'Port'], Optional[str]] # pylint: disable=invalid-name
VALIDATOR_TYPE = Callable[[Any, 'Port'], Optional[str]]


class PortValidationError(Exception):
Expand Down Expand Up @@ -67,7 +67,7 @@ def __init__(
self,
name: str,
valid_type: Optional[Type[Any]] = None,
help: Optional[str] = None, # pylint: disable=redefined-builtin
help: Optional[str] = None,
required: bool = True,
validator: Optional[VALIDATOR_TYPE] = None,
) -> None:
Expand Down Expand Up @@ -135,7 +135,7 @@ def help(self) -> Optional[str]:
return self._help

@help.setter
def help(self, help: Optional[str]) -> None: # pylint: disable=redefined-builtin
def help(self, help: Optional[str]) -> None:
"""Set the help string for this port
:param help: the help string
Expand Down Expand Up @@ -199,9 +199,9 @@ def validate(self, value: Any, breadcrumbs: Sequence[str] = ()) -> Optional[Port
spec = inspect.getfullargspec(self.validator)
if len(spec[0]) == 1:
warnings.warn(VALIDATOR_SIGNATURE_DEPRECATION_WARNING.format(self.validator.__name__))
result = self.validator(value) # type: ignore # pylint: disable=not-callable
result = self.validator(value) # type: ignore
else:
result = self.validator(value, self) # pylint: disable=not-callable
result = self.validator(value, self)
if result is not None:
assert isinstance(result, str), 'Validator returned non string type'
validation_error = result
Expand Down Expand Up @@ -234,11 +234,11 @@ def __init__(
self,
name: str,
valid_type: Optional[Type[Any]] = None,
help: Optional[str] = None, # pylint: disable=redefined-builtin
help: Optional[str] = None,
default: Any = UNSPECIFIED,
required: bool = True,
validator: Optional[VALIDATOR_TYPE] = None,
) -> None: # pylint: disable=too-many-arguments
) -> None:
super().__init__(
name,
valid_type=valid_type,
Expand Down Expand Up @@ -304,14 +304,14 @@ class PortNamespace(collections.abc.MutableMapping, Port):
def __init__(
self,
name: str = '', # Note this was set to None, but that would fail if you tried to compute breadcrumbs
help: Optional[str] = None, # pylint: disable=redefined-builtin
help: Optional[str] = None,
required: bool = True,
validator: Optional[VALIDATOR_TYPE] = None,
valid_type: Optional[Type[Any]] = None,
default: Any = UNSPECIFIED,
dynamic: bool = False,
populate_defaults: bool = True,
) -> None: # pylint: disable=too-many-arguments
) -> None:
"""Construct a port namespace.
:param name: the name of the namespace
Expand Down Expand Up @@ -396,7 +396,7 @@ def valid_type(self, valid_type: Optional[Type[Any]]) -> None:
if valid_type is not None:
self.dynamic = True

super(PortNamespace, self.__class__).valid_type.fset(self, valid_type) # type: ignore # pylint: disable=no-member
super(PortNamespace, self.__class__).valid_type.fset(self, valid_type) # type: ignore

@property
def populate_defaults(self) -> bool:
Expand Down Expand Up @@ -530,7 +530,7 @@ def absorb(
:param namespace_options: a dictionary with mutable PortNamespace property values to override
:return: list of the names of the ports that were absorbed
"""
# pylint: disable=too-many-branches

if not isinstance(port_namespace, PortNamespace):
raise ValueError('port_namespace has to be an instance of PortNamespace')

Expand Down Expand Up @@ -577,7 +577,7 @@ def absorb(
# absorb call that will properly consider the include and exclude rules
self[port_name] = copy.copy(port)
portnamespace = cast(PortNamespace, self[port_name])
portnamespace._ports = {} # pylint: disable=protected-access
portnamespace._ports = {}
portnamespace.absorb(port, sub_exclude, sub_include)
else:
# If include rules are specified but the port name does not appear, simply skip it
Expand Down Expand Up @@ -612,7 +612,7 @@ def project(self, port_values: MutableMapping[str, Any]) -> MutableMapping[str,

return result

def validate( # pylint: disable=arguments-differ
def validate(
self, port_values: Optional[Mapping[str, Any]] = None, breadcrumbs: Sequence[str] = ()
) -> Optional[PortValidationError]:
"""
Expand All @@ -622,7 +622,7 @@ def validate( # pylint: disable=arguments-differ
:param breadcrumbs: a tuple of the path to having reached this point in validation
:return: None or tuple containing 0: error string 1: tuple of breadcrumb strings to where the validation failed
"""
# pylint: disable=arguments-renamed

breadcrumbs_local = (*breadcrumbs, self.name)
message: Optional[str]

Expand Down Expand Up @@ -660,9 +660,9 @@ def validate( # pylint: disable=arguments-differ
spec = inspect.getfullargspec(self.validator)
if len(spec[0]) == 1:
warnings.warn(VALIDATOR_SIGNATURE_DEPRECATION_WARNING.format(self.validator.__name__))
message = self.validator(port_values_clone) # type: ignore # pylint: disable=not-callable
message = self.validator(port_values_clone) # type: ignore
else:
message = self.validator(port_values_clone, self) # pylint: disable=not-callable
message = self.validator(port_values_clone, self)
if message is not None:
assert isinstance(
message, str
Expand Down
Loading

0 comments on commit 9c8fd54

Please sign in to comment.