Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dependency type stubs #651

Merged
merged 4 commits into from
Jun 19, 2024
Merged

dependency type stubs #651

merged 4 commits into from
Jun 19, 2024

Conversation

clavedeluna
Copy link
Contributor

@clavedeluna clavedeluna commented Jun 18, 2024

Overview

Add type stubs to our codemodder dependencies (those that have it) and write those stubs in pyproject.toml when poetry is used

Description

  • the only dependencies codemodder may inject which have type stub libraries are defusedxml and flask-wtf. The latter has two potential type libraries, types-Flask, types-WTForms, but I decided not to add types-Flask because https://pypi.org/project/types-Flask/#description because states if you use flask 2.0+ (out since 2021), the stubs are in Flask itself.
  • otherwise, I used the latest types library versions
  • From there, we want to be able to add these type stub libraries if defusedxml or flask-wtf are added by one of our codemods. At this time we will only add these when a project has a pyproject.toml using poetry. The logic for that is based on some reasonable heuristics. We will add the typing library in one of a few locations where it may be.

testing with pygoat looks like this

  - pyproject.toml
    diff:
      ---
      +++
      @@ -15,6 +15,7 @@
       requests = "^2.25.1"
       pandas = "^1.2.3"
       libcst = ">1.0"
      +defusedxml = "==0.7.1"


       [tool.poetry.dev-dependencies]
      @@ -22,4 +23,5 @@
       black = "2^0.8b1"
       flake8 = "^3.8.4"
       mypy = "~0.800"
      +types-defusedxml = "==0.7.0.20240218"

Closes #635

@clavedeluna clavedeluna marked this pull request as ready for review June 18, 2024 17:31
@@ -9,6 +9,8 @@
from codemodder.diff import create_diff_and_linenums
from codemodder.logging import logger

TYPE_CHECKER_LIBRARIES = ["mypy", "pyright"]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any others we care to add?

Copy link
Member

@drdavella drdavella left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks really good to me overall. I just have a request for an additional unit test case.

tests/dependency_management/test_pyproject_writer.py Outdated Show resolved Hide resolved
Copy link

sonarcloud bot commented Jun 19, 2024

Quality Gate Passed Quality Gate passed

Issues
1 New issue
0 Accepted issues

Measures
0 Security Hotspots
0.0% Coverage on New Code
0.0% Duplication on New Code

See analysis details on SonarCloud

@drdavella drdavella added this pull request to the merge queue Jun 19, 2024
Merged via the queue into main with commit 084a94a Jun 19, 2024
13 checks passed
@drdavella drdavella deleted the type-stubs branch June 19, 2024 16:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

When adding dependencies, include type stubs
2 participants