元组未定义,但它包含信息



我正在寻找一个模块ifcopenshell,我看到了一个非常奇怪的函数:

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import functools
import numbers
import itertools
from . import ifcopenshell_wrapper
try:
import logging
except ImportError as e:
logging = type('logger', (object,), {'exception': staticmethod(lambda s: print(s))})
class entity_instance(object):
def __init__(self, e):
if isinstance(e, tuple):
e = ifcopenshell_wrapper.new_IfcBaseClass(*e)
super(entity_instance, self).__setattr__('wrapped_data', e)

在这种情况下,tuple在任何地方都没有明确定义,但它包含一个值。我的假设是tuple来自一个导入。是这样吗?如何跟踪tuple的来源?

以下是函数的注释:

定义:isistance(o:object,t:Union[type,Tuple[Union[type,Tuple[Any,…]],…]]、/(->bool返回对象是类的实例还是其子类的实例。元组,如isistance(x,(A,B,…((,可以作为检查的目标。这相当于isistance(x,A(或isistance((x,B(或。。。等

tuple是一个内置的类型,类似于intstr。自己试试:

>>> x = (3, 4)
>>> tuple
<class 'tuple'>
>>> isinstance(x, tuple)
True
>>> isinstance(x, str)
False

最新更新