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

improvements to Assign check #76

Merged
merged 3 commits into from
Jan 16, 2022
Merged

improvements to Assign check #76

merged 3 commits into from
Jan 16, 2022

Conversation

JelleZijlstra
Copy link
Collaborator

@JelleZijlstra JelleZijlstra commented Jan 15, 2022

Fixes #44

  • introduce Y093 (require using TypeAlias for type aliases)
  • introduce Y017 (disallows assignments with multiple targets or non-name targets)
  • extend Y001 to cover ParamSpec and TypeVarTuple in addition to TypeVar

Y090 = "Y090 Use explicit attributes instead of assignments in __init__"
Y091 = 'Y091 Function body must not contain "raise"'
Y092 = "Y092 Top-level attribute must not have a default value"
Y093 = "Y093 Use typing_extensions.TypeAlias for type aliases"
Copy link
Collaborator

Choose a reason for hiding this comment

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

It seems like Y09* are used for disabled by default errors. Was the intention to add Y093 to that list?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, because we can't use it for typeshed yet (because of missing support in pytype I believe). We might have to rethink this convention though; the other Y09* checks can probably be safely enabled by default.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Cool, maybe then let's make this Y018, assuming we want to turn this on once all type checkers have support.

I couldn't find any hits for Y09* error codes on grep.app and cs.github.com so we could probably easily change the other error codes too if we wanted.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'd like to land it as Y093 first; making a non-Y09* code disabled by default is likely complicated.

Copy link
Collaborator

@hauntsaninja hauntsaninja Jan 15, 2022

Choose a reason for hiding this comment

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

Afaict there isn't any magic, it's just whatever is in DISABLED_BY_DEFAULT on L539, which this isn't and should be. Sorry, my initial comment could have been clearer.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Not quite, there's also special casing in should_warn on line 479.

Copy link
Collaborator

@hauntsaninja hauntsaninja Jan 15, 2022

Choose a reason for hiding this comment

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

Good catch, maybe that should just check for membership in DISABLED_BY_DEFAULT

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No, because it also needs to support --select=Y09. I'd rather keep the existing structure for this PR and revisit it when we address #75.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Okay, makes sense. Maybe I'm being thick, but we still need to add Y093 to DISABLED_BY_DEFAULT right (as per my first comment)?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good catch, applied that

pyi.py Outdated Show resolved Hide resolved
Co-authored-by: Shantanu <12621235+hauntsaninja@users.noreply.github.com>
Copy link
Collaborator

@hauntsaninja hauntsaninja left a comment

Choose a reason for hiding this comment

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

Lgtm, but I wouldn't mind adding tests for the new errors!

@JelleZijlstra
Copy link
Collaborator Author

I forgot to git add again didn't I.

@JelleZijlstra JelleZijlstra merged commit 56bd4f5 into master Jan 16, 2022
@JelleZijlstra JelleZijlstra deleted the typealias branch January 16, 2022 05:34
@AlexWaygood AlexWaygood mentioned this pull request Jan 18, 2022
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.

Check for type aliases not using TypeAlias
2 participants