Skip to content

fix: __repr__ use collection subclass name - #3219

Merged
youknowone merged 1 commit into
RustPython:mainfrom
muscar:fix/repr-use-collection-subclass-name
Oct 6, 2021
Merged

youknowone merged 1 commit into
RustPython:mainfrom
muscar:fix/repr-use-collection-subclass-name

Conversation

@muscar

@muscar muscar commented Oct 4, 2021

Copy link
Copy Markdown
Contributor

Addresses: #3217

This patch changes the set, frozenset, deque and bytearray
collections to use the subclass name in __repr__, if they are
subclassed.

Comment thread vm/src/builtins/set.rs Resolved
@muscar
muscar force-pushed the fix/repr-use-collection-subclass-name branch from a9c1144 to f5dc0b4 Compare October 6, 2021 08:05
@DimitrisJim DimitrisJim linked an issue Oct 6, 2021 that may be closed by this pull request
Addresses: RustPython#3217

This patch changes the `set`, `frozenset`, `deque` and `bytearray`
collections to use the subclass name in `__repr__`, if they are
subclassed.
@muscar
muscar force-pushed the fix/repr-use-collection-subclass-name branch from f5dc0b4 to cd42160 Compare October 6, 2021 09:01
Comment thread vm/src/builtins/set.rs
Comment on lines +207 to +211
let inner_repr = format!("{{{}}}", str_parts.join(", "));
if let Some(name) = class_name {
return Ok(format!("{}({})", name, inner_repr));
};
Ok(inner_repr)

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.

still double formatting when class_name is Some

@youknowone
youknowone merged commit 13ca594 into RustPython:main Oct 6, 2021
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.

Fix collection(s) repr to correctly handle subclasses

2 participants