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.0-py3-none-any.whl (10.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: whatthetype-1.0-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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 bd6d724263f41daf4efab1e1eef55c713e9394097352eadf5a9449d59a5bac12
MD5 ac044c5662ae0e3463ae2451e4dceebc
BLAKE2b-256 ce4d56f500f70aa1b7de3b8c2b76492110e0c42e5cfdf0deb49f5292debf442c

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