Repository: sdispater/tomlkit

Issue:
Float subtraction with tomlkit.items.Integer raises a NotImplementedType exception
Subtraction with an `tomlkit.items.Integer` and a basic python `float` leads to a `NotImplementedType` error.

The issue seems to be the same category like the addition issue #214 (with the [same solution](https://github.com/sdispater/tomlkit/pull/215/files)?).

stack trace:
```console
>>> doc['table']['my_int'] - 5.0
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/robot/Library/Python/3.10/lib/python/site-packages/tomlkit/items.py", line 657, in __sub__
    return self._new(result)
  File "/Users/robot/Library/Python/3.10/lib/python/site-packages/tomlkit/items.py", line 673, in _new
    return Integer(result, self._trivia, raw)
  File "/Users/robot/Library/Python/3.10/lib/python/site-packages/tomlkit/items.py", line 617, in __new__
    return super().__new__(cls, value)
TypeError: int() argument must be a string, a bytes-like object or a real number, not 'NotImplementedType'
```

minimal code which reproduces the error:

```py
import tomlkit
content = '[table]\nmy_int = 2048'
doc = tomlkit.parse(content)
doc['table']['my_int'] - 5.0
```

used tomlkit version: `0.11.6`

Discussion:

Patch:
diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
index 22bd503..3a850f7 100644
--- a/.github/workflows/release.yml
+++ b/.github/workflows/release.yml
@@ -11,7 +11,7 @@ jobs:
 
     steps:
       - name: Checkout code
-        uses: actions/checkout@v2
+        uses: actions/checkout@v3
         with:
           submodules: "recursive"
 
@@ -20,7 +20,7 @@ jobs:
         run: echo ::set-output name=tag::${GITHUB_REF#refs/tags/}
 
       - name: Set up Python 3.9
-        uses: actions/setup-python@v2
+        uses: actions/setup-python@v4
         with:
           python-version: "3.9"
 
diff --git a/tomlkit/items.py b/tomlkit/items.py
index 5990eea..da40880 100644
--- a/tomlkit/items.py
+++ b/tomlkit/items.py
@@ -647,28 +647,28 @@ class Integer(int, Item):
         return self._raw
 
     def __add__(self, other):
-        return self._new(int(self._raw) + other)
+        result = super().__add__(other)
+        if result is NotImplemented:
+            return result
+        return self._new(result)
 
     def __radd__(self, other):
         result = super().__radd__(other)
-
-        if isinstance(other, Integer):
-            return self._new(result)
-
-        return result
+        if result is NotImplemented:
+            return result
+        return self._new(result)
 
     def __sub__(self, other):
         result = super().__sub__(other)
-
+        if result is NotImplemented:
+            return result
         return self._new(result)
 
     def __rsub__(self, other):
         result = super().__rsub__(other)
-
-        if isinstance(other, Integer):
-            return self._new(result)
-
-        return result
+        if result is NotImplemented:
+            return result
+        return self._new(result)
 
     def _new(self, result):
         raw = str(result)


Test patch:
diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml
index 6108d6b..ebe25ae 100644
--- a/.github/workflows/tests.yml
+++ b/.github/workflows/tests.yml
@@ -48,7 +48,7 @@ jobs:
 
       - name: Install Poetry
         shell: bash
-        run: curl -fsSL https://install.python-poetry.org | python - -y
+        run: curl -fsSL https://install.python-poetry.org | python - -y --version 1.4.0
 
       - name: Update PATH
         if: ${{ matrix.os != 'Windows' }}
diff --git a/tests/test_items.py b/tests/test_items.py
index 57eba32..45aea25 100644
--- a/tests/test_items.py
+++ b/tests/test_items.py
@@ -579,6 +579,29 @@ bar = "baz"
     )
 
 
+def test_add_float_to_int():
+    content = "[table]\nmy_int = 2043"
+    doc = parse(content)
+    doc["table"]["my_int"] += 5.0
+    assert doc["table"]["my_int"] == 2048.0
+    assert isinstance(doc["table"]["my_int"], float)
+
+
+def test_sub_float_from_int():
+    content = "[table]\nmy_int = 2048"
+    doc = parse(content)
+    doc["table"]["my_int"] -= 5.0
+    assert doc["table"]["my_int"] == 2043.0
+    assert isinstance(doc["table"]["my_int"], float)
+
+
+def test_sub_int_from_float():
+    content = "[table]\nmy_int = 2048.0"
+    doc = parse(content)
+    doc["table"]["my_int"] -= 5
+    assert doc["table"]["my_int"] == 2043.0
+
+
 def test_add_sum_int_with_float():
     content = "[table]\nmy_int = 2048.3"
     doc = parse(content)