pytest-dev / pytest-dev/pytest

`MonkeyPatch.setattr`/`delattr` cause descriptor binding even when the `hasattr` check is disabled with `raising=False`

Open
#10,646 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

type: bug
Dominant language
Python
Stars
14.5k
Forks
3.4k
Avg merge
2d 9h
Merged PRs (30d)
35

Description

binding descriptors to see if they raise AttributeErrors is not necessary when the hasattr check is disabled by raising=False, but pytest still does it. i believe most developers would expect that, when the hasattr-equivalent check is disabled, descriptor binding would not be triggered. binding descriptors when the user expects them not to be bound can cause unwanted side effects.

a reproducer is implemented in d5f04b526bfbe7ae630c00bbbc808bd108bd6ae5.

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 with the reproducer in commit d5f04b526bfbe7ae630c00bbbc808bd108bd6ae5 and trace the MonkeyPatch.setattr and delattr entry points. Confirm the behavior with tests covering raising=False; done means descriptor binding is not triggered when the hasattr-equivalent check is disabled.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
testing
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.