i know if python 3.5 type hinting (the typing module) supports return type covariance, pycharm's autocompletion.
here base classes sports framework:
class baseleague: def get_teams(self) -> list[baseteam]: ... ... class baseteam: def get_captain(self) -> baseplayer: ... def get_players(self) -> list[baseplayer]: ... ... class baseplayer: team = none # type: baseteam ... (there many more methods left out, methods on baseleague returning baseteam/baseplayer/baseleague objects, etc.)
i have multiple modules subclass these 3 classes in parallel, , add/override methods , attributes.
in hockey/models.py, have:
class league(baseleague): ... class team(baseteam): ... class player(baseplayer): ... and in football/models.py, have same thing:
class league(baseleague): .... class team(baseteam): ... class player(baseplayer): ... (i have 20+ other sports, soccer, baseball, etc..)
in pycharm, when i'm in football.models.team , type self.get_captain()., pycharm shows me attributes base class baseplayer, show me attributes subclass football.models.player. seems closely related return type covariance.
i have feeling need use generic , typevar this:
player = typevar('player', covariant=true) team = typevar('team', covariant=true) league = typevar('league', covariant=true) class baseteam(generic[player, team, league]): def get_players(self) -> list[player]: ... and in football.models like:
class team(baseteam[player, team, league]): ...where player, team, league references subclasses in same module.
but it's not working (pycharm not showing autocomplete @ all), , i'm not sure if i'm using right syntax.
i working because base classes part of framework's api, , users subclass them hundreds of times, i'd them benefit pycharm autocomplete, without having override each method in own code.)
does know if possible?
Comments
Post a Comment