Description
Hello everyone 👋🏻 I hope you are enjoying the holidays.
Currently the CI is failing https://github.com/Axelrod-Python/Axelrod/actions/runs/3773670578/jobs/6415295764, because of typing issues. I had a look and apparently there are two types of issues:
- “Incompatible default for argument”
For example this error occurs in finite_state_machines.py
at the __init__
of class EvolvableFSMPlayer
:
class EvolvableFSMPlayer(FSMPlayer, EvolvablePlayer):
"""Abstract base class for evolvable finite state machine players."""
...
def __init__(
self,
transitions: tuple = None,
initial_state: int = None,
initial_action: Action = None,
num_states: int = None,
mutation_probability: float = 0.1,
seed: int = None,
) -> None:
Here we declare that transitions
is a tuple
but set None
as a default value and mypy
is not happy with this. I believe there are two ways to fix the above, we either give some default values that have are of correct type or we can use the Optional
type modifier as described on the mypy
documentation: https://mypy.readthedocs.io/en/stable/kinds_of_types.html.
For example if we tweak the __init__
class to be as follows:
def __init__(
self,
transitions: Optional[tuple] = None,
initial_state: Optional[int] = None,
initial_action: Optional[Action] = None,
num_states: Optional[int] = None,
mutation_probability: float = 0.1,
seed: Optional[int] = None,
) -> None:
the tests pass.
- "Missing return statement"
These errors occur because all the return statements are under if
statements, and mypy
is complaining that there is no return statement in case all of the if
statements fail. This can be fixed by slightly changing the code.
I am happy to work on this 👍🏻 could you please let me know what you prefer regarding the errors “Incompatible default for argument”?