Fix type annotations in pandas.core.dtypes
State: closed

- [X] closes #26028
- [X] tests passed
- [X] passes `git diff upstream/master -u -- "*.py" | flake8 --diff`

This one was more complicated than other annotation corrections I've done. The following errors persisted even if the two type definitions in `PandasExtensionDtype` and `ExtensionDtype` were identical:
```
pandas/core/dtypes/dtypes.py:175: error: Definition of "type" in base class "PandasExtensionDtype" is incompatible with definition in base class "ExtensionDtype"
pandas/core/dtypes/dtypes.py:175: error: Definition of "kind" in base class "PandasExtensionDtype" is incompatible with definition in base class "ExtensionDtype"
pandas/core/dtypes/dtypes.py:577: error: Definition of "type" in base class "PandasExtensionDtype" is incompatible with definition in base class "ExtensionDtype"
pandas/core/dtypes/dtypes.py:577: error: Definition of "kind" in base class "PandasExtensionDtype" is incompatible with definition in base class "ExtensionDtype"
pandas/core/dtypes/dtypes.py:732: error: Definition of "kind" in base class "ExtensionDtype" is incompatible with definition in base class "PandasExtensionDtype"
pandas/core/dtypes/dtypes.py:732: error: Definition of "type" in base class "ExtensionDtype" is incompatible with definition in base class "PandasExtensionDtype"
pandas/core/dtypes/dtypes.py:855: error: Definition of "type" in base class "PandasExtensionDtype" is incompatible with definition in base class "ExtensionDtype"
pandas/core/dtypes/dtypes.py:855: error: Definition of "kind" in base class "PandasExtensionDtype" is incompatible with definition in base class "ExtensionDtype"
```

I suspect this has something to do with how mypy handles classes with multiple inheritance and maybe even @property-decorated accessors. See, e.g., https://github.com/python/mypy/pull/6585.

So to address the issue, I left the annotations in pandas.core.dtypes.base.ExtensionDtype.type and .kind (abstract-ish with @property decorators) alone but for a format change. I set the corresponding `type` and `kind` variables in `PandasExtensionDtype` to take the `Any` type explicitly to "correct" the mypy error. Then to provide actual type checking I explicitly typed the `kind` and `type` variables in the subclasses, i.e., CategoricalDtype, DatetimeTZDtype, etc.

Not sure if this is the best approach, but it is a functioning approach that provides static type checking. 

This commit addresses all the following errors:
<details>

```
pandas/core/dtypes/dtypes.py:112: error: Need type annotation for 'shape'
pandas/core/dtypes/dtypes.py:117: error: Need type annotation for '_cache'
pandas/core/dtypes/dtypes.py:175: error: Definition of "type" in base class "PandasExtensionDtype" is incompatible with definition in base class "ExtensionDtype"
pandas/core/dtypes/dtypes.py:175: error: Definition of "kind" in base class "PandasExtensionDtype" is incompatible with definition in base class "ExtensionDtype"
pandas/core/dtypes/dtypes.py:220: error: Incompatible types in assignment (expression has type "Type[CategoricalDtypeType]", base class "PandasExtensionDtype" defined the type as "None")
pandas/core/dtypes/dtypes.py:221: error: Incompatible types in assignment (expression has type "str", base class "PandasExtensionDtype" defined the type as "None")
pandas/core/dtypes/dtypes.py:222: error: Incompatible types in assignment (expression has type "str", base class "PandasExtensionDtype" defined the type as "None")
pandas/core/dtypes/dtypes.py:224: error: Incompatible types in assignment (expression has type "Tuple[str, str]", base class "_DtypeOpsMixin" defined the type as "Tuple[]")
pandas/core/dtypes/dtypes.py:225: error: Need type annotation for '_cache'
pandas/core/dtypes/dtypes.py:577: error: Definition of "type" in base class "PandasExtensionDtype" is incompatible with definition in base class "ExtensionDtype"
pandas/core/dtypes/dtypes.py:577: error: Definition of "kind" in base class "PandasExtensionDtype" is incompatible with definition in base class "ExtensionDtype"
pandas/core/dtypes/dtypes.py:588: error: Incompatible types in assignment (expression has type "str", base class "PandasExtensionDtype" defined the type as "None")
pandas/core/dtypes/dtypes.py:589: error: Incompatible types in assignment (expression has type "str", base class "PandasExtensionDtype" defined the type as "None")
pandas/core/dtypes/dtypes.py:593: error: Incompatible types in assignment (expression has type "Tuple[str, str]", base class "_DtypeOpsMixin" defined the type as "Tuple[]")
pandas/core/dtypes/dtypes.py:595: error: Need type annotation for '_cache'
pandas/core/dtypes/dtypes.py:732: error: Definition of "kind" in base class "ExtensionDtype" is incompatible with definition in base class "PandasExtensionDtype"
pandas/core/dtypes/dtypes.py:732: error: Definition of "type" in base class "ExtensionDtype" is incompatible with definition in base class "PandasExtensionDtype"
pandas/core/dtypes/dtypes.py:740: error: Incompatible types in assignment (expression has type "str", base class "PandasExtensionDtype" defined the type as "None")
pandas/core/dtypes/dtypes.py:741: error: Incompatible types in assignment (expression has type "str", base class "PandasExtensionDtype" defined the type as "None")
pandas/core/dtypes/dtypes.py:744: error: Incompatible types in assignment (expression has type "Tuple[str]", base class "_DtypeOpsMixin" defined the type as "Tuple[]")
pandas/core/dtypes/dtypes.py:746: error: Need type annotation for '_cache'
pandas/core/dtypes/dtypes.py:855: error: Definition of "type" in base class "PandasExtensionDtype" is incompatible with definition in base class "ExtensionDtype"
pandas/core/dtypes/dtypes.py:855: error: Definition of "kind" in base class "PandasExtensionDtype" is incompatible with definition in base class "ExtensionDtype"
pandas/core/dtypes/dtypes.py:864: error: Incompatible types in assignment (expression has type "str", base class "PandasExtensionDtype" defined the type as "None")
pandas/core/dtypes/dtypes.py:867: error: Incompatible types in assignment (expression has type "Tuple[str]", base class "_DtypeOpsMixin" defined the type as "Tuple[]")
pandas/core/dtypes/dtypes.py:869: error: Need type annotation for '_cache'

pandas/core/dtypes/missing.py:6: error: Module 'pandas._libs' has no attribute 'missing'
```
</details>

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

Comments:
# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/26029?src=pr&el=h1) Report
> Merging [#26029](https://codecov.io/gh/pandas-dev/pandas/pull/26029?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/0610a60d06c190cdd597480962f98b97de7b4286?src=pr&el=desc) will **decrease** coverage by `<.01%`.
> The diff coverage is `100%`.

[![Impacted file tree graph](https://codecov.io/gh/pandas-dev/pandas/pull/26029/graphs/tree.svg?width=650&token=eZ4WkYLtcO&height=150&src=pr)](https://codecov.io/gh/pandas-dev/pandas/pull/26029?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master   #26029      +/-   ##
==========================================
- Coverage   91.82%   91.82%   -0.01%     
==========================================
  Files         175      175              
  Lines       52540    52544       +4     
==========================================
  Hits        48247    48247              
- Misses       4293     4297       +4
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `90.38% <100%> (ø)` | :arrow_up: |
| #single | `40.73% <100%> (-0.13%)` | :arrow_down: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/26029?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/core/dtypes/base.py](https://codecov.io/gh/pandas-dev/pandas/pull/26029/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZHR5cGVzL2Jhc2UucHk=) | `100% <100%> (ø)` | :arrow_up: |
| [pandas/core/dtypes/missing.py](https://codecov.io/gh/pandas-dev/pandas/pull/26029/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZHR5cGVzL21pc3NpbmcucHk=) | `93.33% <100%> (+0.04%)` | :arrow_up: |
| [pandas/core/dtypes/dtypes.py](https://codecov.io/gh/pandas-dev/pandas/pull/26029/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZHR5cGVzL2R0eXBlcy5weQ==) | `96.12% <100%> (+0.01%)` | :arrow_up: |
| [pandas/io/gbq.py](https://codecov.io/gh/pandas-dev/pandas/pull/26029/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL2dicS5weQ==) | `75% <0%> (-12.5%)` | :arrow_down: |
| [pandas/core/frame.py](https://codecov.io/gh/pandas-dev/pandas/pull/26029/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZnJhbWUucHk=) | `96.79% <0%> (-0.12%)` | :arrow_down: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/26029?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/26029?src=pr&el=footer). Last update [0610a60...845808b](https://codecov.io/gh/pandas-dev/pandas/pull/26029?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/26029?src=pr&el=h1) Report
> Merging [#26029](https://codecov.io/gh/pandas-dev/pandas/pull/26029?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/6d9b702a661891724e6c10dd96eb149404205c67?src=pr&el=desc) will **decrease** coverage by `<.01%`.
> The diff coverage is `100%`.

[![Impacted file tree graph](https://codecov.io/gh/pandas-dev/pandas/pull/26029/graphs/tree.svg?width=650&token=eZ4WkYLtcO&height=150&src=pr)](https://codecov.io/gh/pandas-dev/pandas/pull/26029?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master   #26029      +/-   ##
==========================================
- Coverage    91.9%   91.89%   -0.01%     
==========================================
  Files         175      175              
  Lines       52485    52489       +4     
==========================================
- Hits        48235    48234       -1     
- Misses       4250     4255       +5
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `90.45% <100%> (ø)` | :arrow_up: |
| #single | `40.76% <100%> (-0.13%)` | :arrow_down: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/26029?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/core/dtypes/base.py](https://codecov.io/gh/pandas-dev/pandas/pull/26029/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZHR5cGVzL2Jhc2UucHk=) | `100% <100%> (ø)` | :arrow_up: |
| [pandas/core/dtypes/missing.py](https://codecov.io/gh/pandas-dev/pandas/pull/26029/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZHR5cGVzL21pc3NpbmcucHk=) | `93.33% <100%> (+0.04%)` | :arrow_up: |
| [pandas/core/dtypes/dtypes.py](https://codecov.io/gh/pandas-dev/pandas/pull/26029/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZHR5cGVzL2R0eXBlcy5weQ==) | `96.12% <100%> (+0.01%)` | :arrow_up: |
| [pandas/io/gbq.py](https://codecov.io/gh/pandas-dev/pandas/pull/26029/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL2dicS5weQ==) | `75% <0%> (-12.5%)` | :arrow_down: |
| [pandas/core/frame.py](https://codecov.io/gh/pandas-dev/pandas/pull/26029/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZnJhbWUucHk=) | `96.79% <0%> (-0.12%)` | :arrow_down: |
| [pandas/util/testing.py](https://codecov.io/gh/pandas-dev/pandas/pull/26029/diff?src=pr&el=tree#diff-cGFuZGFzL3V0aWwvdGVzdGluZy5weQ==) | `90.62% <0%> (-0.11%)` | :arrow_down: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/26029?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/26029?src=pr&el=footer). Last update [6d9b702...85ef4b4](https://codecov.io/gh/pandas-dev/pandas/pull/26029?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

lgtm. @WillAyd merge when satisfied