コード例 #1
0
def _check_defined_methods(cls, methods):
    instance_methods = [
        method for method in methods
        if not isinstance(cls.__dict__[method], classmethod)
    ]
    if not instance_methods:
        raise GenericClassError("Define at least one instance method")
コード例 #2
0
ファイル: private.py プロジェクト: proofit404/generics
def _check_private_methods(methods):
    private_methods = [
        method for method in methods if method.is_private_method()
    ]
    if private_methods:
        raise GenericClassError(
            "Do not use private methods (use composition instead)")
コード例 #3
0
ファイル: __init__.py プロジェクト: giladribak/testProject
def _get_fields(entity):
    if dataclasses._is_dataclass(entity):
        fields = dataclasses._get_fields(entity)
        bases = dataclasses._get_bases()
        return fields, bases
    elif pydantic._is_pydantic(entity):
        fields = pydantic._get_fields(entity)
        bases = pydantic._get_bases()
        return fields, bases
    elif attrs._is_attrs(entity):
        fields = attrs._get_fields(entity)
        bases = attrs._get_bases()
        return fields, bases
    else:
        raise GenericClassError("Unknown type definition")
コード例 #4
0
def _check_private_fields(fields):
    private_fields = [field for field in fields if field.startswith("_")]
    if private_fields:
        raise GenericClassError("Do not use private attributes")
コード例 #5
0
def _check_defined_fields(fields):
    if not fields:
        raise GenericClassError("Define at least one encapsulated attribute")
コード例 #6
0
def _check_defined_methods(methods):
    instance_methods = [method for method in methods if method.is_instance_method()]
    if not instance_methods:
        raise GenericClassError("Define at least one instance method")
コード例 #7
0
def _check_bases(cls):
    if cls.__bases__ != (object,):
        raise GenericClassError("Do not use inheritance (use composition instead)")
コード例 #8
0
 def method(*args, **kwargs):
     message = "Instance methods can not be called on classes"
     raise GenericClassError(message)
コード例 #9
0
def _deny_static_method(attribute):
    if isinstance(attribute, staticmethod):
        message = "Do not use static methods (use composition instead)"
        raise GenericClassError(message)
コード例 #10
0
def _check_private_fields(fields):
    if any(filter(lambda field: field.startswith("_"), fields)):
        raise GenericClassError("Do not use private attributes")
コード例 #11
0
def _check_private_methods(methods):
    if any(filter(lambda method: method.startswith("_"), methods)):
        raise GenericClassError(
            "Do not use private methods (use composition instead)")
コード例 #12
0
def _check_static_methods(cls, methods):
    for method in methods:
        if isinstance(cls.__dict__[method], staticmethod):
            message = "Do not use static methods (use composition instead)"
            raise GenericClassError(message)
コード例 #13
0
def _check_bases(cls, allowed_bases):
    if cls.__bases__ != allowed_bases:
        raise GenericClassError(
            "Do not use inheritance (use composition instead)")