que/util.py
def isnamedtuple(x: Any) -> bool:
    """Test whether an object is a named-tuple.

    Named tuples are essentially extended tuples and instance checks don't work.
    The best thing you can do is just test if they have the special attributes that
    differentiate it from a standard tuple.

    Examples
    ------
    >>> from collections import namedtuple
    >>> from typing import NamedTuple
    >>> class Foo(NamedTuple):
    ...     bar: str
    ...
    >>> isnamedtuple(Foo('bar'))
    True
    >>> Foo = namedtuple('Foo', ['bar'])
    >>> isnamedtuple(Foo('bar'))
    True
    >>> isnamedtuple(tuple())
    False
    """
    return isinstance(x, tuple) and hasattr(x, "_fields") and hasattr(x, "_asdict")
Test whether an object is a named-tuple.

    Named tuples are essentially extended tuples and instance checks don't work.
    The best thing you can do is just test if they have the special attributes that
    differentiate it from a standard tuple.

    Examples
    ------
    >>> from collections import namedtuple
    >>> from typing import NamedTuple
    >>> class Foo(NamedTuple):
    ...     bar: str
    ...
    >>> isnamedtuple(Foo('bar'))
    True
    >>> Foo = namedtuple('Foo', ['bar'])
    >>> isnamedtuple(Foo('bar'))
    True
    >>> isnamedtuple(tuple())
    False
    
Test whether an object is a named-tuple.
Named tuples are essentially extended tuples and instance checks don't work.
The best thing you can do is just test if they have the special attributes that
differentiate it from a standard tuple.

Examples


Test whether an object is a named - tuple . Named tuples are essentially extended tuples and instance checks don ' t work . The best thing you can do is just test if they have the special attributes that differentiate it from a standard tuple . Examples
def isnamedtuple(x: Any) -> bool:
    return isinstance(x, tuple) and hasattr(x, "_fields") and hasattr(x, "_asdict")
def isnamedtuple ( x : Any ) -> bool : return isinstance ( x , tuple ) and hasattr ( x , "_fields" ) and hasattr ( x , "_asdict" )
Test whether an object is a named-tuple.
Test whether an object is a named - tuple .
"""Test whether an object is a named-tuple.

    Named tuples are essentially extended tuples and instance checks don't work.
    The best thing you can do is just test if they have the special attributes that
    differentiate it from a standard tuple.

    Examples
    ------
    >>> from collections import namedtuple
    >>> from typing import NamedTuple
    >>> class Foo(NamedTuple):
    ...     bar: str
    ...
    >>> isnamedtuple(Foo('bar'))
    True
    >>> Foo = namedtuple('Foo', ['bar'])
    >>> isnamedtuple(Foo('bar'))
    True
    >>> isnamedtuple(tuple())
    False
    """
x
Any