Introduce PyUnionType#3497
Conversation
|
@moreal I am sorry to keep this unreviewed for long time. Could you please rebase this PR? |
93d40c7 to
2f14245
Compare
| pub(crate) mod unionobject; | ||
| pub use unionobject::PyUnionObject; |
There was a problem hiding this comment.
typically we don't name ~object for RustPython modules and types. pyunion for module name (to avoid keyword union) and PyUnion for the type name would fit to convention.
| PyRef, PyResult, PyValue, TryFromObject, TypeProtocol, VirtualMachine, | ||
| }; | ||
| use std::fmt; | ||
|
|
|
|
||
| use super::genericalias; | ||
|
|
||
| static CLS_ATTRS: [&str; 1] = ["__module__"]; |
There was a problem hiding this comment.
if there is no specific needs for array, slice also works. (and also const, not to access memory)
| static CLS_ATTRS: [&str; 1] = ["__module__"]; | |
| const CLS_ATTRS: &[&str] = &["__module__"]; |
| #[pymethod(magic)] | ||
| fn repr(&self, vm: &VirtualMachine) -> PyResult<String> { | ||
| fn repr_item(obj: PyObjectRef, vm: &VirtualMachine) -> PyResult<String> { | ||
| if obj.is(&vm.ctx.types.none_type) { |
There was a problem hiding this comment.
| if obj.is(&vm.ctx.types.none_type) { | |
| if vm.is_none(&obj) { |
This commits make some tests skip with `unittest.skip`: - `test.test_typing.BaseCallableTests.test_pickle()` - `test.test_typing.BaseCallableTests.test_paramspec()` Because `CollectionsCallableTests` and `TypingCallableTests` inherit tests in `BaseCallableTests` but the tests are failed only in `CollectionsCallableTests`. I tried to use `unittest.expectedFailure` but I couldn't find the way to apply it conditionally.
Hello @youknowone, I have worked for making this pull request pass the check at this time and it finished. |
|
I've faced this many times before, and I have a solution. What you can do is go down to # TODO: RUSTPYTHON, WeirdError: for some reason, this test failed in this class
@unittest.expectedFailure
def test_whatever(self): # TODO: RUSTPYTHON, remove when this passes
super().test_whatever() # TODO: RUSTPYTHON, remove when this passesIf you want the answer for your specific case, it's under the cut: Answer for your specific casediff --git a/Lib/test/test_typing.py b/Lib/test/test_typing.py
index 330aa1a18..ac97fd781 100644
--- a/Lib/test/test_typing.py
+++ b/Lib/test/test_typing.py
@@ -532,8 +532,6 @@ class BaseCallableTests:
alias = Callable[[int, str], float]
self.assertEqual(weakref.ref(alias)(), alias)
- # TODO: RUSTPYTHON
- @unittest.skip("Failed at CollectionsCallableTests")
def test_pickle(self):
Callable = self.Callable
alias = Callable[[int, str], float]
@@ -575,8 +573,6 @@ class BaseCallableTests:
self.assertIs(a().__class__, C1)
self.assertEqual(a().__orig_class__, C1[[int], T])
- # TODO: RUSTPYTHON
- @unittest.skip("Failed at CollectionsCallableTests")
def test_paramspec(self):
Callable = self.Callable
fullname = f"{Callable.__module__}.Callable"
@@ -646,6 +642,15 @@ class TypingCallableTests(BaseCallableTests, BaseTestCase):
class CollectionsCallableTests(BaseCallableTests, BaseTestCase):
Callable = collections.abc.Callable
+ # TODO: RUSTPYTHON
+ @unittest.expectedFailure
+ def test_paramspec(self): # TODO: RUSTPYTHON, remove when this passes
+ super().test_paramspec() # TODO: RUSTPYTHON, remove when this passes
+
+ # TODO: RUSTPYTHON, pickle.PicklingError: Can't pickle <class 'collections.abc._CallableGenericAlias'>: it's not found as collections.abc._CallableGenericAlias
+ @unittest.expectedFailure
+ def test_pickle(self): # TODO: RUSTPYTHON, remove when this passes
+ super().test_pickle() # TODO: RUSTPYTHON, remove when this passes
class LiteralTests(BaseTestCase):
def test_basics(self): |
youknowone
left a comment
There was a problem hiding this comment.
Looks great! I left a few subtle comments.
|
|
||
| #[pyproperty(magic)] | ||
| fn parameters(&self) -> PyObjectRef { | ||
| self.parameters.as_object().to_owned() |
There was a problem hiding this comment.
| self.parameters.as_object().to_owned() | |
| self.parameters.into() |
|
|
||
| #[pyproperty(magic)] | ||
| fn args(&self) -> PyObjectRef { | ||
| self.args.as_object().to_owned() |
There was a problem hiding this comment.
| self.args.as_object().to_owned() | |
| self.args.into() |
There was a problem hiding this comment.
I tried to apply this suggestion but it failed with the below logs 😿 :
error[E0507]: cannot move out of `self.parameters` which is behind a shared reference
--> vm/src/builtins/pyunion.rs:79:9
|
79 | self.parameters.into()
| ^^^^^^^^^^^^^^^ move occurs because `self.parameters` has type `pyobjectrc::PyRef<PyTuple>`, which does not implement the `Copy` trait
error[E0507]: cannot move out of `self.args` which is behind a shared reference
--> vm/src/builtins/pyunion.rs:84:9
|
84 | self.args.into()
| ^^^^^^^^^ move occurs because `self.args` has type `pyobjectrc::PyRef<PyTuple>`, which does not implement the `Copy` trait
There was a problem hiding this comment.
| self.args.as_object().to_owned() | |
| self.args.clone().into() |
Adding a clone will work.
Co-authored-by: Jeong YunWon <69878+youknowone@users.noreply.github.com>
Co-authored-by: Jeong YunWon <69878+youknowone@users.noreply.github.com>
95b06ee to
dc968c2
Compare
ddcc922 to
d2e3bff
Compare
|
Thank you for long time work! |
I also appreciate your help and passion! 🙇🏻♂️ |
This pull request is related with #3419, #3475.
This pull request does:
PyUnionType(a.k.a.types.UnionType,unionobjectin CPython)_py_abc3.10.0abc3.10.0types3.10.0typing3.10.0_collections_abc3.10.2