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

TYP: disallow comment-based annotation syntax #29741

Merged
merged 8 commits into from
Nov 21, 2019

Conversation

simonjayhawkins
Copy link
Member

No description provided.

@simonjayhawkins simonjayhawkins added Code Style Code style, linting, code_checks Typing type annotations, mypy/pyright type checking labels Nov 20, 2019
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.

looks pretty good one comment

@@ -328,8 +328,9 @@ def my_dog(has='fleas'):
"""

def __init__(self, addendum: Optional[str], join: str = "", indents: int = 0):
self.addendum: Optional[str]
Copy link
Member

Choose a reason for hiding this comment

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

For instance variables I think should follow PEP 526 (@jbrockmendel had this on another PR) so this would move to the class space without definition:

https://www.python.org/dev/peps/pep-0526/#class-and-instance-variable-annotations

Copy link
Member Author

Choose a reason for hiding this comment

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

sure. is that the intention of the PEP? or for compatibility with stubs and dataclasses?

the first line reads "Type annotations can also be used to annotate class and instance variables in class bodies and methods."

and since we have methods, why not annotate where they are defined.

in __init__ it makes no difference but in say DataFrameFormatter, self.max_rows_adj is only added in _chk_truncate and so would be wrong to suggest that the variable always exists and that a hasattr check is not necessary?

Copy link
Member

Choose a reason for hiding this comment

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

The PEP describes all variable annotations. Admittedly haven't gone over every detail so if you see something counter lmk

Copy link
Member

Choose a reason for hiding this comment

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

and so would be wrong to suggest that the variable always exists and that a hasattr check is not necessary?

I think this is part of the benefit of having the annotations; the variable should be set to None in __init__ in this kind of case. In e.g. io.pytables im finding class-level annotations really helpful in classes that set their attributes in a bunch of places.

Copy link
Member Author

Choose a reason for hiding this comment

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

sure. refactoring the code may be beneficial. my comment was regarding adding annotations to the existing code without modification.

should we refactor in parallel to adding type hints, or refactor in a separate PR?

Copy link
Member Author

Choose a reason for hiding this comment

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

in general?

@WillAyd WillAyd added this to the 1.0 milestone Nov 20, 2019
@jreback
Copy link
Contributor

jreback commented Nov 20, 2019

@WillAyd happy to have specific questions in a followup for @simonjayhawkins

can you rebase.

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.

yea lgtm pending merge conflict. nothing outstanding on my end

@jreback
Copy link
Contributor

jreback commented Nov 21, 2019

@simonjayhawkins one more rebase and merge on green.

@simonjayhawkins
Copy link
Member Author

sure

@simonjayhawkins simonjayhawkins merged commit 555e6e1 into pandas-dev:master Nov 21, 2019
proost pushed a commit to proost/pandas that referenced this pull request Dec 19, 2019
proost pushed a commit to proost/pandas that referenced this pull request Dec 19, 2019
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.

5 participants