-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: allow overriding of protocol methods in subclasses (#128)
* Add _handler_of func. MRO classes logic * Add _handler_of func. test * Invert _handler_of func. logic * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Tune _get_handler_index func. with Jim comment * Replace `-1`/`break` logic with an early return. Co-authored-by: Henry Schreiner <[email protected]> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Jim Pivarski <[email protected]> Co-authored-by: Henry Schreiner <[email protected]>
- Loading branch information
1 parent
5ba1115
commit f02e2f0
Showing
2 changed files
with
34 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Copyright (c) 2019-2021, Jonas Eschle, Jim Pivarski, Eduardo Rodrigues, and Henry Schreiner. | ||
# | ||
# Distributed under the 3-clause BSD license, see accompanying file LICENSE | ||
# or https://github.com/scikit-hep/vector for details. | ||
|
||
import vector | ||
|
||
|
||
class CustomVector(vector.VectorObject4D): | ||
pass | ||
|
||
|
||
def test_handler_of(): | ||
object_a = CustomVector.from_xyzt(0.0, 0.0, 0.0, 0.0) | ||
object_b = CustomVector.from_xyzt(1.0, 1.0, 1.0, 1.0) | ||
protocol = vector._methods._handler_of(object_a, object_b) | ||
assert protocol == object_a |