You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
C416 suggests changing d2 to dict(d1), which is incorrect because this will just copy d1.
This seems like an intractable problem to solve in general because you'd have to know whether the thing being iterated over is a dict. In a case like this I suppose it could be done with local type inference, though. SIM118 mentions acting differently based on whether it can statically know something to be a dict, so I assume that's something Ruff is already capable of.
The fix is thankfully already marked as unsafe for a different reason, so this isn't a huge problem. But it seems worth documenting this case as another reason for marking it as unsafe.
The text was updated successfully, but these errors were encountered:
This is sort of a false positive of the rule not a fix safety problem though.
Well, sure, but in general the only way to avoid false positives for this is to only flag it if you can statically determine that it's not a dict, right? But that would make the rule apply much more rarely, so the more pragmatic solution seems like keeping the fix as unsafe and avoiding flagging it if you can statically determine that it's a dict. Not sure if Ruff generally prefers correctness or more broadly applicable rules, though.
https://play.ruff.rs/4d78b865-9778-415b-9303-377a3fdff673
C416 suggests changing
d2
todict(d1)
, which is incorrect because this will just copyd1
.This seems like an intractable problem to solve in general because you'd have to know whether the thing being iterated over is a dict. In a case like this I suppose it could be done with local type inference, though. SIM118 mentions acting differently based on whether it can statically know something to be a dict, so I assume that's something Ruff is already capable of.
The fix is thankfully already marked as unsafe for a different reason, so this isn't a huge problem. But it seems worth documenting this case as another reason for marking it as unsafe.
The text was updated successfully, but these errors were encountered: