Skip to content

Add type hint for decorated function #533

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

Merged
merged 2 commits into from
Dec 7, 2020
Merged

Add type hint for decorated function #533

merged 2 commits into from
Dec 7, 2020

Conversation

jackblk
Copy link
Contributor

@jackblk jackblk commented Dec 7, 2020

Currently some language servers cannot parse the type of wrapped functions. _TFunc is bounded to the function.

Context

Decorated function will lose type hint in some Python language servers (e.g Pylance which VSCode will use officially in the future). Language server is working as intended, and if our wrapper does not change arg types, we should add type hint.

See: microsoft/pyright#774 (comment)

Example code:

    @allure.step("Get field '{field}' edit status.")
    def get_field_edit_status(self, field: str) -> str:
        """Get edit status of the field

        Args:
            field (str): name of the field, case insensitive

        Returns:
            str: edit status: "read only", "yes", "no".
        """
        field = field.lower()
        row_elem: WebElement = self.fields[field]
        status: str = row_elem.find_element_by_xpath(XPATH).text
        return status.lower()

VSCode with Pylance:
image

Argument hint:
image


After this PR:
image

Argument hint:
image

Checklist

No new unit test since no function change. Unit test result is the same to before this PR.

Currently some language servers cannot parse the type of wrapped functions. _TFunc is bounded to the function.
add one more space to pass static check
@sseliverstov sseliverstov merged commit 5923e5c into allure-framework:master Dec 7, 2020
beckerGil pushed a commit to beckerGil/allure-python that referenced this pull request Apr 10, 2023
IvanBuruyane pushed a commit to IvanBuruyane/allure-python that referenced this pull request Mar 19, 2024
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