Skip to content

TYP: Autotyping #48191

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

Merged
merged 13 commits into from
Sep 8, 2022
Merged

TYP: Autotyping #48191

merged 13 commits into from
Sep 8, 2022

Conversation

twoertwein
Copy link
Member

Running autotyping on pandas https://github.com/JelleZijlstra/autotyping

Would be great to add it to pre-commit but before that many abstractmethods need return type annotations (autotyping let's them return None or wait for JelleZijlstra/autotyping#33).

closes #46337
xref #47497

@property
# error: Cannot override final attribute "_is_mixed_type" (previously declared
# in base class "NDFrame")
@property # type: ignore[misc]
def _is_mixed_type(self) -> bool:
Copy link
Member Author

Choose a reason for hiding this comment

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

NDFrame declares _is_mixed_type as final! This method should not exist or the parent method should not be final.

Not sure why mypy didn't find this earlier.

Choose a reason for hiding this comment

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

Mypy generally doesn't check unannotated methods. It should probably still check @final though.

…urrent __new__ methods were called but I think these pickle tests call older __new__ methods which allowed providing multiple positional arguments)
@twoertwein twoertwein added the Typing type annotations, mypy/pyright type checking label Aug 21, 2022
@twoertwein
Copy link
Member Author

This should be ready from my perspective @mroeschke Can work on integrating autotyping into the CI after its next release.

@@ -252,3 +252,14 @@ repos:
/(__init__\.py)|(api\.py)|(_version\.py)|(testing\.py)|(conftest\.py)$
|/tests/
|/_testing/
- id: autotyping
name: autotyping
entry: python -m libcst.tool codemod autotyping.AutotypeCommand --safe 1
Copy link
Member

Choose a reason for hiding this comment

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

Nit: I would slightly prefer --safe to be expanded into the actual flags it enables (unless there's not a way to enable all the transformations at once) so it's more obvious what autotyping occurs.

Copy link
Member Author

Choose a reason for hiding this comment

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

Okay, will change that.

Is it okay to add the .libcst.codemod.yaml? It is needed. If we don't want to clutter the main folder, I could create scripts/run_autotyping.py and create this file only temporarily.

Copy link
Member

Choose a reason for hiding this comment

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

Is it okay to add the .libcst.codemod.yaml?

Yeah sure that would be okay!

@mroeschke mroeschke added this to the 1.6 milestone Sep 8, 2022
@mroeschke mroeschke merged commit 54347fe into pandas-dev:main Sep 8, 2022
@mroeschke
Copy link
Member

Thanks @twoertwein!

@twoertwein twoertwein deleted the autotyping branch September 10, 2022 01:38
@mroeschke mroeschke modified the milestones: 1.6, 2.0 Oct 13, 2022
noatamir pushed a commit to noatamir/pandas that referenced this pull request Nov 9, 2022
* annotate-magics

* annotate-imprecise-magics

* none-return

* scalar-return

* pyi files

* ignore vendored file

* manual changes

* ignore pyright in pickle_compat (these errors would be legit if the current __new__ methods were called but I think these pickle tests call older __new__ methods which allowed providing multiple positional arguments)

* run autotyping in pre-commit

* remove final and expand safe (and add annotate-imprecise-magics)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Typing type annotations, mypy/pyright type checking
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TYP: returning None for __init__
3 participants