python-poetry / tomlkit

Style-preserving TOML library for Python
MIT License
701 stars 99 forks source link

Adding np.array and tomlkit.items.Float leads to NotImplementedType #298

Closed Knusbert closed 1 year ago

Knusbert commented 1 year ago

Maybe similar to #214 . This one has a twist as the order of adding seems to be important. Minimal code:

content = '[table]\n new_float = 3.1415'
doc  = tomlkit.parse(content)

np_array = np.random.rand(10)

# this works
doc['table']['new_float']*np_array + doc['table']['new_float']

# this fails
doc['table']['new_float']+doc['table']['new_float']*np_array

error message:

  File "C:\WPy64-3880\python-3.8.8.amd64\lib\site-packages\tomlkit\items.py", line 690, in __add__
    return self._new(result)

  File "C:\WPy64-3880\python-3.8.8.amd64\lib\site-packages\tomlkit\items.py", line 720, in _new
    return Float(result, self._trivia, raw)

  File "C:\WPy64-3880\python-3.8.8.amd64\lib\site-packages\tomlkit\items.py", line 661, in __new__
    return super().__new__(cls, value)

TypeError: float() argument must be a string or a number, not 'NotImplementedType'

python version 3.8.8 tomlkit version 0.11.8 numpy version 1.23.5