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

Repo review bugbear #9505

Merged
merged 14 commits into from
Sep 19, 2024
Merged

Repo review bugbear #9505

merged 14 commits into from
Sep 19, 2024

Conversation

Armavica
Copy link
Contributor

Second pass on #8239 mainly addressing bugbear ruff lints.

  • Closes #xxxx
  • Tests added
  • User visible changes (including notable bug fixes) are documented in whats-new.rst
  • New functions/methods are listed in api.rst

@Armavica Armavica force-pushed the repo-checker-pyproject branch 2 times, most recently from 767a935 to 5116a3d Compare September 17, 2024 00:44
@Armavica Armavica marked this pull request as ready for review September 17, 2024 02:09
Copy link
Collaborator

@max-sixty max-sixty left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at about 1/3 of lines, it looks good — I did spot one potential issue with the chunk defaults; worth confirming all of those are correct

@@ -2528,7 +2532,7 @@ def _to_dense(self) -> Variable:

def chunk( # type: ignore[override]
self,
chunks: T_Chunks = {},
chunks: T_Chunks = None,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIRC these are intended to be different between {} and None (and the coercion below then doesn't let None through...)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

...though the tests pass, so maybe it's fine (either that or our tests aren't sufficient...)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, there was a couple of instances where a comment was explaining something like this, so I left these ones alone.

chunks: T_ChunksFreq = {}, # {} even though it's technically unsafe, is being used intentionally here (#4667)

chunks: T_ChunksFreq = {}, # {} even though it's technically unsafe, is being used intentionally here (#4667)

In the absence of such comment (like here) I replaced the default with None, but I could also revert these places and add a comment if it was missing.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes that would be great.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dcherian to confirm, you would like this:

I could also revert these places and add a comment if it was missing.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

^ yes.

@@ -330,11 +330,13 @@ def test_parents(self):
def test_lineage(self):
_, leaf_f = create_test_tree()
expected = ["f", "e", "b", "a"]
assert [node.name for node in leaf_f.lineage] == expected
with pytest.warns(DeprecationWarning):
assert [node.name for node in leaf_f.lineage] == expected
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

@@ -72,7 +73,9 @@ def backends_dict_from_pkg(
backend = entrypoint.load()
backend_entrypoints[name] = backend
except Exception as ex:
warnings.warn(f"Engine {name!r} loading failed:\n{ex}", RuntimeWarning)
warnings.warn(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be better to replace all of these with utils.emit_user_level_warning

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(I also think it's fine to do this in another PR, though defer to @dcherian)

We could also add a regex lint in pre-commit that we don't use warnings.warn, we only use utils.emit_level_warning. Here's an example of this from another repo: https://github.com/PRQL/prql/blob/main/.pre-commit-config.yaml#L64-L71

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also think it's fine to do this in another PR,

yes fine by me!

@@ -137,7 +139,7 @@ def dimension_names(

def dimension_sizes(
*,
dim_names: st.SearchStrategy[Hashable] = names(),
dim_names: st.SearchStrategy[Hashable] | None = None,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is unnecessary IIUC, the strategies are immutable.

Copy link
Collaborator

@max-sixty max-sixty left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot!

@max-sixty max-sixty merged commit 7750c00 into pydata:main Sep 19, 2024
28 checks passed
hollymandel pushed a commit to hollymandel/xarray that referenced this pull request Sep 23, 2024
* Use ignore instead of extend-ignore for ruff

* Fix B028 no explicit stacklevel in warnings.warn

* Fix B006, B007 and B011 (auto-fixes)

* B006: mutable argument default
* B007: unused loop control variable
* B011: assert false

* Fix the remaining B006 and B007 manually

* Fix B015: pointless comparisons

* Fix B017: pytest.raises(Exception)

* Fix B023: function definition does not bind loop variable

* Fix B005: strip with multicharacter strings

* Fix B020: loop control variable overrides iterable

* Fix B008: no function call in argument defaults

* Fix B018: useless expression

* Fix B904: raise from within except

* Finally enable ruff bugbear lints

* Fix readthedocs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants