Skip to content

Conversation

simonjayhawkins
Copy link
Member

a few files as POC/for discussion

from https://www.python.org/dev/peps/pep-0563/

PEP 3107 added support for arbitrary annotations on parts of a function definition. Just like default values, annotations are evaluated at function definition time. This creates a number of issues for the type hinting use case:

  • forward references: when a type hint contains names that have not been defined yet, that definition needs to be expressed as a string literal;
  • type hints are executed at module import time, which is not computationally free.

Postponing the evaluation of annotations solves both problems.

@simonjayhawkins simonjayhawkins added the Typing type annotations, mypy/pyright type checking label Sep 1, 2020
@WillAyd
Copy link
Member

WillAyd commented Sep 1, 2020

+/- 0 on doing this now versus waiting until its fully implemented in the standard library. Does this have a noticeable impact on import performance or is it stylistic for where we are at now?

@simonjayhawkins
Copy link
Member Author

I've not tested performance, presumably the import time gets a little longer with every type annotation added.

from a style POV. we can get rid of some noqa: F401 and get better formatting with black (although that's only really the case when PRs with whole typing expressions that sometimes get merged)

for a contributor POV, there are less things to get right if don't need to ensure types are enclosed in quotes see #36022 (comment)

from a reviewer POV, it's nice to just show the type in the IDE which can't be done with string literals (VS code anyway)

+/- 0 on doing this now versus waiting until its fully implemented in the standard library.

That'll be Python 3.10

@jreback
Copy link
Contributor

jreback commented Sep 1, 2020

I would be +1 on this.

Copy link
Member

@WillAyd WillAyd left a comment

Choose a reason for hiding this comment

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

lgtm

@WillAyd WillAyd added this to the 1.2 milestone Sep 2, 2020
@jreback jreback merged commit 5227245 into pandas-dev:master Sep 2, 2020
@jreback
Copy link
Contributor

jreback commented Sep 2, 2020

thanks @simonjayhawkins

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.

3 participants