PyO3 / PyO3/pyo3

PySet::empty could be infallible

Open
#6,074 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
16.2k
Forks
1k
Avg merge
2d 6h
Merged PRs (30d)
66

Description

Currently PySet::empty() returns PyResult<Bound<'_, PySet>>, though AFAIK, this operation can't fail. Or at least it can't fail any more likely than PyDict::new(py) which does not return PyResult. I was initially confused since I was populating an empty set and dict to the same struct.

On the flip side, I understand that PySet::empty is being consistent with PySet::new, which needs to return error for unhashable items. So there is a consistency argument to be made, but in general I guess infallible methods should not return PyResult?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the implementation and call sites for PySet::empty(), then compare its signature with PyDict::new(py) and PySet::new. Resolve whether the API should make this operation infallible; done means the chosen behavior is covered by the relevant tests and all affected uses compile.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, rust
Domain
backend-api-design
Issue type
Refactor
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.