-
-
Notifications
You must be signed in to change notification settings - Fork 374
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
Generic slots classes don't work #313
Comments
This is something about meta classes, isn’t it? 😐 |
I ran into this also (on 18.1), and discovered that oddly enough defining simplified example: @attr.s(these={'foo': attr.ib()})
class Foo(Generic[T]):
__slots__ = ['foo'] I have tested that slots work correctly in this case. I don't really know what that means, but maybe that's useful for narrowing it down? |
Confirming the bug in 18.2.0. |
This does work with python 3.7, at least with |
…cess.run) (#10) * added CompletedProcess class * freeze * updated execute to run * added import * removed slots=True as Python 3.6 workaround: python-attrs/attrs#313
I used the workaround from @dcbaker, but you can use from typing import Generic, TypeVar
import attr
T = TypeVar('T')
@attr.s(these={'foo': attr.ib()}, slots=True)
class Foo(Generic[T]):
pass
f = Foo(1)
assert not hasattr(f, '__dict__')
assert f.__slots__ == ('foo',) # attrs 18.1
assert f.__slots__ == ('foo', '__weakref__') # attrs 20.1 Edit: This only works on 3.7+ apparently |
To save future readers from confusion: the workaround in commit matrix-org/synapse@d15d241 above does not work and was discarded after it was found not to work. (People on our team keep coming across this issue and thinking 'oh look, (other team member) already found a workaround!' only to be confused when it doesn't do the trick..) |
As this bug occurs only in Python <= 3.6, and the next version will drop Python 3.6 support, maybe this issue should be closed? |
yeah looks like this is not an issue on 3.7+ anymore – thanks! |
Attempting to create a generic attrs class with
slots=True
fails if it does not inherit from some other generic class.The full failure stack trace (if we remove the
assertRaises
is:I am using attrs 17.3.0
The text was updated successfully, but these errors were encountered: