Skip to content

CLN, TYP Remove string type hints #39299

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 2 commits into from
Jan 21, 2021

Conversation

MarcoGorelli
Copy link
Member

  • Ensure all linting tests pass, see here for how to run them

For some background: there was some consensus on doing this here

Then here there was the suggestion to use ast.parse, rather than regular expressions. I had a go at that, and made this into its own package: https://github.com/MarcoGorelli/no-string-hints , which I've included here as a pre-commit hook

The changes here are just a result of running pre-commit run no-string-hints -a, and then adding from __future__ import annotations to some files.

@MarcoGorelli MarcoGorelli changed the title remove string type hints CLN, TYP Remove string type hints Jan 20, 2021
@MarcoGorelli MarcoGorelli added Code Style Code style, linting, code_checks Typing type annotations, mypy/pyright type checking labels Jan 20, 2021
Copy link
Contributor

@jreback jreback left a comment

Choose a reason for hiding this comment

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

wow. lgtm. cc @simonjayhawkins

just have to make sure the author sticks around :->

Copy link
Member

@rhshadrach rhshadrach left a comment

Choose a reason for hiding this comment

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

This is great! Just one question below.

Comment on lines 67 to -68
if TYPE_CHECKING:
from numpy.ma.mrecords import MaskedRecords

from pandas import Series
Copy link
Member

Choose a reason for hiding this comment

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

Curious what happened here. Series is imported inline below, so am I correct to say that this is sufficient for mypy?

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks!

And yes, seems like it, e.g.:
t.py:

def foo() -> None:
    a: List[int]
    reveal_type(a)
    from typing import List
$ python3.8 -m mypy t.py 
t.py:3: note: Revealed type is 'builtins.list[builtins.int]'

@simonjayhawkins simonjayhawkins merged commit 0d5a644 into pandas-dev:master Jan 21, 2021
@simonjayhawkins
Copy link
Member

Thanks @MarcoGorelli. this is great.

@MarcoGorelli
Copy link
Member Author

Thanks all for your kind words, much appreciated 🙏 !

@MarcoGorelli MarcoGorelli deleted the no-string-hints branch January 21, 2021 12:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Code Style Code style, linting, code_checks Typing type annotations, mypy/pyright type checking
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants