Skip to content
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

Various small MultiSignalBlocker cleanups #598

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

The-Compiler
Copy link
Member

A couple of things I noticed while working on #594 (which I'll probably abandon as it seems to bring more trouble than it fixes).

self.signal_name = signal_name
self.args = args
signal_name: str
args: list[Any]
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
args: list[Any]
args: list[object]

In this case, we don't care about the type of the object, for this reason object is safer: it will accept anything (just like Any), but contrary to Any, the type checker will flag if we accidentally try to perform some operation on it (say call a method).

Copy link
Member Author

@The-Compiler The-Compiler Mar 25, 2025

Choose a reason for hiding this comment

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

While we don't, this is exposed to users of the plugin, and we don't know what they want to do with those arguments. If we are going to make those types public in the future (and that's my goal), then users would have to cast those to do anything on it in that case, no?

Copy link
Member

@nicoddemus nicoddemus Mar 25, 2025

Choose a reason for hiding this comment

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

Ahh this is exposed? Then you are right, better to leave it as args: list[Any].

Not suggestion to this now, but I think a way to handle this correctly regarding types would would be to make this class Generic so users could type args according to their needs.

Btw should in this case args be tuple[Any, ...] then? Usually this is how *args is typed.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep, see https://pytest-qt.readthedocs.io/en/latest/signals.html#getting-emitted-signals-and-arguments:

To determine which of the expected signals were emitted during a wait() you can use blocker.all_signals_and_args which contains a list of wait_signal.SignalAndArgs objects, indicating the signals (and their arguments) in the order they were received.

I don't think this can be made generic, as the arguments will depend on the signal being recorded, and we don't know which signals (and how many in total) there will be in there.

Good catch regarding tuple[Any, ...], will adjust accordingly.

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