-
-
Notifications
You must be signed in to change notification settings - Fork 18
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
Update expectations of subclasses #144
Conversation
Lints are currently failing with |
Just to clarify, I made this so we could have a concrete proposal to discuss and iterate on. |
I “fixed” the mypy issue this morning (with |
So, any comments about the suggested change? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This all looks reasonable to me. I missed the addition of _unpack and will start a conversation elsewhere about that.
I finally took the time to run the benchmarks, and the results seem pretty clear: there's a large performance hit for all methods that return a vector:
Would there be a way to either:
|
Optimizing that sounds non-trivial, and possibly involve native code. The fact that it is significantly slower than the class-searching stuff is disconcerting, though. |
@astronouth7303 That was my point, though: |
Fixing the performance regression is blocked by #146. |
Except that we don't know what fields there will be? That's the whole point of this whole thing? |
@astronouth7303 Yes, but we know that we only ever want to modify |
Weaken the subclassing guarantees: returned vectors now have the type of `self`.
Some methods do not accept arbitrary vectors or scalars. Make sure we only generate inputs in their domain.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd still prefer a .__copy__()
that just returns self
.
@astronouth7303 How is this related to (the current state of) this PR? |
149: Drop subclassing support r=astronouth7303 a=nbraud - [x] Document that subclassing isn't supported. - [x] Drop the subclassing testsuite. - [x] Drop the subclassing support. - [x] Rename `Vector2` to `Vector`. Avoid breaking backwards-compatibility by adding a `Vector2` alias. - [x] Rename `vector2.py` to `vector.py`. Closes #144 (this is an alternative proposal) Co-authored-by: Nicolas Braud-Santoni <nicolas@braud-santoni.eu>
Those are required to be
dataclasses
, to implement__new__
, and not to implement__init__
.update()
Typing guarantees are weakened: returned vectors are now guaranteed to have the type of
self
.__new__
(see Vector2.__new__ violates its interface contract #146).