Repository: pandas-dev/pandas-stubs (language: python)

Issue:
Index.rename() should return Self
**Describe the bug**
`Index.rename()` should return `Self`

**To Reproduce**
```python
import pandas as pd

ind = pd.Index([1,2,3], name="foo")
ind2 = ind.rename("goo")
reveal_type(ind2)
```
shows that `ind2` is unknown


**Please complete the following information:**
 - OS: Windows 10
 - OS Version ??
 - python version  3.9
 - version of type checker  pyright 1.1.362
 - version of installed `pandas-stubs` :  2.2.2.240514  






Discussion / hints:
Need to fix `rename()` in `core/indexes/base.pyi`
May I take up this issue?
> May I take up this issue?

Assigned to you.  go ahead.  Need a fix and a test.

Fix patch:
diff --git a/pandas-stubs/core/indexes/base.pyi b/pandas-stubs/core/indexes/base.pyi
index 297e9405..ea95aa82 100644
--- a/pandas-stubs/core/indexes/base.pyi
+++ b/pandas-stubs/core/indexes/base.pyi
@@ -292,7 +292,10 @@ class Index(IndexOpsMixin[S1]):
     @names.setter
     def names(self, names: list[_str]): ...
     def set_names(self, names, *, level=..., inplace: bool = ...): ...
-    def rename(self, name, inplace: bool = ...) -> Self: ...
+    @overload
+    def rename(self, name, inplace: Literal[False] = False) -> Self: ...
+    @overload
+    def rename(self, name, inplace: Literal[True]) -> None: ...
     @property
     def nlevels(self) -> int: ...
     def sortlevel(self, level=..., ascending: bool = ..., sort_remaining=...): ...


Test patch:
diff --git a/tests/test_indexes.py b/tests/test_indexes.py
index 46ec843a..75c9fc11 100644
--- a/tests/test_indexes.py
+++ b/tests/test_indexes.py
@@ -121,11 +121,20 @@ def test_str_match() -> None:
 
 
 def test_index_rename() -> None:
+    """Test that index rename returns an element of type Index."""
     ind = pd.Index([1, 2, 3], name="foo")
     ind2 = ind.rename("goo")
     check(assert_type(ind2, "pd.Index[int]"), pd.Index, np.integer)
 
 
+def test_index_rename_inplace() -> None:
+    """Test that index rename in-place does not return anything (None)."""
+    ind = pd.Index([1, 2, 3], name="foo")
+    ind2 = ind.rename("goo", inplace=True)
+    check(assert_type(ind2, None), type(None))
+    assert ind2 is None
+
+
 def test_index_dropna():
     idx = pd.Index([1, 2])