Skip to main content

Derives type hints from data captured during runtime. Updates source files with type hints. USE SOURCE CONTROL before upating in-place!!!!

Project description

How to use

from whatthetype.whatthetype import trace, type_it_like_its_hot

def foo(i,
        x):
    return {'a': [(i + x,)]}

with trace() as data:
    foo(11, 2)
type_it_like_its_hot(data, update_files=True, backup_file_suffix=None, dump_intermediate_data=False)

Result

from whatthetype.whatthetype import trace, type_it_like_its_hot

def foo(i: int,
        x: int) -> dict[str, list[tuple[int]]]:
    return {'a': [(i + x,)]}

with trace() as data:
    foo(11, 2)
type_it_like_its_hot(data, update_files=True, backup_file_suffix=None, dump_intermediate_data=False)

What

Inspects code at runtime, derives types from arguments and updates in-place source files with detected type hints and required imports.

Requirements

At minimum 3.5 - I haven't tested properly. Ideally use 3.9 or higher ( This lib supports both Union and '|' operators)

Install

pip install whatthetype

Params

""" params
update_files: updates source files in place with new types, this is a destructive action! 
            If False, results json will be saved to a file with unix timestamp. 
            Default = False.
backup_file_suffix: creates backup files and adds suffix to them.
            Example: backup_file_suffix="bak" will create `foo.py.bak`. 
            Default = "bak"
dump_intermediate_data: will create 3 files with intermediate data used to derive final results. 
            Default = False
"""

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

whatthetype-1.1-py3-none-any.whl (10.5 kB view details)

Uploaded Python 3

File details

Details for the file whatthetype-1.1-py3-none-any.whl.

File metadata

  • Download URL: whatthetype-1.1-py3-none-any.whl
  • Upload date:
  • Size: 10.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.9.21

File hashes

Hashes for whatthetype-1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 9e02896bd82200065e4cf775d9d75282fba431a6e8ea2d52705c08811d13ca93
MD5 66556fc42a1d58b9b18b84c95ea8c2ad
BLAKE2b-256 d97eed968a3ace63623f20e434be44b240a0a07d2cddcc96f9e42c07187c610b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page