This repository has been archived by the owner on Dec 16, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
make Instance, Batch, and all field classes "slots" classes (#4313)
* make field classes slots classes * update CHANGELOG * make Instance a slot class as well * make Batch a slots class * add test and fix more Matt's edge case * add comment * handle case where sub field is not a slots class * fix comment * safely get slots * clean up * make more robust
- Loading branch information
Showing
18 changed files
with
125 additions
and
2 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
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
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
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
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
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
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
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
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,66 @@ | ||
from allennlp.data.fields import Field | ||
|
||
|
||
def test_eq_with_inheritance(): | ||
class SubField(Field): | ||
|
||
__slots__ = ["a"] | ||
|
||
def __init__(self, a): | ||
self.a = a | ||
|
||
class SubSubField(SubField): | ||
|
||
__slots__ = ["b"] | ||
|
||
def __init__(self, a, b): | ||
super().__init__(a) | ||
self.b = b | ||
|
||
class SubSubSubField(SubSubField): | ||
|
||
__slots__ = ["c"] | ||
|
||
def __init__(self, a, b, c): | ||
super().__init__(a, b) | ||
self.c = c | ||
|
||
assert SubField(1) == SubField(1) | ||
assert SubField(1) != SubField(2) | ||
|
||
assert SubSubField(1, 2) == SubSubField(1, 2) | ||
assert SubSubField(1, 2) != SubSubField(1, 1) | ||
assert SubSubField(1, 2) != SubSubField(2, 2) | ||
|
||
assert SubSubSubField(1, 2, 3) == SubSubSubField(1, 2, 3) | ||
assert SubSubSubField(1, 2, 3) != SubSubSubField(0, 2, 3) | ||
|
||
|
||
def test_eq_with_inheritance_for_non_slots_field(): | ||
class SubField(Field): | ||
def __init__(self, a): | ||
self.a = a | ||
|
||
assert SubField(1) == SubField(1) | ||
assert SubField(1) != SubField(2) | ||
|
||
|
||
def test_eq_with_inheritance_for_mixed_field(): | ||
class SubField(Field): | ||
|
||
__slots__ = ["a"] | ||
|
||
def __init__(self, a): | ||
self.a = a | ||
|
||
class SubSubField(SubField): | ||
def __init__(self, a, b): | ||
super().__init__(a) | ||
self.b = b | ||
|
||
assert SubField(1) == SubField(1) | ||
assert SubField(1) != SubField(2) | ||
|
||
assert SubSubField(1, 2) == SubSubField(1, 2) | ||
assert SubSubField(1, 2) != SubSubField(1, 1) | ||
assert SubSubField(1, 2) != SubSubField(2, 2) |