Skip to content

Conversation

@Alir3z4
Copy link

@Alir3z4 Alir3z4 commented Sep 22, 2016

Fixes #4506

args, _, _, defaults = inspect.getargspec(obj)
else:
args, _, _, defaults = inspect.getfullargspec(obj)[:4]

Copy link
Contributor

Choose a reason for hiding this comment

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

Great stuff. Let's move this into a getargspec() function in compat.py, then we'll be good to go.

Copy link
Contributor

Choose a reason for hiding this comment

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

What would the work overhead to use Signature instead of getfullargspec ?
I'm asking because getfullargspec is deprecated from 3.5 so since we're working on that part, might be good to jump directly to the Signature.

Copy link
Contributor

Choose a reason for hiding this comment

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

Note that I don't want to bother if it's too much work.

Copy link
Author

Choose a reason for hiding this comment

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

@tomchristie Yeah, moving to compat makes more sense. Wasn't familiar with the code much. Will do that now.

@xordoquy that makes more sense, yeah. I agree Signature would be better, I just implemented it with the method with inspect.Signature and I'm going to push it.

Copy link
Contributor

Choose a reason for hiding this comment

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

See here in #4505.

Copy link
Contributor

Choose a reason for hiding this comment

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

@tomchristie - I don't think a compat.getargspec makes sense here, as signature and getargspec behave differently and aren't directly interchangeable. Primarily, signature will not return self for bound methods where as getargspec will. I'll push a test case to demonstrate.

Copy link
Author

@Alir3z4 Alir3z4 Sep 22, 2016

Choose a reason for hiding this comment

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

@rpkilby compat.getargspec only returns the method parameters and defaults and that's all fields.is_simple_callable cares about and nothing else.

If other parts of the application requires something more than that from compat.getargspec then modifications can be applied, otherwise the whole backward compatibility should be taken care of in fields.is_simple_callable itself, which that was what I did in the first place and @tomchristie suggested the change, In my opinion it keeps the code clean and straight.

@lovelydinosaur lovelydinosaur added this to the 3.4.8 Release milestone Sep 22, 2016
@Alir3z4
Copy link
Author

Alir3z4 commented Sep 22, 2016

Just pushed the new changes.
Please review again.



def getargspec(obj): # type: tuple
if not hasattr(inspect, 'signature'):
Copy link
Contributor

Choose a reason for hiding this comment

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

An inline comment referring to which python versions each branch applies to would make sense.

Copy link
Contributor

Choose a reason for hiding this comment

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

Also the # type: tuple seems redundant - if we're going to describe the return type could we instead either do so more fully or not at all.

Copy link
Author

Choose a reason for hiding this comment

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

Return type here has been mentioned as an backward compatible for python mypy for python 2.
I'll remove remove it now an until there's a decision made for such thing.

Copy link
Author

Choose a reason for hiding this comment

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

@tomchristie I've applied the changes you've suggested.

@Alir3z4
Copy link
Author

Alir3z4 commented Sep 22, 2016

Lemme know if you have more suggestions on this so I can apply.
I use python 3 type annotation on my project a lot and having this takes the headache out.

@lovelydinosaur
Copy link
Contributor

Looks good. Will make a final review in due course.

@lovelydinosaur
Copy link
Contributor

Closed via #4510. Incoming in 3.5

@lovelydinosaur lovelydinosaur removed this from the 3.4.8 Release milestone Sep 29, 2016
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.

4 participants