X Tutup
The Wayback Machine - https://web.archive.org/web/20260126030950/https://github.com/RustPython/RustPython/pull/4125
Skip to content

Conversation

@coolreader18
Copy link
Member

  • Rework frozenset construction
  • Rework marshal.rs to use an error enum

use num_traits::Zero;
use std::str;

#[derive(num_enum::TryFromPrimitive)]
Copy link
Member

Choose a reason for hiding this comment

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

👍

inner: PySetInner,
}

impl PyFrozenSetBuilder<'_> {
Copy link
Member

Choose a reason for hiding this comment

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

This type looks like to be able to be used for both frozenset and set.
Then instead of build and build_with_type, PyFrozenSet::from_builder PyFrozenSet::from_builder_with_type, and From<PyFrozenSetBuilder> for PySet will cover any possible use case

Comment on lines +299 to +300
let sign = if len < 0 { Sign::Minus } else { Sign::Plus };
let len = len.unsigned_abs() as usize;
Copy link
Member

Choose a reason for hiding this comment

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

Not a big deal but this is changed from single comparison to double comparison (symentically)

Suggested change
let sign = if len < 0 { Sign::Minus } else { Sign::Plus };
let len = len.unsigned_abs() as usize;
let (sign, len) = if len < 0 {
(Sign::Minus, (-len) as usize)
} else {
(Sign::Plus, len as usize)
};

Copy link
Contributor

Choose a reason for hiding this comment

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

I actually prefer what @coolreader18 wrote here because its intention is clearer. However, I do have one improvement for the first line:

Suggested change
let sign = if len < 0 { Sign::Minus } else { Sign::Plus };
let len = len.unsigned_abs() as usize;
let sign = if len.is_negative() { Sign::Minus } else { Sign::Plus };
let len = len.unsigned_abs() as usize;

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.

3 participants

X Tutup