usort/api.py
def usort(data: bytes, config: Config, path: Optional[Path] = None) -> Result:
    """
    Given bytes for a module, this parses and sorts imports, and returns a Result.
    """
    if path is None:
        path = Path("<data>")

    try:
        module = try_parse(data=data, path=path)
        sorter = ImportSorter(module=module, path=path, config=config)
        new_mod = sorter.sort_module()

        return Result(
            path=path,
            content=data,
            output=new_mod.bytes,
            encoding=new_mod.encoding,
            timings=get_timings(),
            warnings=sorter.warnings,
        )

    except Exception as e:
        return Result(
            path=path,
            content=data,
            error=e,
            timings=get_timings(),
        )

    Given bytes for a module, this parses and sorts imports, and returns a Result.
    
Given bytes for a module, this parses and sorts imports, and returns a Result.
Given bytes for a module this parses and sorts imports and returns a Result .
def usort(data: bytes, config: Config, path: Optional[Path] = None) -> Result:
    if path is None:
        path = Path("<data>")
    try:
        module = try_parse(data=data, path=path)
        sorter = ImportSorter(module=module, path=path, config=config)
        new_mod = sorter.sort_module()
        return Result(
            path=path,
            content=data,
            output=new_mod.bytes,
            encoding=new_mod.encoding,
            timings=get_timings(),
            warnings=sorter.warnings,
        )
    except Exception as e:
        return Result(
            path=path,
            content=data,
            error=e,
            timings=get_timings(),
        )
def usort ( data : bytes , config : Config , path : Optional [ Path ] = None ) -> Result : if path is None : path = Path ( "<data>" ) try : module = try_parse ( data = data , path = path ) sorter = ImportSorter ( module = module , path = path , config = config ) new_mod = sorter . sort_module ( ) return Result ( path = path , content = data , output = new_mod . bytes , encoding = new_mod . encoding , timings = get_timings ( ) , warnings = sorter . warnings , ) except Exception as e : return Result ( path = path , content = data , error = e , timings = get_timings ( ) , )
Given bytes for a module, this parses and sorts imports, and returns a Result.
Given bytes for a module this parses and sorts imports and returns a Result .
"""
    Given bytes for a module, this parses and sorts imports, and returns a Result.
    """
data
bytes
config
Config
path
Optional[Path]