-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
Traps in extension default behaviour #1587
Comments
Thanks for the detailed report! While I generally like the factory solution, I do think it'd kinda ruin the simplicity of setting the If a user does want to do it differently, they obviously still can – they just have to be careful. It's a pretty common Python gotcha after all. |
No worries @ines. I agree simplicity is probably best in this case and the docs will help clarify it. |
Awesome, thanks @ines. |
Looks like the assertion error happens when we only have one non-None value. Line 99 in 75d2a05
So the example in the docs will not work (though Spans don't have the same restriction). https://spacy.io/usage/processing-pipelines#custom-components-attributes
I have a use case where I'd like to keep a list and a
Would this be possible with getters and setters? |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
I've found a few traps in how extension
default
values behave.Unable to set a default of
None
This would be useful to indicate unintialised values (see below), but currently raises an anonymous-looking
AssertionError
.Mutable default values trap
The
default
argument behaves like a standard python default function parameter. One side-effect is thatDocs
will appear to share extension data if you've inadvertently used something like adict
as a default value.It's not a massive deal, but could be a bit dangerous in this context.
To fix, it might be worth:
default_factory
parameter in defaultdict?)Your Environment
The text was updated successfully, but these errors were encountered: