Conversation
|
Hmm, I should probably add a test to confirm that no extra fields are added. Kind of a given I think, but seeing as the workaround involved creating one and I don't think we want that, it seems worth a couple lines of test code I show and verify that desire. I should also probably change my added tests to use hypothesis... :| |
|
Hmmm, IIUC, you’re only setting It’s even questionable whether it should be an option at all, but if it is, it might even be renamed to |
|
I'd be fine with switching on the |
|
@hynek, yes, the intent was to only add TypeError: __weakref__ slot disallowed: either we already got one, or __itemsize__ != 0Same thing happens with an attribute named |
|
If the option is kept and renamed, perhaps Would we want an exception in case of |
hynek
left a comment
There was a problem hiding this comment.
- I think to me it’s more important that we do what’s right/expected so I’m gonna say: make it an option but make it True by default. People like Tin who care about 8 bytes can always set it to False.
- Yes, it should be renamed.
weakref_slotsounds fine. - Yes, exception would be good.
changelog.d/420.change.rst
Outdated
| @@ -0,0 +1 @@ | |||
| Add weakref parameter to attr.s() allowing for weak referenceable slots classes. No newline at end of file | |||
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
src/attr/_make.py
Outdated
| ``object.__setattr__(self, "attribute_name", value)``. | ||
|
|
||
| .. _slots: https://docs.python.org/3/reference/datamodel.html#slots | ||
| :param bool weakref: Make instancess weak-referenceable. This has no |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
|
Once we switch to I'm coding towards |
|
Changing the default broke some tests so I stashed that and went ahead and added parametrization to them for |
|
It does make sense to me that |
|
FWIF, I can live with not having an exception. I’d like to point out tho, that it’s specifically
Otherwise I think everything we settled before is still true? True by default so Tin can save his precious bytes, …? |
|
I couldn't reason to a sensible exception with the name and default Anyways, I'm not waiting on anyone but myself to get back to this and figure out the failures. |
|
Nah it’s fine, as I said, you can drop the exception. Default True, the docs explain that it’s a NOP on dict classes. |
|
Do we have outstanding actions on this at this point? Should any of the tests I added use Hypothesis? Or others that haven't been added but should be? |
hynek
left a comment
There was a problem hiding this comment.
I think it’s mostly fine now, it just needs a bunch of updates where is still refers to weakref instead of weakref_slot.
Also please add an example to tests/typing_example.py to ensure the stubs work (we’ve almost missed the wrong name!).
changelog.d/420.change.rst
Outdated
| @@ -0,0 +1 @@ | |||
| Add weakref parameter to attr.s() allowing for weak referenceable slotted classes. No newline at end of file | |||
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
docs/glossary.rst
Outdated
|
|
||
| - As always with slotted classes, you must specify a ``__weakref__`` slot if you wish for the class to be weak-referenceable. | ||
| Here's how it looks using ``attrs``: | ||
| - Slotted classes are weak-referenceable by default. This can be disabled in CPython by passing ``weakref_slot=False`` to ``@attr.s`` [#pypyweakref]_. |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
src/attr/__init__.pyi
Outdated
| init: bool = ..., | ||
| slots: bool = ..., | ||
| frozen: bool = ..., | ||
| weakref: bool = ..., |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
src/attr/__init__.pyi
Outdated
| init: bool = ..., | ||
| slots: bool = ..., | ||
| frozen: bool = ..., | ||
| weakref: bool = ..., |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
src/attr/__init__.pyi
Outdated
| init: bool = ..., | ||
| slots: bool = ..., | ||
| frozen: bool = ..., | ||
| weakref: bool = ..., |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
src/attr/_make.py
Outdated
| ``object.__setattr__(self, "attribute_name", value)``. | ||
|
|
||
| .. _slots: https://docs.python.org/3/reference/datamodel.html#slots | ||
| :param bool weakref: Make instances weak-referenceable. This has no |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
tests/strategies.py
Outdated
| If `slots=True` is passed in, only slots classes will be generated, and | ||
| if `slots=False` is passed in, no slot classes will be generated. The same | ||
| applies to `frozen`. | ||
| By default, all combinations of slots, frozen, and weakref classes will be |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
tests/strategies.py
Outdated
| By default, all combinations of slots, frozen, and weakref classes will be | ||
| generated. If `slots=True` is passed in, only slots classes will be | ||
| generated, and if `slots=False` is passed in, no slot classes will be | ||
| generated. The same applies to `frozen` and `weakref`. |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
|
@hynek, sorry... i thought i had done all that a few days ago. |
|
Thanks! |
#325