-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Standardize type comments #4467
base: main
Are you sure you want to change the base?
Changes from all commits
67119b9
aeca4e4
32e9218
95b12be
e45dc1d
4924b41
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -214,6 +214,7 @@ class Preview(Enum): | |
# hug_parens_with_braces_and_square_brackets to remove parens in some cases | ||
remove_lone_list_item_parens = auto() | ||
pep646_typed_star_arg_type_var_tuple = auto() | ||
type_comments_standardization = auto() | ||
always_one_newline_after_import = auto() | ||
|
||
|
||
|
@@ -251,13 +252,6 @@ class Mode: | |
enabled_features: set[Preview] = field(default_factory=set) | ||
|
||
def __contains__(self, feature: Preview) -> bool: | ||
""" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why was this docstring removed? |
||
Provide `Preview.FEATURE in Mode` syntax that mirrors the ``preview`` flag. | ||
|
||
In unstable mode, all features are enabled. In preview mode, all features | ||
except those in UNSTABLE_FEATURES are enabled. Any features in | ||
`self.enabled_features` are also enabled. | ||
""" | ||
if self.unstable: | ||
return True | ||
if feature in self.enabled_features: | ||
|
@@ -298,3 +292,18 @@ def get_cache_key(self) -> str: | |
features_and_magics, | ||
] | ||
return ".".join(parts) | ||
|
||
def __hash__(self) -> int: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this necessary? And could we instead make dataclass generate the hash method? |
||
return hash(( | ||
frozenset(self.target_versions), | ||
self.line_length, | ||
self.string_normalization, | ||
self.is_pyi, | ||
self.is_ipynb, | ||
self.skip_source_first_line, | ||
self.magic_trailing_comma, | ||
frozenset(self.python_cell_magics), | ||
self.preview, | ||
self.unstable, | ||
frozenset(self.enabled_features), | ||
)) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
def f( | ||
a, # type: int | ||
): | ||
pass | ||
|
||
|
||
# test type comments | ||
def f(a, b, c, d, e, f, g, h, i): | ||
# type: (int, int, int, int, int, int, int, int, int) -> None | ||
pass |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# flags: --preview | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add tests with |
||
|
||
|
||
def f( | ||
a, # type: int | ||
): | ||
pass | ||
|
||
|
||
# test type comments | ||
def f(a, b, c, d, e, f, g, h, i): | ||
# type: (int, int, int, int, int, int, int, int, int) -> None | ||
pass | ||
|
||
|
||
def f( | ||
a, # type : int | ||
b, # type : int | ||
c, #type : int | ||
d, # type: int | ||
e, # type: int | ||
f, # type : int | ||
g, #type:int | ||
h, # type: int | ||
i, # type: int | ||
): | ||
# type: (...) -> None | ||
pass | ||
|
||
|
||
|
||
# output | ||
def f( | ||
a, # type: int | ||
): | ||
pass | ||
|
||
|
||
# test type comments | ||
def f(a, b, c, d, e, f, g, h, i): | ||
# type: (int, int, int, int, int, int, int, int, int) -> None | ||
pass | ||
|
||
|
||
def f( | ||
a, # type : int | ||
b, # type : int | ||
c, # type : int | ||
d, # type: int | ||
e, # type: int | ||
f, # type : int | ||
g, # type: int | ||
h, # type: int | ||
i, # type: int | ||
): | ||
# type: (...) -> None | ||
pass |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aren't the two branches of this if-else equivalent?