Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add auto_attribs #277

Merged
merged 17 commits into from
Nov 8, 2017
18 changes: 8 additions & 10 deletions src/attr/_make.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,16 +191,14 @@ class MyClassAttributes(tuple):
])


try:
from typing import ClassVar

# You cannot use ClassVar together with isinstance.
_CLASS_VAR_CLS = ClassVar.__class__
except ImportError:
class FakeClassVar(object):
pass
def _is_class_var(annot):
"""
Check whether *annot* is a typing.ClassVar.

_CLASS_VAR_CLS = FakeClassVar
The implementation is gross but importing `typing` is slow and there are
discussions to remove it from the stdlib alltogether.
"""
return str(annot).startswith("typing.ClassVar")

This comment was marked as spam.



def _transform_attrs(cls, these, auto_attribs):
Expand Down Expand Up @@ -231,7 +229,7 @@ def _transform_attrs(cls, these, auto_attribs):
ca_list = []
annot_names = set()
for attr_name, type in anns.items():
if isinstance(type, _CLASS_VAR_CLS):
if _is_class_var(type):
continue
annot_names.add(attr_name)
a = cd.get(attr_name, NOTHING)
Expand Down