Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SIM904][False-positive] Accessing previous dict values #100

Closed
Skylion007 opened this issue Feb 14, 2022 · 3 comments · Fixed by #103
Closed

[SIM904][False-positive] Accessing previous dict values #100

Skylion007 opened this issue Feb 14, 2022 · 3 comments · Fixed by #103
Assignees
Labels
enhancement New feature or request

Comments

@Skylion007
Copy link
Contributor

Desired change

  • Rule(s): SIM986, SIM987
  • Adjustment: In which way should it/they be adjusted?

Explanation

  • The SIM904 check currently does not check if previous values were accessed in keys. This means new keys cannot access old keys since the dictionary is not yet constructed.

Why is the adjustment necessary / better?

Example

This is an example where the mentioned rule(s) would currently be suboptimal:

        perf = {"total_time": end_time - start_time}
        perf["frame_time"] = perf["total_time"] / total_frames
        perf["fps"] = 1.0 / perf["frame_time"]
        perf["time_per_step"] = time_per_step
        perf["avg_sim_step_time"] = total_sim_step_time / total_frames

or more simply:

        perf = {"a": 1}
        perf["b"] = perf["a"] / 10

Yes, in this case, it could be written by creating lots of additional variables to replace the references to previous values of "total_time" and "frame_time", but in more complicated dictionaries it seems like this rule could become more troublesome,

@Skylion007 Skylion007 added the enhancement New feature or request label Feb 14, 2022
@MartinThoma
Copy link
Owner

Good catch, I'll fix that tomorrow.

@MartinThoma
Copy link
Owner

Just in case you missed it : in order to still add new rules quickly and don't disturb users of flake8-simplify, I'll use SIM9 rules. If there are no more false positives for 6 months, I'll change the rule to something not beginning with "9". This way people can ignore the SIM9 rules in their CI and just try them once in a while.

@MartinThoma MartinThoma changed the title [Adjust Rule] SIM904 false positive (accessing previous dict values) [SIM904][False-positive] Accessing previous dict values Feb 16, 2022
@MartinThoma
Copy link
Owner

This looks very similar to #99 . I'll address both in the same PR/commit

MartinThoma added a commit that referenced this issue Feb 16, 2022
Bug fixes: #99 and #100
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants