便利に使おう変数アノテーション -typing.py との楽しいお付き合い-

C825832c4fc71ffdfd44905729281fb0?s=47 Takumi Sueda
September 08, 2017
6.6k

便利に使おう変数アノテーション -typing.py との楽しいお付き合い-

PyCon JP 2017 Conference Day 1

C825832c4fc71ffdfd44905729281fb0?s=128

Takumi Sueda

September 08, 2017
Tweet

Transcript

  1. كٝٔח⢪ֲֶ㢌侧،ظذ٦ءّٝ UZQJOHQZהך嚂׃ְֶ➰ֹさְ .BOJQVMBUJOH7BSJBCMF"OOPUBUJPOTPO3VOUJNF 'PSBZFUBOPUIFSVTBHFPGUZQFIJOUT 5BLVNJ4VFEB 'VMMFS *OD%FWFMPQFS

  2. )J 5BLVNJ4VFEB QVIJUBLV 'VMMFS *OD 1ZUIPO(PMBOH 8FC$SBXMFST"84*OGSBTUSVDUVSF 4PMEFSJOH&NCFEEFE4ZTUFN 

  3. 50$ ˖ 5IFIJTUPSZPGBOOPUBUJPOT ˖ 6TFBOOPUBUJPOTJOSVOUJNF 8IZ  ˖ 1MBOPGQPSUJOH(PMBOH+40/VONBSTIBMFSJOUP1ZUIPO ˖

    3FBEWBSJBCMFBOOPUBUJPOT ˖ 8IBUBSFHFOFSJDUZQFT  ˖ 1SBDUJDF"OBUPNZPGHFOFSJDUZQFT ˖ JGFMTFGPSUZQFJEFOUJDBUJPO 
  4. 5IFIJTUPSZPGBOOPUBUJPOT _،ظذ٦ءّٝך娖〷_ 

  5. 5IFIJTUPSZPGBOOPUBUJPOT  1&1 1&1 1&1 'VODUJPO "OOPUBUJPOT 7BSJBCMF "OOPUBUJPOT 4ZOUBY

    4FNBOUJDT 4ZOUBY 4FNBOUJDT Ԩ ˌ ˌ ˌ ˌ Ԩ ӛ Ԩ ˌ ˌ Ԩ ˌ %FD 4FQ "VH
  6. 1&1 5IFIJTUPSZPGBOOPUBUJPOT  1&1 1&1 'VODUJPO "OOPUBUJPOT 7BSJBCMF "OOPUBUJPOT 4ZOUBY

    4FNBOUJDT 4ZOUBY 4FNBOU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