Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix (some) errors reported by mypy #696

Merged
merged 1 commit into from
Mar 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 5 additions & 5 deletions fwdpy11/_functions/data_matrix_from_tables.py
Expand Up @@ -22,15 +22,15 @@
import numpy as np

from .._fwdpy11 import _data_matrix_from_tables, _make_data_matrix
from .._types import DataMatrix
from .._types import DataMatrix, DiploidPopulation, TableCollection


def make_data_matrix(
pop: "fwdpy11.DiploidPopulation",
pop: DiploidPopulation,
samples: Union[List, np.ndarray],
record_neutral: bool,
record_selected: bool,
) -> "fwdpy11.DataMatrix":
) -> DataMatrix:
"""
Create a :class:`fwdpy11.DataMatrix` from a table collection.

Expand Down Expand Up @@ -58,15 +58,15 @@ def make_data_matrix(


def data_matrix_from_tables(
tables: "fwdpy11.TableCollection",
tables: TableCollection,
samples: Union[List, np.ndarray],
*,
record_neutral: bool = True,
record_selected: bool = True,
include_fixations: bool = False,
begin: float = 0.0,
end: Optional[float] = None,
) -> "fwdpy11.DataMatrix":
) -> DataMatrix:
"""
Create a :class:`fwdpy11.DataMatrix` from a table collection.

Expand Down
6 changes: 3 additions & 3 deletions fwdpy11/_types/data_matrix.py
Expand Up @@ -21,7 +21,7 @@

import numpy as np

from .._fwdpy11 import ll_DataMatrix
from .._fwdpy11 import ll_DataMatrix, StateMatrix


class DataMatrix(ll_DataMatrix):
Expand Down Expand Up @@ -55,7 +55,7 @@ def ncol(self) -> int:
return self._ncol

@property
def neutral(self) -> "fwdpy11.StateMatrix":
def neutral(self) -> StateMatrix:
""":class:`fwdpy11.StateMatrix` for neutral variants"""
return self._neutral

Expand All @@ -65,7 +65,7 @@ def neutral_keys(self) -> List[int]:
return self._neutral_keys

@property
def selected(self) -> "fwdpy11.StateMatrix":
def selected(self) -> StateMatrix:
""":class:`fwdpy11.StateMatrix` for selected variants"""
return self._selected

Expand Down
3 changes: 2 additions & 1 deletion fwdpy11/_types/data_matrix_iterator.py
Expand Up @@ -22,6 +22,7 @@
import numpy as np

from .._fwdpy11 import ll_DataMatrixIterator
from .._types import TableCollection


class DataMatrixIterator(ll_DataMatrixIterator):
Expand Down Expand Up @@ -60,7 +61,7 @@ class DataMatrixIterator(ll_DataMatrixIterator):

def __init__(
self,
tables: "fwdpy11.TableCollection",
tables: TableCollection,
samples: Union[List[int], np.ndarray],
intervals: List[Tuple[float, float]],
neutral: bool,
Expand Down
18 changes: 13 additions & 5 deletions fwdpy11/_types/demography_debugger.py
Expand Up @@ -18,13 +18,17 @@
#
import collections
import copy
import typing
import warnings
from typing import Dict, List, Optional, Union

import attr
import fwdpy11
import numpy as np

from ..demographic_models import DemographicModelDetails
from ..discrete_demography import DiscreteDemography
from .diploid_population import DiploidPopulation


def _create_event_list(o):
try:
Expand Down Expand Up @@ -86,10 +90,14 @@ class DemographyDebugger(object):
A list of initial deme sizes is now accepted.
"""

initial_deme_sizes = attr.ib(converter=_create_initial_deme_sizes)
_events = attr.ib(converter=_create_event_list)
simlen = attr.ib(converter=_convert_simlen, default=None)
deme_labels = attr.ib(default=None)
initial_deme_sizes: Union[List[int], DiploidPopulation] = attr.ib(
converter=_create_initial_deme_sizes
)
_events: Union[DiscreteDemography, DemographicModelDetails] = attr.ib(
converter=_create_event_list
)
simlen: int = attr.ib(converter=_convert_simlen, default=None)
deme_labels: Optional[Dict] = attr.ib(default=None)

def __attrs_post_init__(self):
self._validate_migration_rate_change_lengths(self._events)
Expand Down
24 changes: 12 additions & 12 deletions fwdpy11/_types/diploid_population.py
@@ -1,16 +1,16 @@
from typing import IO, Dict, Iterable, Iterator, List, Optional, Tuple, Union

import fwdpy11._fwdpy11
import fwdpy11._types
import fwdpy11.tskit_tools._dump_tables_to_tskit
import numpy as np
import tskit

from .._fwdpy11 import DiploidGenotype, DiploidMetadata, ll_DiploidPopulation
from .population_mixin import PopulationMixin
from .table_collection import TableCollection


class DiploidPopulation(fwdpy11._fwdpy11.ll_DiploidPopulation, PopulationMixin):
class DiploidPopulation(ll_DiploidPopulation, PopulationMixin):
"""
A population of diploid individuals.

Expand All @@ -29,7 +29,7 @@ def __init__(
N: Union[int, List[int]],
length: float,
*,
ll_pop: Optional[fwdpy11._fwdpy11.ll_DiploidPopulation] = None
ll_pop: Optional[ll_DiploidPopulation] = None
):
if ll_pop is None:
super(DiploidPopulation, self).__init__(N, length)
Expand All @@ -39,7 +39,7 @@ def __init__(
self._pytables = TableCollection(self._tables)

@classmethod
def create_from_tskit(cls, ts: tskit.TreeSequence) -> "fwdpy11.DiploidPopulation":
def create_from_tskit(cls, ts: tskit.TreeSequence):
"""
Create a new object from an tskit.TreeSequence

Expand All @@ -63,23 +63,23 @@ def create_from_tskit(cls, ts: tskit.TreeSequence) -> "fwdpy11.DiploidPopulation
for example.)

"""
ll = fwdpy11._fwdpy11.ll_DiploidPopulation._create_from_tskit(ts)
ll = ll_DiploidPopulation._create_from_tskit(ts)
return cls(0, 0.0, ll_pop=ll)

@classmethod
def load_from_file(cls, filename: str) -> "fwdpy11.DiploidPopulation":
def load_from_file(cls, filename: str):
"""
Load population from the output of
:func:`fwdpy11.DiploidPopulation.dump_to_file`.

:param filename: A file name
:type filename: str
"""
ll = fwdpy11._fwdpy11.ll_DiploidPopulation._load_from_file(filename)
ll = ll_DiploidPopulation._load_from_file(filename)
return cls(0, 0.0, ll_pop=ll)

@classmethod
def load_from_pickle_file(cls, filename: IO) -> "fwdpy11.DiploidPopulation":
def load_from_pickle_file(cls, filename: IO):
"""
Read in a pickled population from a file.
The file muse have been generated by
Expand All @@ -90,7 +90,7 @@ def load_from_pickle_file(cls, filename: IO) -> "fwdpy11.DiploidPopulation":
.. versionadded: 0.3.0

"""
ll = fwdpy11._fwdpy11.ll_DiploidPopulation._load_from_pickle_file(filename)
ll = ll_DiploidPopulation._load_from_pickle_file(filename)
return cls(0, 0.0, ll_pop=ll)

@property
Expand All @@ -115,17 +115,17 @@ def ancient_sample_nodes(self) -> np.ndarray:
return self.preserved_nodes

@property
def ancient_sample_metadata(self) -> Iterable[fwdpy11.DiploidMetadata]:
def ancient_sample_metadata(self) -> Iterable[DiploidMetadata]:
"""Supports buffer protocol"""
return self._ancient_sample_metadata

@property
def diploids(self) -> Iterable[fwdpy11.DiploidGenotype]:
def diploids(self) -> Iterable[DiploidGenotype]:
"""Supports buffer protocol"""
return self._diploids

@property
def diploid_metadata(self) -> Iterable[fwdpy11.DiploidMetadata]:
def diploid_metadata(self) -> Iterable[DiploidMetadata]:
"""Supports buffer protocol"""
return self._diploid_metadata

Expand Down
14 changes: 3 additions & 11 deletions fwdpy11/_types/model_params.py
Expand Up @@ -19,23 +19,15 @@
import warnings

import attr
import numpy as np

import fwdpy11
import numpy as np
from fwdpy11.class_decorators import (attr_add_asblack,
attr_class_to_from_dict_no_recurse)

_common_attr_attribs = {
"kw_only": True,
"frozen": True,
"slots": True,
"repr_ns": "fwdpy11",
}


@attr_add_asblack
@attr_class_to_from_dict_no_recurse
@attr.s(**_common_attr_attribs)
@attr.s(kw_only=True, frozen=True, slots=True, repr_ns="fwdpy11")
class MutationAndRecombinationRates(object):
"""
Stores and validates the mutation and recombination rate parameters
Expand Down Expand Up @@ -107,7 +99,7 @@ def _convert_demography(o):

@attr_add_asblack
@attr_class_to_from_dict_no_recurse
@attr.s(**_common_attr_attribs)
@attr.s(kw_only=True, frozen=True, slots=True, repr_ns="fwdpy11")
class ModelParams(object):
"""
This class stores and validates the parameters of a simulation.
Expand Down
42 changes: 21 additions & 21 deletions fwdpy11/_types/population_mixin.py
Expand Up @@ -16,12 +16,12 @@
# You should have received a copy of the GNU General Public License
# along with fwdpy11. If not, see <http://www.gnu.org/licenses/>.
#
from typing import Dict, Optional, Iterable
from typing import Dict, Iterable, Optional

import fwdpy11
import fwdpy11._fwdpy11
import numpy as np

from .._fwdpy11 import HaploidGenome, Mutation


class PopulationMixin(object):
@property
Expand All @@ -35,19 +35,19 @@ def ancient_sample_genetic_values(self) -> np.ndarray:
.. versionadded 0.3.0

"""
return self._ancient_sample_genetic_values
return self._ancient_sample_genetic_values # type: ignore

@property
def fixations(self) -> Iterable[fwdpy11.Mutation]:
return self._fixations
def fixations(self) -> Iterable[Mutation]:
return self._fixations # type: ignore

@property
def fixation_times(self) -> Iterable[int]:
return self._fixation_times
return self._fixation_times # type: ignore

@property
def generation(self) -> int:
return self._generation
return self._generation # type: ignore

@property
def genetic_values(self) -> np.ndarray:
Expand All @@ -59,34 +59,34 @@ def genetic_values(self) -> np.ndarray:
.. versionadded 0.3.0

"""
return self._genetic_values
return self._genetic_values # type: ignore

@property
def haploid_genomes(self) -> Iterable[fwdpy11.HaploidGenome]:
return self._haploid_genomes
def haploid_genomes(self) -> Iterable[HaploidGenome]:
return self._haploid_genomes # type: ignore

@property
def mcounts(self) -> Iterable[int]:
return self._mcounts
return self._mcounts # type: ignore

@property
def mcounts_ancient_samples(self) -> Iterable[int]:
return self._mcounts_ancient_samples
return self._mcounts_ancient_samples # type: ignore

def mutation_indexes(self, pos) -> Optional[np.ndarray]:
"""
Return indexes in :attr:`fwdpy11.DiploidPopulation.mutations`
that are mutations at postion `pos`.
"""
return self._mutation_indexes(pos)
return self._mutation_indexes(pos) # type: ignore

@property
def mut_lookup(self) -> Dict:
return self._mut_lookup
return self._mut_lookup # type: ignore

@property
def mutations(self) -> Iterable[fwdpy11.Mutation]:
return self._mutations
def mutations(self) -> Iterable[Mutation]:
return self._mutations # type: ignore

@property
def mutations_ndarray(self) -> np.ndarray:
Expand All @@ -100,11 +100,11 @@ def mutations_ndarray(self) -> np.ndarray:

.. versionadded:: 0.4.0
"""
return self._mutations_ndarray
return self._mutations_ndarray # type: ignore

@property
def N(self):
return self._N
return self._N # type: ignore

def find_fixation_by_key(self, key, offset=0):
"""
Expand All @@ -122,7 +122,7 @@ def find_fixation_by_key(self, key, offset=0):
.. versionadded:: 0.2.0

"""
return self._find_fixation_by_key(key, offset)
return self._find_fixation_by_key(key, offset) # type: ignore

def find_mutation_by_key(self, key, offset):
"""
Expand All @@ -140,4 +140,4 @@ def find_mutation_by_key(self, key, offset):
.. versionadded:: 0.2.0

"""
return self._find_mutation_by_key(key, offset)
return self._find_mutation_by_key(key, offset) # type: ignore