Код: Выделить всё
from typing import TypeVar, Generic, List, NewType
TPopMember = TypeVar('TPopMember')
Population = NewType('Population', List[TPopMember])
class EvolutionaryAlgorithm(Generic[TPopMember]):
def __init__(self, populationSize: int) -> None:
# The following raises TypeError: 'TypeVar' object is not callable
self.__population = Population([TPopMember() for _ in range(populationSize)])
Я использую Python 3.7.2.
Подробнее здесь: https://stackoverflow.com/questions/553 ... -a-typevar
Мобильная версия