Skip to content

Commit

Permalink
fix generic namedtuple support when the class is
Browse files Browse the repository at this point in the history
Summary:
X-link: pytorch/pytorch#141360
Approved by: https://github.com/jansel

Reviewed By: atalman

Differential Revision: D66524965

fbshipit-source-id: 9033a6685cbaf2c023b1ee8ce60e7680deeb0650
  • Loading branch information
XuehaiPan authored and facebook-github-bot committed Dec 2, 2024
1 parent 9f8813e commit 82a8a60
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions userbenchmark/dynamo/dynamobench/_dynamo/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
Deque,
Dict,
Generator,
Generic,
Iterable,
Iterator,
KeysView,
Expand Down Expand Up @@ -1597,14 +1598,19 @@ def is_namedtuple_cls(cls):
if isinstance(getattr(cls, "_fields", None), tuple) and callable(
getattr(cls, "_make", None)
):
if cls.__bases__ == (tuple,):
# The subclassing style namedtuple can have an extra base `typing.Generic`
bases = tuple(t for t in cls.__bases__ if t is not Generic)
if bases == (tuple,):
# This is a namedtuple type directly created by `collections.namedtuple(...)`
return True
if (
# Subclass of namedtuple
is_namedtuple_cls(cls.__bases__[0])
# For subclasses of namedtuple, the __new__ method should not be customized
and cls.__new__ is cls.__bases__[0].__new__
if bases and any(
(
# Subclass of namedtuple
is_namedtuple_cls(t)
# For subclasses of namedtuple, the __new__ method should not be customized
and cls.__new__ is t.__new__
)
for t in bases
):
return True
except TypeError:
Expand Down

0 comments on commit 82a8a60

Please sign in to comment.