python-trio / trio

Trio – a friendly Python library for async concurrency and I/O
https://trio.readthedocs.io
Other
6.12k stars 335 forks source link

Enable ruff `flake8-builtins` rule #2930

Closed CoolCat467 closed 8 months ago

CoolCat467 commented 8 months ago

This pull request enables ruff's flake8-builtins rule, sorts the enabled rules and ignored rules sections, and fixes or ignores a lot of newly generated "argument or variable is shadowing a python builtin" errors.

codecov[bot] commented 8 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Comparison is base (0204d04) 99.64% compared to head (67116bc) 99.64%.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #2930 +/- ## ======================================= Coverage 99.64% 99.64% ======================================= Files 116 116 Lines 17503 17503 Branches 3148 3148 ======================================= Hits 17441 17441 Misses 43 43 Partials 19 19 ``` | [Files](https://app.codecov.io/gh/python-trio/trio/pull/2930?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=python-trio) | Coverage Δ | | |---|---|---| | [src/trio/\_core/\_io\_kqueue.py](https://app.codecov.io/gh/python-trio/trio/pull/2930?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=python-trio#diff-c3JjL3RyaW8vX2NvcmUvX2lvX2txdWV1ZS5weQ==) | `87.20% <100.00%> (ø)` | | | [src/trio/\_core/\_tests/test\_asyncgen.py](https://app.codecov.io/gh/python-trio/trio/pull/2930?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=python-trio#diff-c3JjL3RyaW8vX2NvcmUvX3Rlc3RzL3Rlc3RfYXN5bmNnZW4ucHk=) | `100.00% <100.00%> (ø)` | | | [src/trio/\_highlevel\_open\_tcp\_listeners.py](https://app.codecov.io/gh/python-trio/trio/pull/2930?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=python-trio#diff-c3JjL3RyaW8vX2hpZ2hsZXZlbF9vcGVuX3RjcF9saXN0ZW5lcnMucHk=) | `100.00% <100.00%> (ø)` | | | [src/trio/\_socket.py](https://app.codecov.io/gh/python-trio/trio/pull/2930?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=python-trio#diff-c3JjL3RyaW8vX3NvY2tldC5weQ==) | `100.00% <100.00%> (ø)` | | | [src/trio/\_subprocess.py](https://app.codecov.io/gh/python-trio/trio/pull/2930?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=python-trio#diff-c3JjL3RyaW8vX3N1YnByb2Nlc3MucHk=) | `100.00% <100.00%> (ø)` | | | [...c/trio/\_tests/test\_highlevel\_open\_tcp\_listeners.py](https://app.codecov.io/gh/python-trio/trio/pull/2930?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=python-trio#diff-c3JjL3RyaW8vX3Rlc3RzL3Rlc3RfaGlnaGxldmVsX29wZW5fdGNwX2xpc3RlbmVycy5weQ==) | `100.00% <100.00%> (ø)` | | | [src/trio/\_tests/test\_highlevel\_open\_tcp\_stream.py](https://app.codecov.io/gh/python-trio/trio/pull/2930?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=python-trio#diff-c3JjL3RyaW8vX3Rlc3RzL3Rlc3RfaGlnaGxldmVsX29wZW5fdGNwX3N0cmVhbS5weQ==) | `100.00% <100.00%> (ø)` | | | [src/trio/\_tests/test\_socket.py](https://app.codecov.io/gh/python-trio/trio/pull/2930?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=python-trio#diff-c3JjL3RyaW8vX3Rlc3RzL3Rlc3Rfc29ja2V0LnB5) | `100.00% <100.00%> (ø)` | | | [src/trio/testing/\_fake\_net.py](https://app.codecov.io/gh/python-trio/trio/pull/2930?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=python-trio#diff-c3JjL3RyaW8vdGVzdGluZy9fZmFrZV9uZXQucHk=) | `100.00% <100.00%> (ø)` | |
Fuyukai commented 8 months ago

Why is this three separate PRs that will all conflict due to all three reformattting the pyproject.toml?

CoolCat467 commented 8 months ago

Because they are separate rules, and if they conflict I will deal with that.

CoolCat467 commented 8 months ago

The segfault in pypy-3.9 happened again: https://github.com/python-trio/trio/actions/runs/7607032357/job/20713702030#step:5:1186 For future reference, where should these be recorded?

A5rocks commented 8 months ago

Gah, well see the segfaults don't exactly provide much information... But I agree that it's annoying. At this point ig we might as well make an issue here (on trio) to track things cause upstream pytest hasn't been able to solve this yet.


Also, I don't really see the use of this rule. We have type checkers; I don't see the issue with this shadowing. Maybe others see issue though?

CoolCat467 commented 8 months ago

In all reality we might not need flake8-builtins, but I wanted to throw it out there because it's a part of best practice not to shadow builtins.

jakkdl commented 8 months ago

I'm in favor of not shadowing builtins in general, type checking might catch most errors it might lead to (only if the object is different though!) - but I can definitely see it causing confusion/lead to bugs/etc.