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

class-level classmethod() can only be called on a method_descriptor or instance method. #3044

Open
zwigid opened this issue Jul 17, 2019 · 0 comments

Comments

@zwigid
Copy link

commented Jul 17, 2019

util.py:

import inspect

class Singleton(type):
    _instances=[]
    def __call__(cls, *args, **kwargs):
        if cls not in cls._instances:
            cls._instances[cls] = super(Singleton, cls).__call__(*args, **kwargs)


class MetaResult(Singleton):
    def __getattribute__(cls, name):
        return super().__getattribute__(name)

class Result(metaclass=MetaResult):
    @staticmethod
    def res_decorator(func):
        def funcwrap(*args, **kwargs):
            sig = inspect.signature(func)
            bound_sig = sig.bind(*args, **kwargs)
            bound_sig.apply_defaults()
            #additional code to extract function arguments 
        return funcwrap        

check_params.py

from util.py import Result as _Result
from abc import ABCMeta as _ABCMeta

class paramparse(metaclass=_ABCMeta)

    @classmethod
    @_Result.res_decorator
    def parse_flash_params(cls, flash_config_path):
        #some code

Now, I cythonize the file check_params.py with following setup :
cythonize.py

import os as _os
from pathlib import Path as _Path
from distutils.core import setup as _setup
from Cython.Distutils import build_ext as _build_ext

files_to_compile = []

def cython_build(source_path):
    for dirpath, _, fnames in os.walk(source_path):
        for fname in [x for x in fnames if f.endswith('.py'):
            fname = _Path(fname)
            files_to_compile.append(fname)

    for e in files_to_compile:
        e.cython_directives = {'binding':True, 'language_level':3}

    _setup(name="Proj1",cmdclass={build_ext':_build_ext}, ext_modules=files_to_compile}      

cythonized as: python cythonize.py --path C:\directory_where_check_params_exist

generates a pyd file on which the following unit tests were attempted to run:

Now, coming to the usage, in the unit tests:

unit_test_check_params.py

from check_params import *    #getting error here , details outside the code

# unit tests written here

check_params.pyx:112: in init check_params ??? E
TypeError: Class-level classmethod() can only be called on a method_descriptor or instance method.

So when i debug this, the error appears as being caused because of the classmethod descriptor over decorator (def parse_flash_params) in check_params.py

Please let me know if you need more information.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant
You can’t perform that action at this time.