Skip to content
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

Show parameters on decorated functions in PyCharm #913

Merged
merged 1 commit into from
May 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion TM1py/Services/CellService.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
case_and_space_insensitive_equals, get_cube, resembles_mdx, require_admin, extract_compact_json_cellset, \
cell_is_updateable, build_mdx_from_cellset, build_mdx_and_values_from_cellset, \
dimension_names_from_element_unique_names, frame_to_significant_digits, build_dataframe_from_csv, \
drop_dimension_properties
drop_dimension_properties, decohints

try:
import pandas as pd
Expand All @@ -45,6 +45,7 @@
_has_pandas = False


@decohints
def tidy_cellset(func):
""" Higher order function to tidy up cellset after usage
"""
Expand All @@ -68,6 +69,7 @@ def wrapper(self, cellset_id, *args, **kwargs):
return wrapper


@decohints
def manage_transaction_log(func):
""" Control state of transaction log during and after write operation for a given cube through:
`deactivate_transaction_log` and `reactivate_transaction_log`.
Expand Down Expand Up @@ -103,6 +105,7 @@ def wrapper(self, *args, **kwargs):
return wrapper


@decohints
def manage_changeset(func):
""" Control the start and end of change sets which goups write events together in the TM1 transaction log.

Expand All @@ -124,6 +127,7 @@ def wrapper(self, *args, **kwargs):
return wrapper


@decohints
def odata_compact_json(return_as_dict: bool):
""" Higher order function to manage header and response when using compact JSON

Expand Down
3 changes: 2 additions & 1 deletion TM1py/Services/ChoreService.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@
from TM1py.Objects import Chore, ChoreTask
from TM1py.Services.ObjectService import ObjectService
from TM1py.Services.RestService import RestService
from TM1py.Utils import format_url
from TM1py.Utils import format_url, decohints


@decohints
def deactivate_activate(func):
""" Higher Order function to handle activation and deactivation of chores before updating them

Expand Down
4 changes: 3 additions & 1 deletion TM1py/Services/RestService.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@

# SSO not supported for Linux
from TM1py.Exceptions.Exceptions import TM1pyTimeout
from TM1py.Utils import case_and_space_insensitive_equals, CaseAndSpaceInsensitiveSet, HTTPAdapterWithSocketOptions
from TM1py.Utils import case_and_space_insensitive_equals, CaseAndSpaceInsensitiveSet, HTTPAdapterWithSocketOptions, \
decohints

try:
from requests_negotiate_sspi import HttpNegotiateAuth
Expand All @@ -30,6 +31,7 @@
import http.client as http_client


@decohints
def httpmethod(func):
""" Higher Order Function to wrap the GET, POST, PATCH, PUT, DELETE methods
Takes care of:
Expand Down
4 changes: 3 additions & 1 deletion TM1py/Services/ServerService.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@
from TM1py.Services.ObjectService import ObjectService
from TM1py.Services.RestService import RestService
from TM1py.Utils import format_url
from TM1py.Utils.Utils import CaseAndSpaceInsensitiveDict, CaseAndSpaceInsensitiveSet, require_admin, require_version
from TM1py.Utils.Utils import CaseAndSpaceInsensitiveDict, CaseAndSpaceInsensitiveSet, require_admin, require_version, \
decohints


@decohints
def odata_track_changes_header(func):
""" Higher Order function to handle addition and removal of odata.track-changes HTTP Header

Expand Down
14 changes: 13 additions & 1 deletion TM1py/Utils/Utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from contextlib import suppress
from enum import Enum, unique
from io import StringIO
from typing import Any, Dict, List, Tuple, Iterable, Optional, Generator, Union
from typing import Any, Dict, List, Tuple, Iterable, Optional, Generator, Union, Callable

import requests
from mdxpy import MdxBuilder, Member
Expand All @@ -27,6 +27,16 @@
_has_pandas = False


def decohints(decorator: Callable) -> Callable:
"""
Decorator for decorators to see parameters of decorated functions in PyCharm

Implementation of https://github.com/gri-gus/decohints
"""
return decorator


@decohints
def require_admin(func):
@functools.wraps(func)
def wrapper(self, *args, **kwargs):
Expand All @@ -37,6 +47,7 @@ def wrapper(self, *args, **kwargs):
return wrapper


@decohints
def require_version(version):
""" Higher order function to check required version for TM1py function
"""
Expand All @@ -53,6 +64,7 @@ def wrapper(self, *args, **kwargs):
return wrap


@decohints
def require_pandas(func):
@functools.wraps(func)
def wrapper(self, *args, **kwargs):
Expand Down