Skip to main content

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.

Metadata

Release files for uglyduck 0.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for uglyduck 0.0.3
File Size Uploaded Provenance Actions
uglyduck-0.0.3.tar.gz 9.8 kB Without provenance Details for uglyduck-0.0.3.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for uglyduck 0.0.3
File Interpreter ABI Platform Actions
uglyduck-0.0.3-py3-none-any.whl Python 3 none any Details for uglyduck-0.0.3-py3-none-any.whl

Total release size: 19.9 kB

Release files / uglyduck-0.0.3.tar.gz

Download URL uglyduck-0.0.3.tar.gz
Size 9.8 kB
Tags Source
SHA-256 checksum
How to use checksums
ce06526ed4f0d4ff4b48fb61b56d1a7630c091f08cbfd728f9b3028445b047d8
BLAKE2b-256 checksum
How to use checksums
f0253ab3b7c71a3ac08c4c7027394f8f53ce48d361b6ee01665c86e8dc23b66b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.10

Release files / uglyduck-0.0.3-py3-none-any.whl

Download URL uglyduck-0.0.3-py3-none-any.whl
Size 10.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
40277b968704e586b07174aebd1d2b11776f6e373a733958b08747317d3fd1d6
BLAKE2b-256 checksum
How to use checksums
6cf0e013da478cea702ecf80494c55ddc53b340c371fd2f2c6cc479714ec61ee
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.10

Security for uglyduck 0.0.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page