Skip to content

File: custom_types.py

Role: Python Source Code

Path: mosheh

For every type hint and notation that goes beyond the traditional, there is a custom type here created.

The idea of this types is to keep everything logical and short, with proper types and in-code description. This is a way to turn Python into a "typed" lang, kinda.

The Statement, ImportType, FunctionType and FileRole classes are enums with a really useful function: to standardize the possible types of their own types (for example, a function strictly assumes only 4 different types, and exactly one of them).

The other ones are typing.TypeAlias, simpler but also fuctional.


Imports

import Enum

Path: enum

Category: Native

SNIPPET
Python
from enum import Enum

import auto

Path: enum

Category: Native

SNIPPET
Python
from enum import auto

import TypeAlias

Path: typing

Category: Native

SNIPPET
Python
from typing import TypeAlias

Consts

NO CONSTANT DEFINED HERE


Classes

class Statement

Parents: Enum

Decorators: None

Kwargs: None

Enum-like class to enumerate in-code the dealed statements.

SNIPPET
Python
class Statement(Enum):
    """Enum-like class to enumerate in-code the dealed statements."""
    Import = auto()
    ImportFrom = auto()
    Assign = auto()
    AnnAssign = auto()
    ClassDef = auto()
    FunctionDef = auto()
    AsyncFunctionDef = auto()
    Assert = auto()

class ImportType

Parents: Enum

Decorators: None

Kwargs: None

Enum-like class to enumerate in-code the import types.

SNIPPET
Python
1
2
3
4
5
class ImportType(Enum):
    """Enum-like class to enumerate in-code the import types."""
    Native = 'Native'
    TrdParty = '3rd Party'
    Local = 'Local'

class FunctionType

Parents: Enum

Decorators: None

Kwargs: None

Enum-like class to enumerate in-code the function types.

SNIPPET
Python
1
2
3
4
5
6
class FunctionType(Enum):
    """Enum-like class to enumerate in-code the function types."""
    Function = 'Function'
    Method = 'Method'
    Generator = 'Generator'
    Coroutine = 'Coroutine'

class FileRole

Parents: Enum

Decorators: None

Kwargs: None

Enum-like class to enumerate in-code the files investigated.

SNIPPET
Python
1
2
3
class FileRole(Enum):
    """Enum-like class to enumerate in-code the files investigated."""
    PythonSourceCode = 'Python Source Code'

Functions

NO FUNCTION DEFINED HERE


Assertions

NO ASSERT DEFINED HERE