@@ -0,0 +1,1447 @@
+# coding: utf-8%0A%22%22%22%0Atyping.NamedTuple %E3%81%AB%E3%81%A4%E3%81%84%E3%81%A6%E3%81%AE%E3%82%B5%E3%83%B3%E3%83%97%E3%83%AB%E3%81%A7%E3%81%99%E3%80%82%0A%22%22%22%0Aimport collections%0Aimport dis%0Aimport sys%0Aimport typing%0A%0Afrom trypython.common.commoncls import SampleBase%0Afrom trypython.common.commonfunc import pr, hr%0A%0A%0Aclass MyData(typing.NamedTuple):%0A    id: int%0A    name: str%0A    age: int%0A%0A%0AMyData2 = collections.namedtuple('MyData2', 'id name age')%0A%0A%0A# noinspection PyArgumentList%0Aclass Sample(SampleBase):%0A    def exec(self):%0A        # ------------------------------------------%0A        # collections.namedtuple%E3%81%A8typing.NamedTuple%0A        # -----------------------------------------%0A        # %E3%81%A9%E3%81%A1%E3%82%89%E3%82%82%E5%90%8C%E3%81%98%E3%83%87%E3%83%BC%E3%82%BF%E6%A7%8B%E9%80%A0%E3%82%92%E4%BD%9C%E3%82%8A%E5%87%BA%E3%81%99%E3%80%82%0A        # %E3%83%90%E3%82%A4%E3%83%88%E3%82%B3%E3%83%BC%E3%83%89%E3%82%82%E5%90%8C%E3%81%98%E3%81%A8%E3%81%AA%E3%82%8B%E3%80%82%0A        # ------------------------------------------%0A        m1 = MyData(1, 'name01', 33)%0A        m2 = MyData2(1, 'name22', 22)%0A        pr('typing.NamedTuple', m1)%0A        pr('collections.namedtuple', m2)%0A%0A        pr('getsizeof(typing.NamedTuple)', sys.getsizeof(m1))%0A        pr('getsizeof(collections.namedtuple)', sys.getsizeof(m2))%0A%0A        try:%0A            m1.name = 'name02'%0A        except AttributeError as e:%0A            pr('typing.NamedTuple is immutable', e)%0A%0A        try:%0A            m2.name = 'name02'%0A        except AttributeError as e:%0A            pr('collections.namedtuple is immutable', e)%0A%0A        hr('dis.dis(MyData)')%0A        dis.dis(MyData.__new__)%0A%0A        hr('dis.dis(MyData2)')%0A        dis.dis(MyData2.__new__)%0A%0A%0Adef go():%0A    obj = Sample()%0A    obj.exec()%0A%0A%0Aif __name__ == '__main__':%0A    go()%0A

add typing01.py