A Python type explainer!

Overview

typesplainer

A Python typehint explainer!

Available as a cli, as a website, as a vscode extension, as a vim extension

PyPI Website Visual Studio Marketplace Version Vim

Usage

First, install the package with pip install typesplainer

Then like any other tool such a black, isort. run typesplainer on your desired files or directory. It will automatically find all types and then explain them for you. e.g.

python -m typesplainer my_file.py
python -m typesplainer my_directory

Features

  • Very performant! Takes 1.7 seconds (YMMV) to explain the entire python rich library source code consisting of around 50,000 lines!
  • Colorized output. Output with colors is going to make sure your eyes feel refreshed.
  • Intelligent explanation. Takes pluralization, pronoun usage, article usage, correct grammar into account.
  • Best in class parser. It does not rely on some substandard AI based description generator, instead it parses the file using mypy's custom parser and shows the most accurate description

Contribute

Contributions are appreciated. See the TODO.md file or open issues

You might also like...
Crab is a flexible, fast recommender engine for Python that integrates classic information filtering recommendation algorithms in the world of scientific Python packages (numpy, scipy, matplotlib).

Crab - A Recommendation Engine library for Python Crab is a flexible, fast recommender engine for Python that integrates classic information filtering r

Python scripts to detect faces in Python with the BlazeFace Tensorflow Lite models
Python scripts to detect faces in Python with the BlazeFace Tensorflow Lite models

Python scripts to detect faces using Python with the BlazeFace Tensorflow Lite models. Tested on Windows 10, Tensorflow 2.4.0 (Python 3.8).

A fast python implementation of Ray Tracing in One Weekend using python and Taichi
A fast python implementation of Ray Tracing in One Weekend using python and Taichi

ray-tracing-one-weekend-taichi A fast python implementation of Ray Tracing in One Weekend using python and Taichi. Taichi is a simple "Domain specific

Technical Indicators implemented in Python only using Numpy-Pandas as Magic  - Very Very Fast! Very tiny!  Stock Market Financial Technical Analysis Python library .  Quant Trading automation or cryptocoin exchange
Technical Indicators implemented in Python only using Numpy-Pandas as Magic - Very Very Fast! Very tiny! Stock Market Financial Technical Analysis Python library . Quant Trading automation or cryptocoin exchange

MyTT Technical Indicators implemented in Python only using Numpy-Pandas as Magic - Very Very Fast! to Stock Market Financial Technical Analysis Python

This is an open source python repository for various python tests

Welcome to Py-tests This is an open source python repository for various python tests. This is in response to the hacktoberfest2021 challenge. It is a

Composable transformations of Python+NumPy programsComposable transformations of Python+NumPy programs

Chex Chex is a library of utilities for helping to write reliable JAX code. This includes utils to help: Instrument your code (e.g. assertions) Debug

Automatic self-diagnosis program (python required)Automatic self-diagnosis program (python required)

auto-self-checker 자동으로 자가진단 해주는 프로그램(python 필요) 중요 이 프로그램이 실행될때에는 절대로 마우스포인터를 움직이거나 키보드를 건드리면 안된다(화면인식, 마우스포인터로 직접 클릭) 사용법 프로그램을 구동할 폴더 내의 cmd창에서 pip

POPPY (Physical Optics Propagation in Python) is a Python package that simulates physical optical propagation including diffraction
POPPY (Physical Optics Propagation in Python) is a Python package that simulates physical optical propagation including diffraction

POPPY: Physical Optics Propagation in Python POPPY (Physical Optics Propagation in Python) is a Python package that simulates physical optical propaga

Space-invaders - Simple Game created using Python & PyGame, as my Beginner Python Project
Space-invaders - Simple Game created using Python & PyGame, as my Beginner Python Project

Space Invaders This is a simple SPACE INVADER game create using PYGAME whihc hav

Comments
  • [BUG]: Crash when parsing `Optional[Awaitable]`

    [BUG]: Crash when parsing `Optional[Awaitable]`

    Description of the bug

    I ran typesplainer on my code base and it crashed on the type Optional[Awaitable]. Using mypy on the same file produced no diagnostics indicating a problem with the typing. I've included a reproducer class and the stack trace in the additional information section.

    Steps To Reproduce

    1. installed from pypi
    2. ran on reproducer: python3 -m typesplainer reproducer.py
    3. crash

    Additional Information

    # reproducer.py
    from typing import Awaitable, Optional
    class BugClass:
        def no_crash(self) -> Optional[Awaitable[None]]:
            """A method that returns None or an Awaitable"""
    
        def crashes(self) -> Optional[Awaitable]:
            """A method that returns None or an Awaitable"""
    
    $ python3 -m typesplainer reproducer.py 
    Optional[Awaitable[None]] (reproducer.py:5:27) : A optional awaitable that returns nothing/none.
    Traceback (most recent call last):
      File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/runpy.py", line 197, in _run_module_as_main
        return _run_code(code, main_globals, None,
      File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/runpy.py", line 87, in _run_code
        exec(code, run_globals)
      File "/Users/ejo/Library/Caches/pypoetry/virtualenvs/busylight-for-humans-gON-ipZ_-py3.9/lib/python3.9/site-packages/typesplainer/__main__.py", line 99, in <module>
        print_description(f.read(), file_name=file)
      File "/Users/ejo/Library/Caches/pypoetry/virtualenvs/busylight-for-humans-gON-ipZ_-py3.9/lib/python3.9/site-packages/typesplainer/__main__.py", line 45, in print_description
        console.print(text, format_location(def_, typehint_text, file_name), ":", describe(def_))
      File "/Users/ejo/Library/Caches/pypoetry/virtualenvs/busylight-for-humans-gON-ipZ_-py3.9/lib/python3.9/site-packages/typesplainer/core.py", line 200, in describe
        return _describe(thing).capitalize() + "."
      File "/Users/ejo/Library/Caches/pypoetry/virtualenvs/busylight-for-humans-gON-ipZ_-py3.9/lib/python3.9/site-packages/typesplainer/core.py", line 47, in _describe
        return f"{'a ' if a else ''}optional {_describe(thing.args[0], a=False, plural=plural)}"
      File "/Users/ejo/Library/Caches/pypoetry/virtualenvs/busylight-for-humans-gON-ipZ_-py3.9/lib/python3.9/site-packages/typesplainer/core.py", line 132, in _describe
        return f"{'a ' if a else ''}awaitable that returns {_describe(thing.args[0])}"
    IndexError: tuple index out of range
    [VE] ejo@ufo:bl2 -> 
    
    
    bug 
    opened by JnyJny 4
  • [FEAT]: Type aliases aren't supported

    [FEAT]: Type aliases aren't supported

    Description

    Type aliases such as IntegerList = List[int] aren't supported yet

    FixedWidthParseSpec = Union[
        Tuple[str, int],
        Tuple[str, int, Optional[int]],
        Tuple[str, int, Optional[int], Optional[Callable[[str], Any]]],
    ]
    

    Due to how mypy parses these things these are parsed not as types but as any general python object indexing. Essentially

    List = [1, 2, 3] 
    a = List[0]
    

    And

    SomeList = List[int]
    

    Have the same structure, so differentiating between them is a bit hard and requires some processing power since these elements can be nested i.e Dict[List[str], int]

    Additional Information

    No response

    enhancement 
    opened by wasi-master 0
Owner
Typesplainer
Python typehint explainer
Typesplainer
Explainer for black box models that predict molecule properties

Explaining why that molecule exmol is a package to explain black-box predictions of molecules. The package uses model agnostic explanations to help us

White Laboratory 172 Dec 19, 2022
Runtime type annotations for the shape, dtype etc. of PyTorch Tensors.

torchtyping Type annotations for a tensor's shape, dtype, names, ... Turn this: def batch_outer_product(x: torch.Tensor, y: torch.Tensor) -> torch.Ten

Patrick Kidger 1.2k Jan 3, 2023
People movement type classifier with YOLOv4 detection and SORT tracking.

Movement classification The goal of this project would be movement classification of people, in other words, walking (normal and fast) and running. Yo

null 4 Sep 21, 2021
Collective Multi-type Entity Alignment Between Knowledge Graphs (WWW'20)

CG-MuAlign A reference implementation for "Collective Multi-type Entity Alignment Between Knowledge Graphs", published in WWW 2020. If you find our pa

Bran Zhu 28 Dec 11, 2022
LSTM Neural Networks for Spectroscopic Studies of Type Ia Supernovae

Package Description The difficulties in acquiring spectroscopic data have been a major challenge for supernova surveys. snlstm is developed to provide

null 7 Oct 11, 2022
Angle data is a simple data type.

angledat Angle data is a simple data type. Installing + using Put angledat.py in the main dir of your project. Import it and use. Comments Comments st

null 1 Jan 5, 2022
A commany has recently introduced a new type of bidding, the average bidding, as an alternative to the bid given to the current maximum bidding

Business Problem A commany has recently introduced a new type of bidding, the average bidding, as an alternative to the bid given to the current maxim

Kübra Bilinmiş 1 Jan 15, 2022
tinykernel - A minimal Python kernel so you can run Python in your Python

tinykernel - A minimal Python kernel so you can run Python in your Python

fast.ai 37 Dec 2, 2022
Python-experiments - A Repository which contains python scripts to automate things and make your life easier with python

Python Experiments A Repository which contains python scripts to automate things

Vivek Kumar Singh 11 Sep 25, 2022