How to use Pythonic - 5 common examples

To help you get started, we’ve selected a few Pythonic examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jeshan / botostubs / main.py View on Github external
def get_paginator_str(paginator_model):
    value = ''
    if not paginator_model:
        return value
    for name, paginator in paginator_model._paginator_config.items():
        wait_docstr = f'r"""see function `{pythonic.xform_name(name)}` for valid parameters"""'
        value += f"""    class {name}Paginator(Paginator):
        def wait(self, **kwargs):
            {wait_docstr}
            pass
"""
    value += '\n'
    return value
github jeshan / botostubs / main.py View on Github external
def get_waiter_str(waiter_model):
    value = ''
    if not waiter_model:
        return value
    for name in waiter_model.waiter_names:
        waiter = waiter_model.get_waiter(name)
        wait_docstr = f'r"""see function `{pythonic.xform_name(waiter.operation)}` for valid parameters"""'
        value += f"""    class {name}Waiter(Waiter):
        def wait(self, **kwargs):
            {wait_docstr}
            pass
"""
    value += '\n'
    return value
github jeshan / botostubs / main.py View on Github external
if shape_class[1] != name:
                continue
            base_type = 'Mapping' if shape_class[0].type_name == 'structure' else 'object'
            shape_str.append(f"""            class {shape_class[0].name}({base_type}):
                pass
""")

        return '\n'.join(set(shape_str))

    service_model = resource.meta.client.meta.service_model  # sub_resource.resource.meta.client.meta.service_model
    attr = getattr(resource, sub_resource.name)

    params = []
    shape_classes = []
    for identifier in sub_resource.resource.identifiers:
        params.append(pythonic.xform_name(identifier.target))

    model_shape = sub_resource.resource.model.shape
    attributes_doc = '\n            '
    if model_shape:
        shape = service_model.shape_for(model_shape)
        attributes = resource.meta.resource_model.get_attributes(shape)
        for key, value in attributes.items():
            type_shape = value[1]
            attributes_doc += get_param_name(type_shape, key, type_shape, shape_classes, resource_name) + f"""
            """
    resource_doc = f'r"""{inspect.getdoc(attr)}"""'
    params_str = ''
    if len(params):
        params_str = ', ' + ', '.join(params)
    return f"""        
        class {sub_resource.name}:
github jeshan / botostubs / main.py View on Github external
def get_method_signature(service_model, operation_name, shapes, class_name):
    pythonic_op_name = pythonic.xform_name(operation_name)
    operation_model = service_model.operation_model(operation_name)
    input_shape = operation_model.input_shape
    output_shape = operation_model.output_shape
    parameters = input_shape.members if input_shape else {}

    if input_shape:
        append_to_shapes(input_shape, class_name, shapes)
    if output_shape:
        append_to_shapes(output_shape, class_name, shapes)

    param_list = get_param_list(input_shape, parameters, shapes, class_name)

    param_str = ', '.join(param_list)

    operation_doc = operation_model.documentation.replace('<p>', '').replace('</p>', '')
    docstr = f'r"""{operation_doc}\n'
github rg3915 / python-experience / pythonic / vector0.py View on Github external
def __mul__(self, scalar):
        if isinstance(scalar, numbers.Real):
            return Vector(n * scalar for n in self)
        else:
            return NotImplemented

Pythonic

Graphical automation tool

GPL-3.0
Latest version published 3 years ago

Package Health Score

39 / 100
Full package analysis