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

Fix is_simple_callable with variable args, kwargs #4622

Merged
merged 2 commits into from Oct 25, 2016

Conversation

rpkilby
Copy link
Member

@rpkilby rpkilby commented Oct 24, 2016

Fix #4602

py3k is_simple_callable was not accounting for variable args and kwargs

@tomchristie tomchristie added this to the 3.5.2 Release milestone Oct 24, 2016
@tomchristie
Copy link
Member

tomchristie commented Oct 24, 2016

Thanks for working towards this! Milestoned this as 3.5.2 to keep it on our immediate horizon. Some tests failing in its current state.

@rpkilby
Copy link
Member Author

rpkilby commented Oct 24, 2016

yep - see my comment on #4602. I'll have to think more on how to proceed with the fix.

@rpkilby
Copy link
Member Author

rpkilby commented Oct 25, 2016

This should be good to go now. There were two separate issues:

  • The callable check was incorrect - needed to be the more restrictive isfunction or ismethod.
  • The parameter check needed to allow for *args and **kwargs. This is necessary to validate get_FIELD_display() as it's a curried function where it's only inspectable parameters are *args and **kwargs.

@tomchristie
Copy link
Member

tomchristie commented Oct 25, 2016

Great work!

😄 👍

@tomchristie tomchristie merged commit eafc9a2 into encode:master Oct 25, 2016
3 checks passed
@rpkilby rpkilby deleted the fix-simple-callable branch Oct 26, 2016
param.kind == param.VAR_KEYWORD or
param.default != param.empty
for param in params
)
Copy link
Collaborator

@carltongibson carltongibson Oct 26, 2016

Choose a reason for hiding this comment

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

@rpkilby: Can you just explain this call to me, just for my sanity? 🙂

I'm expecting any(iterable) — it looks like bool or bool or generator, so why isn't it this:

>>> a = True
>>> b = True
>>> def c():
...     yield True
...     yield False
>>> all(a or b or c())
TypeError: 'bool' object is not iterable

Sorry for being slow. Thanks!

Copy link
Collaborator

@carltongibson carltongibson Oct 26, 2016

Choose a reason for hiding this comment

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

OK. 1 second after Comment it becomes clear. ... — even seeing it though, I still struggle to read it right...

Copy link
Member Author

@rpkilby rpkilby Oct 26, 2016

Choose a reason for hiding this comment

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

@carltongibson - it probably wouldn't have hurt to have added a second set of parens wrapping the conditions

return all((
        param.kind == param.VAR_POSITIONAL or
        param.kind == param.VAR_KEYWORD or
        param.default != param.empty
    ) for param in params
)

Copy link
Collaborator

@carltongibson carltongibson Oct 26, 2016

Choose a reason for hiding this comment

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

Yeah, that's kind to of where I came to. (That vs a nested any)

It's fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants