mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-29 21:35:58 +00:00

## Summary PIE807 will rewrite `lambda: []` to `list` -- AFAICT though, the same rationale also applies to dicts, so I've modified the code to also rewrite `lambda: {}` to `dict`. Two things I'm not sure about: * Should this go to a new rule? This no longer actually matches the behavior of flake8-pie, and while I think thematically it makes sense to be part of the same rule, we could make it a standalone rule (but if so, where should I put it and what error code should I use)? * If we want a single rule, are there backwards compatibility concerns with the rule name change (from `reimplemented_list_builtin` to `reimplemented_container_builtin`? ## Test Plan Added snapshot tests of the functionality.
37 lines
809 B
Python
37 lines
809 B
Python
@dataclass
|
|
class Foo:
|
|
foo: List[str] = field(default_factory=lambda: []) # PIE807
|
|
bar: Dict[str, int] = field(default_factory=lambda: {}) # PIE807
|
|
|
|
|
|
class FooTable(BaseTable):
|
|
foo = fields.ListField(default=lambda: []) # PIE807
|
|
bar = fields.ListField(default=lambda: {}) # PIE807
|
|
|
|
|
|
class FooTable(BaseTable):
|
|
foo = fields.ListField(lambda: []) # PIE807
|
|
bar = fields.ListField(default=lambda: {}) # PIE807
|
|
|
|
|
|
@dataclass
|
|
class Foo:
|
|
foo: List[str] = field(default_factory=list)
|
|
bar: Dict[str, int] = field(default_factory=dict)
|
|
|
|
|
|
class FooTable(BaseTable):
|
|
foo = fields.ListField(list)
|
|
bar = fields.ListField(dict)
|
|
|
|
|
|
lambda *args, **kwargs: []
|
|
lambda *args, **kwargs: {}
|
|
|
|
lambda *args: []
|
|
lambda *args: {}
|
|
|
|
lambda **kwargs: []
|
|
lambda **kwargs: {}
|
|
|
|
lambda: {**unwrap}
|