python / python/mypy

Programmatic Access to Extract Type Information with mypy

Open
#15,890 1 comment 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

feature
Dominant language
Python
Stars
20.6k
Forks
3.3k
PR merge metrics
PR metrics pending

Description

Feature

I'm currently working on a project where I need to analyze a Python codebase programatically to extract type information for several variables. As mypy is a robust type-checker, I am keen on utilizing it for this purpose.

Objective: My goal is to use mypy programmatically to analyze Python code and obtain type information for specific variables.

Approaches Considered: As mypy can function as a language server, I am thinking to set up a LSP client, initiating the mypy language server, and subsequently dispatching LSP requests to gather type data. However, I am not sure about the viability of this strategy.

Direct Utilization of mypy: I am curious if there's a simpler way to leverage it directly as a library format for Python code analysis and extract type information extraction.

Questions:

Is there a recommended way to do programmatic type extraction using mypy?
Are there any internal APIs or tools within mypy that could be leveraged for this purpose?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the mypy language server and the proposed LSP-client approach, then investigate whether mypy exposes a direct library interface for extracting variable type information. The issue needs a concrete supported workflow and scope before implementation can begin; done would be a decided and documented programmatic access path.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
developer-experience, tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.