Generate a types.py file for a package that contains protocols for classes generated from the files specified.
Project description
Ugly Duck
Use this module to make protocols based on classes in your python project. This project was made out of frustration with the current state of static types in Python 3, mainly juggling with circular imports and the workaround of importing with TYPE_CHECKING. I originally made this to generate a starting point for one of my projects, but I ended up enjoying working with it and ended up setting it up to work in real-time in other projects. It makes working with static typing in Python as easy as it is in other languages. All protocols are the class name with an 'I' prefix. For example, a class named 'User' will have a protocol named 'IUser'. You can then import IUser from the types.py file and use it anywhere and not have to think about/manage imports. It's ugly, I know.
Installation
pip install uglyduck
Usage
Include the following in a package's __init__.py
file:
from uglyduck.inspector import TypeInspector
# This will create packagename/types.py with protocols for all classes in the
# models and helpers modules.
TypeInspector.make_package_types_file('packagename', modules=[
'models',
'helpers'
])
If you're using Django, you will need to run it after the app is ready in your
apps.py
file:
from django.conf import settings
from django.apps import AppConfig
from uglyduck.inspector import TypeInspector
class MyAppConfig(AppConfig):
name = "apps.myapp"
def ready(self):
if settings.DEBUG:
TypeInspector.make_package_types_file('apps.myapp', modules=[
'models',
'helpers'
])
Possible Improvements
- Support inheritance from classes outside of the package.
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
File details
Details for the file uglyduck-0.0.3.tar.gz
.
File metadata
- Download URL: uglyduck-0.0.3.tar.gz
- Upload date:
- Size: 9.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ce06526ed4f0d4ff4b48fb61b56d1a7630c091f08cbfd728f9b3028445b047d8 |
|
MD5 | de4033bd11fb2f3b8af627158a3215bb |
|
BLAKE2b-256 | f0253ab3b7c71a3ac08c4c7027394f8f53ce48d361b6ee01665c86e8dc23b66b |
File details
Details for the file uglyduck-0.0.3-py3-none-any.whl
.
File metadata
- Download URL: uglyduck-0.0.3-py3-none-any.whl
- Upload date:
- Size: 10.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 40277b968704e586b07174aebd1d2b11776f6e373a733958b08747317d3fd1d6 |
|
MD5 | 0d2d31c34ed411975aab66d5c9ea8f9d |
|
BLAKE2b-256 | 6cf0e013da478cea702ecf80494c55ddc53b340c371fd2f2c6cc479714ec61ee |