BUG: Fix error message for unknown methodtype
State: closed

- [ ] closes #xxxx (Replace xxxx with the GitHub issue number)
- [ ] [Tests added and passed](https://pandas.pydata.org/pandas-docs/dev/development/contributing_codebase.html#writing-tests) if fixing a bug or adding a new feature
- [ ] All [code checks passed](https://pandas.pydata.org/pandas-docs/dev/development/contributing_codebase.html#pre-commit).
- [ ] Added [type annotations](https://pandas.pydata.org/pandas-docs/dev/development/contributing_codebase.html#type-hints) to new arguments/methods/functions.
- [ ] Added an entry in the latest `doc/source/whatsnew/vX.X.X.rst` file if fixing a bug or adding a new feature.


Labels:
name: Error Reporting
description: Incorrect or improved errors from pandas

Comments:
hi @yeesian - this looks right, if you add a test we can get it in
Hi sorry for the slow response and thanks for the ping! I wasn't sure where to be adding the test and what it should look like. Was investigating for a bit but then work caught up so this slipped by, sorry again for stalling here, maybe some pointers can help me
sure

for a start, could you come a up with a small reproducible example which reproduces the issue which you're fixing?
thanks for updating!

could you run the test locally please to check it passes? there are also some pre-commit failures, please check the contributing guide for how to run them
Sorry for the slow updates here, just to give a brief update: I tried following https://pandas.pydata.org/docs/dev/development/contributing_codebase.html#running-the-test-suite but ran into the following error:

```python
$ pytest pandas/tests/test_errors.py
ImportError while loading conftest '.../pandas/pandas/conftest.py'.
pandas/__init__.py:22: in <module>
    from pandas.compat import is_numpy_dev as _is_numpy_dev  # pyright: ignore # noqa:F401
pandas/compat/__init__.py:25: in <module>
    from pandas.compat.numpy import (
pandas/compat/numpy/__init__.py:4: in <module>
    from pandas.util.version import Version
pandas/util/__init__.py:2: in <module>
    from pandas.util._decorators import (  # noqa:F401
pandas/util/_decorators.py:14: in <module>
    from pandas._libs.properties import cache_readonly
pandas/_libs/__init__.py:13: in <module>
    from pandas._libs.interval import Interval
E   ModuleNotFoundError: No module named 'pandas._libs.interval'
```

I tried looking up the error, got some vague advice about uninstalling and reinstalling pandas and gave up.

I think [the precommit failure(s)](https://github.com/pandas-dev/pandas/actions/runs/4520477581/jobs/7961612201#step:8:449) might be coming from the indentation in https://github.com/pandas-dev/pandas/pull/51484/commits/b697aba60edcfade44c09e904e85c7aa5663711b:

```
Couldn't parse '/home/runner/work/pandas/pandas/pandas/tests/test_errors.py' as Python source: 'unexpected indent' at line 115
```

I'll be happy to revert the change in https://github.com/pandas-dev/pandas/pull/51484#discussion_r1148406692 and interpolate the types into the error message just to keep things moving (I personally don't think it's that much logic and it runs the risk of being flakey about the way that sets should be displayed as strings), otherwise I'll rather bail on this PR.
It's failing with the following error, so I guess the test was not exercising the correct codepath:

```
=================================== FAILURES ===================================
_____________________ test_AbstractMethodError_classmethod _____________________
[gw0] linux -- Python 3.8.15 /home/circleci/miniconda3/envs/pandas-dev/bin/python3.8

    def test_AbstractMethodError_classmethod():
        xpr = "This classmethod must be defined in the concrete class Foo"
        with pytest.raises(AbstractMethodError, match=xpr):
            Foo.classmethod()
    
        xpr = "This property must be defined in the concrete class Foo"
        with pytest.raises(AbstractMethodError, match=xpr):
            Foo().property
    
        xpr = "This method must be defined in the concrete class Foo"
        with pytest.raises(AbstractMethodError, match=xpr):
            Foo().method()
    
        types = {"method", "classmethod", "staticmethod", "property"}
        xpr = f"methodtype must be one of {types}, got 'unknownmethod' instead."
        with pytest.raises(AbstractMethodError, match=xpr):
>           Foo().unknownmethod()
E           AttributeError: 'Foo' object has no attribute 'unknownmethod'
```
It's unclear to me why [the initialization of `AbstractMethodError` requires a `methodtype: str`](https://github.com/pandas-dev/pandas/blob/d69eaae79af408b1a941ec42f6ac52a545bc39c0/pandas/errors/__init__.py#L190) to begin with, given that [it's not used anywhere else in the codebase](https://github.com/search?q=repo%3Apandas-dev%2Fpandas+AbstractMethodError&type=code) so I think this PR is addressing hypothetical scenarios that users don't actually hit in practice. (I only came across it while browsing the code through github, saw it and thought to make a one-line change.) A better PR might be to simply remove the argument from the constructor altogether.
> A better PR might be to simply remove the argument from the constructor altogether.

yeah, sure, if it's actually unused that sounds good to me
closing as stale, but thanks for your PR - feel free to open a new PR if you'd like to continue