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

Avoid use of inspect.signature on CommandContribution class #146

Merged
merged 2 commits into from
Apr 4, 2022

Conversation

tlambert03
Copy link
Collaborator

@tlambert03 tlambert03 commented Apr 3, 2022

fixes #144

This fixes the breakage of napari used with PySide2 in npe2=0.2.2, just by "avoiding" using inspect.signature ... this is super annoying bug in PySide2, that affects the ability to modify signatures of any python object. See napari/napari#2265 for details

@codecov
Copy link

codecov bot commented Apr 3, 2022

Codecov Report

Merging #146 (8406043) into main (d86c2c4) will not change coverage.
The diff coverage is 100.00%.

@@            Coverage Diff            @@
##              main      #146   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           26        26           
  Lines         1719      1717    -2     
=========================================
- Hits          1719      1717    -2     
Impacted Files Coverage Δ
npe2/_dynamic_plugin.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d86c2c4...8406043. Read the comment docs.

@tlambert03
Copy link
Collaborator Author

pre-commit failure is unrelated... upstream problem

@Carreau
Copy link
Collaborator

Carreau commented Apr 4, 2022

Trying closing and reopening for precommit.

@Carreau Carreau closed this Apr 4, 2022
@Carreau Carreau reopened this Apr 4, 2022
Comment on lines +208 to +212
cmd_kwargs = {
k: kwargs.pop(k)
for k in list(kwargs)
if k in CommandContribution.__fields__
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
cmd_kwargs = {
k: kwargs.pop(k)
for k in list(kwargs)
if k in CommandContribution.__fields__
}
kwargs_set = set(kwargs)
cmd_kwargs = {
k: kwargs.pop(k)
for k in kwargs_set
if k in CommandContribution.__fields__
}

I know that this is only a few positions, but creating a list every time? Some less experienced users may use this as inspiration in places where this condition is not satisfied.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I mean you don't even need the set/list, as 'k in kwargs' will iterate over the dict keys, and if you use the set, then why not kwargs_set = set(kwargs).union(set(CommandContribution.__fields__)) and avoid the test.

Copy link
Collaborator

Choose a reason for hiding this comment

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

not union but intersection

Copy link
Collaborator

@Czaki Czaki Apr 4, 2022

Choose a reason for hiding this comment

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

ahh, maybe to early. I replace in the head if check with iteration. Ignore this change request.

Copy link
Collaborator

@Carreau Carreau Apr 4, 2022

Choose a reason for hiding this comment

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

not union but intersection

Ghhhhaaaa. Pfrrlrlrlflfr. Yes.

Copy link
Collaborator

Choose a reason for hiding this comment

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

... How many programmers do you need to get a dict comprehension right ...
Today is not a functioning brain day.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I mean you don't even need the set/list, as 'k in kwargs' will iterate over the dict keys,

we do in this case, since kwargs is getting changed on each iteration by kwargs.pop...

but creating a list every time?

it's not creating a list on each iteration either way (the list would only get called on the first evaluation of the comprehension)

In [13]: class T:
    ...:     def __iter__(self):
    ...:         print('iter')
    ...:         yield from ['a','b','c']
    ...:

In [14]: kwargs = T()

In [15]: list(kwargs)
iter
Out[15]: ['a', 'b', 'c']

In [16]: {k for k in list(kwargs) if k in ['a','b']}
iter
Out[16]: {'a', 'b'}

In [17]: {k for k in kwargs if k in ['a','b']}
iter
Out[17]: {'a', 'b'}

@Czaki
Copy link
Collaborator

Czaki commented Apr 4, 2022

pre-commit failure is unrelated... upstream problem

see #147

@tlambert03 tlambert03 merged commit b1d7e02 into napari:main Apr 4, 2022
@tlambert03 tlambert03 deleted the fix-pydantic branch April 4, 2022 20:48
@tlambert03 tlambert03 added the bug Something isn't working label Apr 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

npe2==0.2.2 broken with Pyside2
3 participants