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

Consider more stdlib decorators to be property-like #12583

Merged
merged 1 commit into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions crates/ruff_linter/resources/test/fixtures/flake8_return/RET501.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,25 @@ class BaseCache2:
def prop(self) -> None:
print("Property not found")
return None


import abc
import enum
import types


class Baz:
@abc.abstractproperty
def prop2(self) -> None:
print("Override me")
return None

@types.DynamicClassAttribute
def prop3(self) -> None:
print("Gotta make this a multiline function for it to be a meaningful test")
return None

@enum.property
def prop4(self) -> None:
print("I've run out of things to say")
return None
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,22 @@ class Cached:
@cached_property
def cached_prop(self, value): # [property-with-parameters]
...


import abc
import enum
import types


class Baz:
@abc.abstractproperty
def prop2(self, param) -> None: # [property-with-parameters]
return None

@types.DynamicClassAttribute
def prop3(self, param) -> None: # [property-with-parameters]
return None

@enum.property
def prop4(self, param) -> None: # [property-with-parameters]
return None
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,28 @@ property_with_parameters.py:48:9: PLR0206 Cannot have defined parameters for pro
| ^^^^^^^^^^^ PLR0206
49 | ...
|

property_with_parameters.py:59:9: PLR0206 Cannot have defined parameters for properties
|
57 | class Baz:
58 | @abc.abstractproperty
59 | def prop2(self, param) -> None: # [property-with-parameters]
| ^^^^^ PLR0206
60 | return None
|

property_with_parameters.py:63:9: PLR0206 Cannot have defined parameters for properties
|
62 | @types.DynamicClassAttribute
63 | def prop3(self, param) -> None: # [property-with-parameters]
| ^^^^^ PLR0206
64 | return None
|

property_with_parameters.py:67:9: PLR0206 Cannot have defined parameters for properties
|
66 | @enum.property
67 | def prop4(self, param) -> None: # [property-with-parameters]
| ^^^^^ PLR0206
68 | return None
|
5 changes: 4 additions & 1 deletion crates/ruff_python_semantic/src/analyze/visibility.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,10 @@ pub fn is_property(
.is_some_and(|qualified_name| {
matches!(
qualified_name.segments(),
["" | "builtins", "property"] | ["functools", "cached_property"]
["" | "builtins" | "enum", "property"]
| ["functools", "cached_property"]
| ["abc", "abstractproperty"]
| ["types", "DynamicClassAttribute"]
) || extra_properties
.iter()
.any(|extra_property| extra_property.segments() == qualified_name.segments())
Expand Down
Loading