[refurb] Check for subclasses includes subscript expressions (FURB189) (#16155)

## Summary

Added checks for subscript expressions on builtin classes as in FURB189.
The object is changed to use the collections objects and the types from
the subscript are kept.

Resolves #16130 

> Note: Added some comments in the code explaining why
## Test Plan


- Added a subscript dict and list class to the test file.
- Tested locally to check that the symbols are changed and the types are
kept.
- No modifications changed on optional `str` values.
This commit is contained in:
Vlad Nedelcu 2025-02-14 21:21:26 +02:00 committed by GitHub
parent f58a54f043
commit 219712860c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 65 additions and 6 deletions

View file

@ -8,7 +8,7 @@ class SetOnceMappingMixin:
if key in self:
raise KeyError(str(key) + ' already set')
return super().__setitem__(key, value)
class CaseInsensitiveEnumMeta(EnumMeta):
pass
@ -23,6 +23,12 @@ class L(list):
class S(str):
pass
class SubscriptDict(dict[str, str]):
pass
class SubscriptList(list[str]):
pass
# currently not detected
class SetOnceDict(SetOnceMappingMixin, dict):
pass