内置的join函数使用了哪些方法?

What methods does the built-in join function use?

我正在尝试使用

a = ''.join((Symbol('a'), Symbol('b'))

但我明白了

File "/home/j/_Github-Projects/MiscScripts/string_permutations.py", line 72, in get_permutations
    permutation = Symbol(''.join(permutation))
TypeError: sequence item 0: expected str instance, Symbol found

python 文档说接受一个可迭代对象作为 join 的参数,但这似乎与异常告诉我的内容相矛盾。

我尝试在 Symbol 中定义一些基本 class 方法,但没有帮助。

def __concat__(self, other):
    return Symbol(self.symbol + other.symbol)
__add__ = __concat__
__and__ = __concat__

def __iconcat__(self, other):
    self.symbol += other.symbol
    return self

str.join(iterable) docs

doc 还说:

A TypeError will be raised if there are any non-string values in iterable...

毕竟,Symbol('a') 不是字符串。

好的,应该这样做,而不是 join

        permutation = functools.reduce(
            lambda x, y: x.concatenate(y),
            permutation)

动态语言的乐趣,看了一眼参数名,却不知道只接受某些值类型。