Skip to content

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