Skip to content

Conversation

jhpalmieri
Copy link
Member

Fix the warnings coming from pycodestyle E721, "E721 do not compare types, for exact checks use is / is not, for instance checks use isinstance()".

Mostly I've made changes like type(x) == type(y) to type(x) is type(y), also adding some uses of isinstance. When I run pycodestyle --select=E721 --statistics src/sage/ I now get no hits.

📝 Checklist

  • The title is concise, informative, and self-explanatory.
  • The description explains in detail what this PR is about.
  • I have linked a relevant issue or discussion.
  • I have created tests covering the changes.
  • I have updated the documentation accordingly.

⌛ Dependencies

@jhpalmieri
Copy link
Member Author

Well, maybe I missed some of them: .pyx files in particular. I can add those on if people think this ticket is a good idea, or we can do them with a separate PR.

Copy link
Contributor

@mkoeppe mkoeppe left a comment

Choose a reason for hiding this comment

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

LGTM.

@jhpalmieri
Copy link
Member Author

Thanks! We can address more such changes with another PR.

@jhpalmieri jhpalmieri mentioned this pull request Aug 4, 2023
5 tasks
@vbraun
Copy link
Member

vbraun commented Aug 4, 2023

Merge conflict

@jhpalmieri
Copy link
Member Author

Rebased.

@github-actions
Copy link

github-actions bot commented Aug 6, 2023

Documentation preview for this PR (built with commit 3ceb31e; changes) is ready! 🎉

vbraun pushed a commit to vbraun/sage that referenced this pull request Aug 11, 2023
sagemathgh-36032: Fix pycodestyle warning E721
    
<!-- ^^^^^
Please provide a concise, informative and self-explanatory title.
Don't put issue numbers in there, do this in the PR body below.
For example, instead of "Fixes sagemath#1234" use "Introduce new method to
calculate 1+1"
-->

Fix the warnings coming from pycodestyle E721, "E721 do not compare
types, for exact checks use `is` / `is not`, for instance checks use
`isinstance()`".

<!-- Describe your changes here in detail -->

Mostly I've made changes like `type(x) == type(y)` to `type(x) is
type(y)`, also adding some uses of `isinstance`. When I run `pycodestyle
--select=E721 --statistics src/sage/` I now get no hits.

<!-- Why is this change required? What problem does it solve? -->
<!-- If this PR resolves an open issue, please link to it here. For
example "Fixes sagemath#12345". -->
<!-- If your change requires a documentation PR, please link it
appropriately. -->

### 📝 Checklist

<!-- Put an `x` in all the boxes that apply. -->
<!-- If your change requires a documentation PR, please link it
appropriately -->
<!-- If you're unsure about any of these, don't hesitate to ask. We're
here to help! -->
<!-- Feel free to remove irrelevant items. -->

- [X] The title is concise, informative, and self-explanatory.
- [X] The description explains in detail what this PR is about.
- [X] I have linked a relevant issue or discussion.
- [ ] I have created tests covering the changes.
- [ ] I have updated the documentation accordingly.

### ⌛ Dependencies

<!-- List all open PRs that this PR logically depends on
- sagemath#12345: short description why this is a dependency
- sagemath#34567: ...
-->

<!-- If you're unsure about any of these, don't hesitate to ask. We're
here to help! -->
    
URL: sagemath#36032
Reported by: John H. Palmieri
Reviewer(s): Matthias Köppe
vbraun pushed a commit to vbraun/sage that referenced this pull request Aug 12, 2023
sagemathgh-36036: Fix E721 warnings for .pyx files
    
Fix E721 warnings for .pyx files

<!-- ^^^^^
Please provide a concise, informative and self-explanatory title.
Don't put issue numbers in there, do this in the PR body below.
For example, instead of "Fixes sagemath#1234" use "Introduce new method to
calculate 1+1"
-->
<!-- Describe your changes here in detail -->

pycodestyle reports: "E721 do not compare types, for exact checks use
`is` / `is not`, for instance checks use `isinstance()`." So replace
`type(x) == str` with `isinstance(x, str)`, replace `type(x) != type(y)`
with `type(x) is not type(y)`, etc. This is a followup to sagemath#36032 which
dealt with .py files.

<!-- Why is this change required? What problem does it solve? -->
<!-- If this PR resolves an open issue, please link to it here. For
example "Fixes sagemath#12345". -->
<!-- If your change requires a documentation PR, please link it
appropriately. -->

### 📝 Checklist

<!-- Put an `x` in all the boxes that apply. -->
<!-- If your change requires a documentation PR, please link it
appropriately -->
<!-- If you're unsure about any of these, don't hesitate to ask. We're
here to help! -->
<!-- Feel free to remove irrelevant items. -->

- [X] The title is concise, informative, and self-explanatory.
- [X] The description explains in detail what this PR is about.
- [X] I have linked a relevant issue or discussion.
- [ ] I have created tests covering the changes.
- [ ] I have updated the documentation accordingly.

### ⌛ Dependencies

<!-- List all open PRs that this PR logically depends on
- sagemath#12345: short description why this is a dependency
- sagemath#34567: ...
-->

<!-- If you're unsure about any of these, don't hesitate to ask. We're
here to help! -->
    
URL: sagemath#36036
Reported by: John H. Palmieri
Reviewer(s): John H. Palmieri, Matthias Köppe
@vbraun vbraun merged commit 1039d66 into sagemath:develop Aug 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants