Sitelet https://web.archive.org/web/20260617113102/https://github.com/RustPython/RustPython/pull/3600
Skip to content

modify empty tuple (genericalias repr)#3600

Merged
youknowone merged 4 commits into
RustPython:mainfrom
hwi-ya:llliiisssttt
Apr 10, 2022
Merged

modify empty tuple (genericalias repr)#3600
youknowone merged 4 commits into
RustPython:mainfrom
hwi-ya:llliiisssttt

Conversation

@hwi-ya

@hwi-ya hwi-ya commented Apr 10, 2022

Copy link
Copy Markdown
Contributor

Modify list[] to print list[()] when executing list[()]

@hwi-ya hwi-ya changed the title Llliiisssttt modify empty tuple (genericalias repr) Apr 10, 2022
Comment thread Lib/test/test_genericalias.py Outdated
pass
self.assertEqual(repr(list[str]), 'list[str]')
self.assertEqual(repr(list[()]), 'list[()]')
self.assertEqual(repr(list[()]), 'list[()]')

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whitespace is added.

Suggested change
self.assertEqual(repr(list[()]), 'list[()]')
self.assertEqual(repr(list[()]), 'list[()]')

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@youknowone i fixed it

Comment thread vm/src/builtins/genericalias.rs Outdated
Comment on lines +102 to +120
if self.args.len() == 0 {
Ok(format!(
"{}[{}]",
repr_item(self.origin.as_object().to_owned(), vm)?,
"()"
))
}
else {
Ok(format!(
"{}[{}]",
repr_item(self.origin.as_object().to_owned(), vm)?,
self.args
.as_slice()
.iter()
.map(|o| repr_item(o.clone(), vm))
.collect::<PyResult<Vec<_>>>()?
.join(", ")
))
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It shares the first argument but duplicating the whole formatting code.

Comment thread vm/src/builtins/genericalias.rs Outdated

@youknowone youknowone left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good, thank you!

@youknowone youknowone merged commit cf6a83e into RustPython:main Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants