Skip to content

ImportString

Wrapper for python import strings.

Handsdown API Index / Handsdown / Utils / ImportString

Auto-generated documentation for handsdown.utils.import_string module.

ImportString

Show source in import_string.py:11

Wrapper for python import strings.

Arguments

  • value - Import string.

Signature

class ImportString:
    def __init__(self, value: str) -> None:
        ...

ImportString().add

Show source in import_string.py:39

Add new import part.

Examples

ImportString("my_module") + "MyClass"
ImportString("my_module.MyClass")

ImportString("") + "MyClass"
ImportString("MyClass")

Arguments

  • other - Import string part.

Returns

A new ImportString instance.

Signature

def __add__(self, other: str) -> "ImportString":
    ...

ImportString().bool

Show source in import_string.py:62

Check if not empty.

Examples

bool(ImportString("my_module"))
True

bool(ImportString(""))
False

Returns

True if not empty.

Signature

def __bool__(self) -> bool:
    ...

ImportString().eq

Show source in import_string.py:79

Compare to another ImportString or a string.

Examples

ImportString("my_module.MyClass") == ImportString("my_module.MyClass")
True

ImportString("my_module.MyClass") == ImportString("my_module.OtherClass")
False

ImportString("my_module.MyClass") == "my_module.MyClass"
True

ImportString("my_module.MyClass") == "my_module"
False

ImportString("my_module.MyClass") == b"my_module.MyClass"
False

Arguments

other - ImportString instance or a string.

Returns

True if import strings are equal.

Signature

def __eq__(self, other: Any) -> bool:
    ...

ImportString().str

Show source in import_string.py:22

Get string value.

Examples

str(ImportString("my_module"))
"my_module"

Returns

Original import string.

Signature

def __str__(self) -> str:
    ...

ImportString().get_parents

Show source in import_string.py:164

Get all parents.

Returns

A list of ImportString instances.

Signature

def get_parents(self: _R) -> List[_R]:
    ...

ImportString().is_top_level

Show source in import_string.py:132

Check if import string has no parents.

Returns

True if it has no parents.

Signature

def is_top_level(self) -> bool:
    ...

ImportString().length

Show source in import_string.py:183

Length of import string parts.

Returns

Length of import string.

Signature

@property
def length(self) -> int:
    ...

ImportString().name

Show source in import_string.py:193

Last part of the import string.

Signature

@property
def name(self) -> str:
    ...

ImportString().parent

Show source in import_string.py:141

Parent import string.

Returns

A new ImportString instance.

Signature

@property
def parent(self: _R) -> _R:
    ...

ImportString().parts

Show source in import_string.py:114

Parts of import string splitted by dots.

Examples

ImportString("my_module.MyClass")
["my_module", "MyClass"]

ImportString("")
[]

Returns

A list of import string parts.

Signature

@property
def parts(self) -> List[str]:
    ...

ImportString().startswith

Show source in import_string.py:155

Check if it starts with import_string.

Returns

True if it is a child.

Signature

def startswith(self: _R, import_string: _R) -> bool:
    ...