Open marksteward opened 3 years ago
Apparently there's no easy way to detect namedtuples other than existence of these not-quite-magic methods. This feels like a footgun, but I'm not sure how to fix it now.
From https://bugs.python.org/issue7796, it seems that the "easiest" way to check if we're dealing with a namedtuple
is to check that the type is tuple
and that it has a _fields
attribute.
Also see this answer from A. Martelli on SO: https://stackoverflow.com/a/2166841
I think these should read namedtuple:
https://github.com/Infinidat/munch/blob/d0aeb06/munch/__init__.py#L461 https://github.com/Infinidat/munch/blob/d0aeb06/munch/__init__.py#L523
Currently, if a custom class inherits from tuple and an instance ends up with a _make attribute, munch will call it when the
__dict__
attribute is accessed. Unlikely to happen by chance, but munch also inserts itself into SafeLoader, so it should probably err on the defensive side.