2016-06-07 141 views
4

我正在使用Python 3.5来做doctest。总是有一个错误:Python 3.5:TypeError:__init __()得到了一个意外的关键字参数'nosigint'

File "D:\Program Files\Anaconda\lib\doctest.py", line 357, in __init__ 
    pdb.Pdb.__init__(self, stdout=out, nosigint=True) 

TypeError: __init__() got an unexpected keyword argument 'nosigint' 

看来,错误发生在doctest.py文件中,但不是在我自己的代码中。

我希望能定义一个类似于dict的类。我的代码是:

class Dict(dict): 
    ''' 
    Simple dict but also support access as x.y style. 

    >>> d1 = Dict() 
    >>> d1['x'] = 100 
    >>> d1.x 
    100 
    >>> d1.y = 200 
    >>> d1['y'] 
    200 
    >>> d2 = Dict(a=1, b=2, c='3') 
    >>> d2.c 
    '3' 
    >>> d2['empty'] 
    Traceback (most recent call last): 
     ... 
    KeyError: 'empty' 
    >>> d2.empty 
    Traceback (most recent call last): 
     ... 
    AttributeError: 'Dict' object has no attribute 'empty' 
    ''' 
    def __init__(self, **kw): 
     super(Dict, self).__init__(**kw) 

    def __getattr__(self, key): 
     try: 
      return self[key] 
     except KeyError: 
      raise AttributeError(r"'Dict' object has no attribute '%s'" % key) 

    def __setattr__(self, key, value): 
     self[key] = value 

if __name__=='__main__': 
    import doctest 
    doctest.testmod() 

你能帮助我吗?

回答

3

看起来你正在使用Anaconda Python发行版。

您是否正在使用Spyder IDE运行?

Spyder的问题跟踪器中有一个open bug

建议的解决方法涉及修改pdbdoctest的来源。

For a shoddy quick fix you can remove the

nosigint=True argument from the pdb.Pdb.init in doctest.py

and change the default value of nosigint to True in pdb.py

,如果你正受到这个错误,你可以鼓励谁做的Spyder通过Subscribing to Notifications about this issue on GitHub

+1

我正在使用Spyder IDE。谢谢。 – Dawn

2

有,我已经习惯了解决此bug的另一个潜在的解决方案来解决它的人。您可以将__init__方法添加到SpyderPdb类中,该类为缺失的nosigint参数设置默认值。

我使用WinPython发行版来获取Spyder,但它可能与Anaconda类似。对于Python 3.5+,它位于:\ WinPython ... \ python ... \ Lib \ site-packages \ spyder \ utils \ site \ sitecustomize.py

对于早期版本,它可能位于... \ Lib \站点包\ spyderlib \部件\ externalshell \ sitecustomize.py

class SpyderPdb(pdb.Pdb): 
    def __init__(self, completekey='tab', stdin=None, stdout=None, skip=None, nosigint=False): 
     super(pdb.Pdb, self).__init__() 
1

Spyder的开发商在这里)这个问题将被固定在Spyder的3.1.4,在三月中旬/ 2017年被释放。

相关问题