2016-06-07 146 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年被釋放。

相關問題