Skip to content

Commit

Permalink
Consider more stdlib decorators to be property-like
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexWaygood committed Jul 30, 2024
1 parent e33d1f5 commit 82cded5
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 1 deletion.
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

0 comments on commit 82cded5

Please sign in to comment.