FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Add type hint for decorated function by jackblk · Pull Request #533 · allure-framework/allure-python · GitHub

Add type hint for decorated function - #533

Merged
sseliverstov merged 2 commits into
allure-framework:masterfrom
jackblk:master
Dec 7, 2020
Merged

Add type hint for decorated function#533
sseliverstov merged 2 commits into
allure-framework:masterfrom
jackblk:master

Conversation

jackblk commented Dec 7, 2020
edited
Loading

Copy link
Copy Markdown
Contributor

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:

Argument hint:


After this PR:

Argument hint:

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 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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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


Back | FazBrowse Home | New Git URL