I enhanced a class by adding some few methods from another class (Jira’s class from atlassian-python package)
My class is called JiraExtended
.
Original methods from the class display this way:
The ones I created show this way with lesser info on function parameters for exemple:
The way I define docstrings is pretty much the same.
def grant_user_permission(self, username : str = None, permissionschemeid : str|int = None, permission : str = "BROWSE_PROJECTS") -> None:
"""
Grants a permission to a user (username) on a specified Permission Scheme.
:username: the user's username to grant the permission to, current username if not specified.
:permissionschemeid: The id of the permission scheme.
:permission: The permission key to grant, "BROWSE_PROJECTS" if not specified.
"""
if not permissionschemeid:
raise Exception("Provide a username and permissionschemeid")
if not username:
username : str = self.myself()['name']
url = self.resource_url(resource = f"permissionscheme/{permissionschemeid}/permission")
self.post(url, data=json.dumps({"holder": {"type": "user", "parameter": username}, "permission": permission}))
What’s the secret so that Pylance guides me correctly?
1
Ensure that your type annotations are clear and consistent and all necessary imports for type annotations are correctly included.
def grant_user_permission(self, username: str = None, permissionschemeid: str | int = None, permission: str = "BROWSE_PROJECTS") -> None:
"""
Grants a permission to a user (username) on a specified Permission Scheme.
:param username: the user's username to grant the permission to, current username if not specified.
:type username: str, optional
:param permissionschemeid: The id of the permission scheme.
:type permissionschemeid: str or int, optional
:param permission: The permission key to grant, "BROWSE_PROJECTS" if not specified.
:type permission: str, optional
:raises Exception: If permissionschemeid is not provided.
"""
if not permissionschemeid:
raise Exception("Provide a username and permissionschemeid")
if not username:
username: str = self.myself()['name']
url = self.resource_url(resource=f"permissionscheme/{permissionschemeid}/permission")
self.post(url, data=json.dumps({"holder": {"type": "user", "parameter": username}, "permission": permission}))