Skip to content

Instantly share code, notes, and snippets.

@cocuh
Last active September 7, 2015 09:26
Show Gist options
  • Save cocuh/8ffed1c9d3ad0f2fc0ed to your computer and use it in GitHub Desktop.
Save cocuh/8ffed1c9d3ad0f2fc0ed to your computer and use it in GitHub Desktop.
override = lambda f:f
class BaseData(object):
pass
class BaseApp(object):
def __init__(self):
self.data = self.build_data()
""":type: BaseData"""
def build_data(self):
return BaseData()
class SpamData(BaseData):
def get_spam(self):
return u'spam'
class SpamApp(BaseApp):
@override
def build_data(self):
return SpamData()
def hoge(self):
data = self.data
""":type: SpamData"""
@cocuh
Copy link
Author

cocuh commented Sep 7, 2015

https://gist.github.com/cocuh/8ffed1c9d3ad0f2fc0ed#file-test-py-L26
でpydocにおいてアップキャストというか、がされてる。

@cocuh
Copy link
Author

cocuh commented Sep 7, 2015

継承したクラスSpamAppが具象化したフィールドの型SpamDataをpydoc上で記述する方法がきになる

@cocuh
Copy link
Author

cocuh commented Sep 7, 2015

pycharmのtype hintingするためだけにこの一文を書くのやめたいだけなのでどっちかというとpycharm側のenhancementかも

class SpamApp(BaseApp):
    def __init__(self):
        super().__init__()
        self.data = self.data
        """:type: SpamData"""

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment