Skip to content

Fix when using typing check, keyword is not found - #2625

Closed
kbfu wants to merge 4 commits into
robotframework:masterfrom
kbfu:master
Closed

kbfu wants to merge 4 commits into
robotframework:masterfrom
kbfu:master

Conversation

@kbfu

@kbfu kbfu commented Jun 26, 2017 •

Copy link
Copy Markdown
Contributor

For Python 3, when I use typing check, Robot Framework always shows me "no keyword with name" error. I found it should be the deprecated method "inspect.getargspec" used in argumentparser.py.

So I put some new code with "inspect.getfullargspec", everything works fine for me now.

This change should be compatible between Python 2 and 3.
Typing hint refer: https://docs.python.org/3.6/library/typing.html
Inspect refer: https://docs.python.org/3.6/library/inspect.html#inspect.getfullargspec

@pekkaklarck pekkaklarck left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks mostly good for me. Few general comments:

  • Although this is somewhat related to #2555, it would be good to submit a separate issue about the typing problem.

  • Acceptance tests are needed. Please take a a look at atest/README.rst for details and let me know if you need help.

args, varargs, kwargs, defaults = inspect.getargspec(handler)
if sys.version_info[0] == 2:
args, varargs, kwargs, defaults = inspect.getargspec(handler)
varkw = kwargs

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Use either varkw or kwargs, not both.


def _get_arg_spec(self, handler):
args, varargs, kwargs, defaults = inspect.getargspec(handler)
if sys.version_info[0] == 2:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could also add from robot.utils import PY2 and use PY2 here.

@kbfu

kbfu commented Jun 28, 2017 •

Copy link
Copy Markdown
Contributor Author

@pekkaklarck Thanks for the comments, my bad, I should not use two different variable names for kwargs.

And I have run the atest, seems ok for me. I ran the test on OS X 10.12.5 with Python 2.7.13 installed.
Here is test results:
Python-2.7-OSX.zip
Issue submitted here #2627

@pekkaklarck

Copy link
Copy Markdown
Member

This fix would need new tests too. Could probably add them/it into some existing suite.

@kbfu

kbfu commented Jun 28, 2017

Copy link
Copy Markdown
Contributor Author

The acceptance test is currently running under Python 2, since the typing hint is newly added in 3.5, I don't think it will work in the acceptance test scripts if I add some new tests.

@pekkaklarck

Copy link
Copy Markdown
Member

This work was continued by @Kompakti in PR #2751 that's been merged.

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