PyConJP2017に参加しました

PyConJP2017に参加してきました。1日目が終了したのでとりあえずメモ。

見てきた物リスト&メモ

その他1

色々ひどいまとめだけど、ひどいついでに試しに実行したやつをそのまま貼り付ける

In [1]: import typing

In [8]: def f(arg: List[str]) -> List[str]:
   ...:     return arg
   ...: 

In [9]: f(['hoge', 'piy'])
Out[9]: ['hoge', 'piy']

In [10]: f([1, 2, 3])
Out[10]: [1, 2, 3] # 実行時型チェックするわけではないのだな(?) IPythonだったからか?

In [12]: List[str].mro() # mro()、初知り
Out[12]: 
[typing.List[str],
 typing.List,
 list,
 typing.MutableSequence,
 collections.abc.MutableSequence,
 typing.Sequence,
 collections.abc.Sequence,
 typing.Reversible,
 collections.abc.Reversible,
 typing.Collection,
 collections.abc.Collection,
 collections.abc.Sized,
 typing.Iterable,
 collections.abc.Iterable,
 typing.Container,
 collections.abc.Container,
 typing.Generic,
 object]

In [13]: List[str].__args__
Out[13]: (str,)

In [14]: List[List[str]].__args__
Out[14]: (typing.List[str],)

In [15]: Optional[str].__args__
Out[15]: (str, NoneType)

In [16]: int in vars(__builtins__).values()
Out[16]: True


In [17]: class WaruiObj:
    ...:     def __len__(self):
    ...:         return '0'
    ...:     

In [18]: len(WaruiObj())
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-18-49ec83f96080> in <module>()
----> 1 len(WaruiObj())

TypeError: 'str' object cannot be interpreted as an integer

In [19]: # len() Adapter

In [20]: len(1)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-20-8b3587a43b59> in <module>()
----> 1 len(1)

TypeError: object of type 'int' has no len()

In [21]: # デザインと歴史FAQ

In [22]: iter([1,2,3,4])
Out[22]: <list_iterator at 0x7f84595512e8>

その他2

  • @puhitaku さんとお知り合いに。スク水はいいぞ
  • 今まで書いてたコンピュータの理論と実装の本は完全に3日坊主状態になりました()