TYP: enable disallow_untyped_decorators
State: closed

- [ ] closes #33455, closes #41588, (closes #43388,  closes #43387)
- [ ] tests added / passed
- [ ] Ensure all linting tests pass, see [here](https://pandas.pydata.org/pandas-docs/dev/development/contributing_codebase.html#pre-commit) for how to run them
- [ ] whatsnew entry

Some of the many type errors unveiled by `cache_readonly` might be easily fixable. This PR simply ignores all the uncovered errors to quickly enable mypy's `disallow_untyped_decorators` to prevent future untyped decorators.

I enabled mypy's `disallow_untyped_decorators` but pyright's `reportUntypedFunctionDecorator` finds the following three functions that are not found by mypy, so I didn't enable `reportUntypedFunctionDecorator` (can't add ignore statements, otherwise mypy will complain about unused ignore statements, edit: using pyright's file-based ignore comments):

- pandas/conftest.py:1505
- ~~pandas/core/util/numba_.py:93~~
- pandas/core/window/numba_.py:244

Labels:
name: Typing
description: type annotations, mypy/pyright type checking

Comments:
The failure from the web-docs: 

> pandas/pandas/core/indexes/datetimes.py:docstring of pandas.core.indexes.datetimes.DatetimeIndex:124: WARNING: autosummary: stub file not found 'pandas.DatetimeIndex.std'. Check your autosummary_generate setting.

seems unrelated, but it looks legit. `DatetimeIndex` inherits the `std` name through a decorator, but the class from which the method is copied has no doc-string for it (pandas/core/arrays/datetimes.py:1917).
> seems unrelated, but it looks legit. DatetimeIndex inherits the std name through a decorator, but the class from which the method is copied has no doc-string for it (pandas/core/arrays/datetimes.py:1917).

yah there are several methods near the top of DatetimeIndex that are there instead of using the decorator for this reason, most of the "# methods that dispatch to DatetimeArray and wrap result" section
> yah there are several methods near the top of DatetimeIndex that are there instead of using the decorator for this reason, most of the "# methods that dispatch to DatetimeArray and wrap result" section

So the solution is to write a doc-string?

I'm surprised that this warning/error occurs only for this PR. The 1.3.3 [documentation of DatetimeIndex](https://pandas.pydata.org/docs/reference/api/pandas.DatetimeIndex.html) has the same issue: 
![image](https://user-images.githubusercontent.com/6618166/137193151-d72c201f-ab66-4be5-859e-0a92eb8656fa.png)



> So the solution is to write a doc-string?

IIRC the motivation was for mypy, not docstrings.  the decorator should handle docstrings correctly.
The decorator seems to handle doc-strings correctly, all other attributes (for example `tz`)  have their doc-string string in the web-documentation. The main difference between `tz` and `std` is that `DatetimeArray.tz` has a doc-string while `DatetimeArray.std` has none: `DatetimeIndex.tz` has therefore a doc-string but `DatetimeIndex.std` doesn't have a doc-string.

I will write a doc-string in a separate PR.

But I don't understand why this PR causes this issue.
Should be ready for review :)
cc @simonjayhawkins 
> I enabled mypy's `disallow_untyped_decorators` but pyright's `reportUntypedFunctionDecorator` finds the following three functions that are not found by mypy, so I didn't enable `reportUntypedFunctionDecorator` (can't add ignore statements, otherwise mypy will complain about unused ignore statements):
> 
> * pandas/conftest.py:1505
> * pandas/core/util/numba_.py:93
> * pandas/core/window/numba_.py:244

maybe open an issue after this is merged.
(or use module level pyright comment syntax)
> Some of the many type errors unveiled by `cache_readonly` might be easily fixable. This PR simply ignores all the uncovered errors to quickly enable mypy's `disallow_untyped_decorators` to prevent future untyped decorators.

SGTM
Rebased and addressed the big comments.

If it is green, it should be ready for merging from my perspective.
> If it is green, it should be ready for merging from my perspective.

sure. @jreback @jbrockmendel any further comments?
There is something failing related due to the numba wrapper, will debug that
I think numba analyzes the source code to JIT it. I think the errors are a results of jitting a function that itself has a jitted function where the inner function is jitted with `typed_numba_jit`.
I think I have to revert the numba-wrapper: https://numba.pydata.org/numba-doc/dev/reference/pysupported.html#functions-as-arguments. It would be great to clean up all the ignore statement for `numba.jit` calls but I'm te wrong person for that - not familiar with numba and how pandas uses it.

@simonjayhawkins let me know if you see a simple non-intrusive way that could avoid the ignore statements for this PR. Otherwise, I will revert the commit that added `typed_numba_jit`.
> @simonjayhawkins let me know if you see a simple non-intrusive way that could avoid the ignore statements for this PR. Otherwise, I will revert the commit that added `typed_numba_jit`.

no problem leaving that out of this PR. The method I'm working with would not prevent the ignores but does providing typing for the "pandas lib api". I use that term loosely as meaning anything coded in Cython, as this is otherwise not formalized. https://github.com/simonjayhawkins/pandas/blob/ec8f0397b5c4a232e8e3e7abfbec91e9ea33016a/pandas/_libs_numba/algos.py#L245-L255

It'll probably be better to write out own stubs for now and include them in the main repo
I removed the numba wrapper and rebased
The isinstance change and rebased after #44144
@twoertwein can you resolve conflicts
> I removed the numba wrapper and rebased

i've opened #44233 that we could maybe merge after this.
> i've opened #44233 that we could maybe merge after this.

Great! I'll rebase this PR to resolve the conflicts with master.
Hello @twoertwein! Thanks for updating this PR. We checked the lines you've touched for [PEP 8](https://www.python.org/dev/peps/pep-0008) issues, and found:



















































There are currently no PEP 8 issues detected in this Pull Request. Cheers! :beers: 

##### Comment last updated at 2021-10-30 11:55:31 UTC
nice thanks @twoertwein and @simonjayhawkins for the review.