mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-03 18:28:24 +00:00
[ruff
] add fix safety section (RUF013
) (#17759)
The PR add the fix safety section for rule `RUF013` (https://github.com/astral-sh/ruff/issues/15584 ) The fix was introduced here #4831 The rule as a lot of False Negative (as it is explained in the docs of the rule). The main reason because the fix is unsafe is that it could change code generation tools behaviour, as in the example here: ```python def generate_api_docs(func): hints = get_type_hints(func) for param, hint in hints.items(): if is_optional_type(hint): print(f"Parameter '{param}' is optional") else: print(f"Parameter '{param}' is required") # Before fix def create_user(name: str, roles: list[str] = None): pass # After fix def create_user(name: str, roles: Optional[list[str]] = None): pass # Generated docs would change from "roles is required" to "roles is optional" ```
This commit is contained in:
parent
784daae497
commit
3f32446e16
1 changed files with 5 additions and 0 deletions
|
@ -72,6 +72,11 @@ use super::super::typing::type_hint_explicitly_allows_none;
|
|||
/// ## Options
|
||||
/// - `target-version`
|
||||
///
|
||||
/// ## Fix safety
|
||||
///
|
||||
/// This fix is always marked as unsafe because it can change the behavior of code that relies on
|
||||
/// type hints, and it assumes the default value is always appropriate—which might not be the case.
|
||||
///
|
||||
/// [PEP 484]: https://peps.python.org/pep-0484/#union-types
|
||||
#[derive(ViolationMetadata)]
|
||||
pub(crate) struct ImplicitOptional {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue