Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Miscellaneous cli-related parity fixes #5442

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 4, 2024

Conversation

coolreader18
Copy link
Member

@coolreader18 coolreader18 commented Nov 13, 2024

Part of this is taken from #5414.

@coolreader18 coolreader18 force-pushed the cli-fixes branch 3 times, most recently from decf6a8 to cccbd2e Compare November 14, 2024 23:25
RunMode::Command(command) => {
debug!("Running command {}", command);
vm.run_code_string(scope, &command, "<stdin>".to_owned())?;
vm.run_code_string(scope.clone(), &command, "<stdin>".to_owned())
.map(drop)
Copy link
Member

Choose a reason for hiding this comment

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

Is this a common convention to drop value from Result? It looks like drop is important logic here to me. If not, a weak suggestion.

Suggested change
.map(drop)
.map(|_| ())

Copy link
Member Author

Choose a reason for hiding this comment

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

I've seen .map(drop) a decent amount, yeah.

Comment on lines +349 to +354
env::var_os(name).filter(|v| !v.is_empty()).map(|value| {
value
.to_str()
.and_then(|v| v.parse::<u8>().ok())
.unwrap_or(1)
})
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
env::var_os(name).filter(|v| !v.is_empty()).map(|value| {
value
.to_str()
.and_then(|v| v.parse::<u8>().ok())
.unwrap_or(1)
})
let value_str = env::var_os(name).filter(|v| !v.is_empty())?;
let value = value_str
.to_str()
.and_then(|v| v.parse::<u8>().ok())
.unwrap_or(1);
Some(value)

Copy link
Member Author

Choose a reason for hiding this comment

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

Given there's 2 layers of Option here, I think I'd like to keep the logic as it is - looking at the suggested version my instinct was to change it to .to_str()?.parse().unwrap_or(1), but that's different. I think the explicit map() makes more clear the control flow and conditions.

Copy link
Member

Choose a reason for hiding this comment

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

line 349 and the following lines are unrelated logics. early return reveals line 350 is independent to 349 and code readers can forget about 349 when going to 350.
Using map make readers essentially follow the full logic without benefit.

@coolreader18 coolreader18 merged commit 848db34 into RustPython:main Dec 4, 2024
11 checks passed
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
Morty Proxy This is a proxified and sanitized view of the page, visit original site.