Typehints with documentation.
Project description
IntelliType
IntelliType is a Python library that provides enhanced type annotations with custom structure and validation capabilities. It combines the power of static type hinting with runtime type checking and validation, while ensuring full intellisense support.
Features
- Enhanced type annotations with full intellisense support
- Runtime type checking and validation
- Integration with Pydantic for robust data validation
- Support for custom metadata in type definitions
Installation
You can install IntelliType using pip:
pip install crimson-intelli-type
Quick Start
Here's a simple example of how to use IntelliType:
from typing import List, Generic, TypeVar
from crimson.intelli_type import IntelliType
T = TypeVar('T')
class IntList(IntelliType, List[int], Generic[T]):
pass
# This will pass and provide full intellisense support
valid_list: IntList[List[int]] = IntList.type_safe([1, 2, 3])
# This will raise a validation error
invalid_list: IntList[List[int]] = IntList.type_safe(["a", "b", "c"])
Advanced Usage
IntelliType supports adding custom metadata to your type definitions:
class CustomType(IntelliType, List[int], Generic[T]):
pass
CustomType[List[int], "This is custom metadata"]
Why use Generic[T]?
Including Generic[T]
in your IntelliType class definition is crucial for proper intellisense support. It allows your IDE to provide accurate type hints and autocompletion, enhancing your development experience and catching potential type errors early.
Examples
AutoPydantic
I used IntelliType to add type hints to AutoPydantic. The custom types are imported from another script. In the current script, you can easily access the type information by hovering over the variables.
DeepLearning
Please check out the example in the link below. When using IntelliType, we don't write docstrings for attributes in the function documentation. Instead, arguments are individually documented, and their docstrings are reused throughout the code. This allows you to focus the function's documentation solely on describing its purpose and behavior.
Reusability
One of the biggest advantages of IntelliType is its reusability. Many arguments are often used across different functions. Traditionally, you would need to write the docstring for these arguments repeatedly.
The worst-case scenario is when you've written docstrings in multiple places and can't remember where they all are. When you modify one of your arguments, you'd need to edit all the related docstrings. However, with IntelliType, the information for your arguments is used consistently, allowing you to manage your package more cleanly and reliably.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for crimson_intelli_type-0.1.3.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 205713568a0c4940b06438e22cf0770749dc4770cb53dac6eb17caef38e0e496 |
|
MD5 | e57b76e208433e3b205a4c906c44bfb8 |
|
BLAKE2b-256 | d63d61015575f40136adeb377abb0209cb64550ef32f0363269f4715a97b91b1 |
Hashes for crimson_intelli_type-0.1.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a9a0de85e016f395c2f72a46355f4169a0732fceef6d87d0e3d6ceff984e327c |
|
MD5 | b3a1bb2de5be912c7d93727abc006a17 |
|
BLAKE2b-256 | a3cbb2caea7b4e6f315f8be94113fcd8d135f16122e2f09bd7daf6dfc8328995 |