Repository: pandas-dev/pandas

Issue:
Fix Type Annotations in pandas.core.generic
Part of #25882

Current errors are as follows:

```sh
pandas/core/generic.py:116: error: Need type annotation for '_accessors'
pandas/core/generic.py:119: error: Need type annotation for '_metadata'
```

Both of these are containers which should contain strings, so just need proper annotation and this module can be removed from mypy.ini


Discussion:
Also makes sense to clean up a similar error in the frame module:

```sh
pandas/core/frame.py:368: error: Need type annotation for '_accessors'
```
I think we need to add a comment like this: `# type: List[str]` or

    from typing import Container
    _metadata: Container[str] = []

right? I can do that. But I have never contributed to open source before so if you can help me a bit if I get stuck somewhere it will be nice.
Hi, I tried `_metadata: Container[str] = []` but now pep8 gives me error that:

> pandas/core/generic.py:120:14: E701 multiple statements on one line (colon)

Should I use the the comment syntax `# type: Container[str]` or can we ignore this error?
Yea for local variables need comment syntax as we still support Py35 and that didn’t come until Py36. 

Should use List here 

Sent from my iPhone

> On Mar 28, 2019, at 4:37 AM, Vaibhav Vishal <notifications@github.com> wrote:
> 
> Hi, I tried _metadata: Container[str] = [] but now pep8 gives me error that:
> 
> pandas/core/generic.py:120:14: E701 multiple statements on one line (colon)
> 
> Should I use the the comment syntax # type: Container[str] or can we ignore this error?
> 
> —
> You are receiving this because you authored the thread.
> Reply to this email directly, view it on GitHub, or mute the thread.

Thanks, I will fix this and open a pull request. There are some other open issues related to Type Annotation, should I fix them too in the same PR, or you want different PR for each one?

Also looking at the code `_metadata` looks like a list to me, should I use `List[str]` or `Container[str]`
Use List and one PR per issue for now

Sent from my iPhone

> On Mar 28, 2019, at 5:39 AM, Vaibhav Vishal <notifications@github.com> wrote:
> 
> Thanks, I will fix this and open a pull request. There are some other open issues related to Type Annotation, should I fix them too in the same PR, or you want different PR for each one?
> 
> Also looking at the code _metadata looks like a list to me, should I use List[str] or Container[str]
> 
> —
> You are receiving this because you authored the thread.
> Reply to this email directly, view it on GitHub, or mute the thread.

ok. You said list in your last comment, sorry I missed that, my bad. I was looking at your very first comment which said both are containers.

Resolving patch:
diff --git a/pandas/core/frame.py b/pandas/core/frame.py
--- a/pandas/core/frame.py
+++ b/pandas/core/frame.py
@@ -16,7 +16,7 @@
 import sys
 import warnings
 from textwrap import dedent
-from typing import List, Optional, Union
+from typing import FrozenSet, List, Optional, Set, Type, Union
 
 import numpy as np
 import numpy.ma as ma
@@ -360,10 +360,11 @@ class DataFrame(NDFrame):
     def _constructor(self):
         return DataFrame
 
-    _constructor_sliced = Series
-    _deprecations = NDFrame._deprecations | frozenset(
-        ['get_value', 'set_value', 'from_csv', 'from_items'])
-    _accessors = set()
+    _constructor_sliced = Series  # type: Type[Series]
+    _deprecations = NDFrame._deprecations | frozenset([
+        'get_value', 'set_value', 'from_csv', 'from_items'
+    ])  # type: FrozenSet[str]
+    _accessors = set()  # type: Set[str]
 
     @property
     def _constructor_expanddim(self):
diff --git a/pandas/core/generic.py b/pandas/core/generic.py
--- a/pandas/core/generic.py
+++ b/pandas/core/generic.py
@@ -6,6 +6,7 @@
 import operator
 import pickle
 from textwrap import dedent
+from typing import FrozenSet, List, Set
 import warnings
 import weakref
 
@@ -108,12 +109,13 @@ class NDFrame(PandasObject, SelectionMixin):
     _internal_names = ['_data', '_cacher', '_item_cache', '_cache', '_is_copy',
                        '_subtyp', '_name', '_index', '_default_kind',
                        '_default_fill_value', '_metadata', '__array_struct__',
-                       '__array_interface__']
-    _internal_names_set = set(_internal_names)
-    _accessors = frozenset()
-    _deprecations = frozenset(['as_blocks', 'blocks',
-                               'convert_objects', 'is_copy'])
-    _metadata = []
+                       '__array_interface__']  # type: List[str]
+    _internal_names_set = set(_internal_names)  # type: Set[str]
+    _accessors = set()  # type: Set[str]
+    _deprecations = frozenset([
+        'as_blocks', 'blocks', 'convert_objects', 'is_copy'
+    ])  # type: FrozenSet[str]
+    _metadata = []  # type: List[str]
     _is_copy = None
 
     # ----------------------------------------------------------------------


Test patch: