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

[2097] Fix is_type_comment #3339

Open
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

itxasos23
Copy link

Description

Issue #2097 raised the issue that is_type_comment only works for comments starting with # type:, and more spaces/tabs between # and type, or typeand : are valid as per typed-ast/ast, but not black.

This PR (for now!) only tries to make is_type_comment be consistent with typed-ast, not to remove the extra spaces/tabs if they are present.

I'd like some guidance as to:

  • Using regex. Is there a way to perform this check fast, while not changing the ast parsing?
  • Testing. I want to unit test the method to ensure it works as expected, but I don't see tests for similar functions in the tests directory. Is this by design?
  • Is this user facing?
  • Do you think it makes sense to parse these type_comments into its component tokens: #, type, : and the rest? I believe that would help with fixing the formatting.

Checklist - did you ...

  • Add an entry in CHANGES.md if necessary?
  • Add / update tests if necessary?
  • Add new / update outdated documentation?

@github-actions
Copy link

github-actions bot commented Oct 17, 2022

diff-shades reports zero changes comparing this PR (1303fb4) to main (26de5f9).


What is this? | Workflow run | diff-shades documentation

@itxasos23
Copy link
Author

I'd argue this PR doesn't merit a changelog entry by now (maybe it does if we decide to reformat # type:* comments?)

Copy link

@clavedeluna clavedeluna left a comment

Choose a reason for hiding this comment

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

LGTM! Hopefully a maintainer will answer the questions on your PR description :)

@ichard26
Copy link
Collaborator

Hey!

I just wanted to say thank you for submitting a PR. I know us maintainers haven't been very active reviewing PRs lately and that's disheartening. I speak for the rest of the maintainership team that we really appreciate all of your work.

I promise I've seen this come into my inbox and care about it. I've just been really busy lately and finding time (and the energy) to do reviews has been tough. I'll try my best to find time this week.

Thanks again.

Copy link
Collaborator

@cooperlees cooperlees left a comment

Choose a reason for hiding this comment

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

I know there's probably been discussion, but I don't like we're introducing a regex to parse for broken syntactical usages of a deprecated (or are there valid uses I don't know of for type comments) feature of Python ...

Copy link
Collaborator

@JelleZijlstra JelleZijlstra left a comment

Choose a reason for hiding this comment

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

How does this affect formatting in practice? It's not clear to me whether this will need to go in the preview style.

Also, you need a changelog entry.

@@ -778,12 +779,18 @@ def is_import(leaf: Leaf) -> bool:
)


is_type_comment_regex = re.compile(r"^#[\s\t]+type[\s\t]*:")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Isn't \t included in \s?

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.

None yet

5 participants