Skip to content

Commit cc5f88f

Browse files
committed
Fix repr for union
1 parent 835771b commit cc5f88f

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

Lib/test/test_types.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -929,8 +929,6 @@ def test_or_type_operator_with_SpecialForm(self):
929929
assert typing.Optional[int] | str == typing.Union[int, str, None]
930930
assert typing.Union[int, bool] | str == typing.Union[int, bool, str]
931931

932-
# TODO: RUSTPYTHON
933-
@unittest.expectedFailure
934932
def test_or_type_repr(self):
935933
assert repr(int | str) == "int | str"
936934
assert repr((int | str) | list) == "int | str | list"

vm/src/builtins/union.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,9 @@ impl PyUnion {
6464
.and_then(|o| o.downcast_ref::<PyStr>().map(|m| m.as_str().to_string())),
6565
) {
6666
(None, _) | (_, None) => Ok(obj.repr(vm)?.as_str().to_string()),
67-
(Some(qualname), Some(module)) => Ok(if module == "builtins" {
67+
(Some(qualname), Some(module)) => Ok(if qualname.eq("NoneType") {
68+
"None".to_string()
69+
} else if module == "builtins" {
6870
qualname
6971
} else {
7072
format!("{}.{}", module, qualname)

0 commit comments

Comments
 (0)