Методы отображаются как атрибуты данных - PullRequest
0 голосов
/ 11 июня 2018

В настоящее время я создаю новый класс в модуле, в Python 3.6 с Pyzo, и некоторые из созданных мной методов экземпляров не отображаются в разделе справки модуля.Почему это происходит?

Вот код и раздел справки:

# Module polynoms

"""
Contains a Polynom class, in which a polynom is basically the list of its 
coefficients.
Also contains object methods that help adding two polynoms (they will be 
turned into __add__
and other special methods soon, this was the first version I have written.)

pln is an abbreviation for Polynom.
"""

from functools import wraps
# I was told in a tutorial to import this function
# in order to keep information about the methods I need to decorate.

class Polynom :
""" A way to represent polynoms """

def __init__(self,*coeff) :
    print(list(*coeff))
    for i in list(*coeff) :
        assert type(i) == float or type(i) == int
    assert len(*coeff) > 0

    self.coeff = list(*coeff) # Only one attribute

def __repr__(self) :
    return str(self.coeff)

def verif_pln(f) :
    """ Decorator that verifies
    that the arguments given to f are polynoms. """

    @wraps
    def wrapper(*arg_f) :
        try :
            for i in arg_f :
                type(i) == Polynom
        except AssertionError :
            print("Enter a valid Polynom")
    return wrapper


@verif_pln
def degre(P) :
    """ Renvoie le degré du polynôme."""
    if P == [0] :
        return "-infini"
    return len(P)-1

@verif_pln
def somme(P,Q) :
    """ Adds two polynoms. """
    S = [ 0 for i in range(max(len(P),len(Q)))]
    for i in range(min(len(P),len(Q))) :
        S[i] = P[i] + Q[i]
    return S


def prod_sc(P,k) :
    """ Multiply P by a number k. """
    P2=[]
    for p in P :
        p*=k
        P2.append(p)
    return P2

Так что это мой класс.Это единственное, что написано в файле.Когда я выполняю файл и набираю help(Polynom) в командной консоли, вот что я получаю:

Help on class Polynom in module __main__:

class Polynom(builtins.object)
 |  A way to represent polynoms
 |  
 |  Methods defined here:
 |  
 |  __init__(self, *coeff)
 |      Initialize self.  See help(type(self)) for accurate signature.
 |  
 |  __repr__(self)
 |      Return repr(self).
 |  
 |  prod_sc(P, k)
 |      Multiply P by a number k.
 |  
 |  verif_pln(f)
 |      Decorator that verifies
 |      that the arguments given to f are polynoms.
 |  
 |  ----------------------------------------------------------------------
 |  Data descriptors defined here:
 |  
 |  __dict__
 |      dictionary for instance variables (if defined)
 |  
 |  __weakref__
 |      list of weak references to the object (if defined)
 |  
 |  ----------------------------------------------------------------------
 |  Data and other attributes defined here:
 |  
 |  degre = functools.partial(<function update_wrapper at 0x...oc__', '__a...
 |      partial(func, *args, **keywords) - new function with partial application
 |      of the given arguments and keywords.
 |  
 |  somme = functools.partial(<function update_wrapper at 0x...oc__', '__a...
 |      partial(func, *args, **keywords) - new function with partial application
 |      of the given arguments and keywords.

Итак, я украсил degre и somme verif_pln, и теперь они не появляютсякак методы больше.Зачем?Кем они стали?Это проблема, и если да, то как мне ее решить?

...