Skip to content

Commit

Permalink
get rid of Y090 and Y091
Browse files Browse the repository at this point in the history
Part of #86
  • Loading branch information
JelleZijlstra committed Jan 16, 2022
1 parent 8732e45 commit 8d3e181
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 28 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ Change Log
unreleased
~~~~~~~~~~

* extend Y010 to cover what was previously included in Y090 (disallow
assignments in ``__init__`` methods) and Y091 (disallow ``raise``
statements)
* extend Y010 to check async functions in addition to normal functions
* introduce Y093 (require using TypeAlias for type aliases)
* introduce Y017 (disallows assignments with multiple targets or non-name targets)
Expand Down
17 changes: 1 addition & 16 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ currently emitted:
* Y009: Empty body should contain "...", not "pass". This is just a stylistic
choice, but it's the one typeshed made.
* Y010: Function body must contain only "...". Stub files should not contain
code, so function bodies should be empty. Currently, we make exceptions for
raise statements and for assignments in `__init__` methods.
code, so function bodies should be empty.
* Y011: All default values for typed function arguments must be "...". Type
checkers ignore the default value, so the default value is not useful
information in a stub file.
Expand All @@ -70,20 +69,6 @@ currently emitted:

The following warnings are disabled by default:

* Y090: Use explicit attributes instead of assignments in `__init__`. This
is a stricter version of Y010. Instead of::

class Thing:
def __init__(self, x: str) -> None:
self.x = x

you should write::

class Thing:
x: str
def __init__(self, x: str) -> None: ...

* Y091: Function body must not contain "raise".
* Y092: Top-level attribute must not have a default value.

License
Expand Down
13 changes: 1 addition & 12 deletions pyi.py
Original file line number Diff line number Diff line change
Expand Up @@ -412,15 +412,6 @@ def _visit_function(self, node: ast.FunctionDef | ast.AsyncFunctionDef) -> None:
statement.value, ast.Ellipsis
):
continue
# special-case raise for backwards compatibility
if isinstance(statement, ast.Raise):
self.error(statement, Y091)
continue
# allow assignments in constructor for now
# (though these should probably be changed)
if node.name == "__init__":
self.error(statement, Y090)
continue
self.error(statement, Y010)

def visit_arguments(self, node: ast.arguments) -> None:
Expand Down Expand Up @@ -534,9 +525,7 @@ def should_warn(self, code):
Y015 = 'Y015 Attribute must not have a default value other than "..."'
Y016 = "Y016 Duplicate union member"
Y017 = "Y017 Only simple assignments allowed"
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"

DISABLED_BY_DEFAULT = [Y090, Y091, Y092, Y093]
DISABLED_BY_DEFAULT = [Y092, Y093]

0 comments on commit 8d3e181

Please sign in to comment.