[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
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

Refactor: Replace '.func is' with 'isinstance()' for code quality #27339

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

Jatinbhardwaj-093
Copy link
@Jatinbhardwaj-093 Jatinbhardwaj-093 commented Dec 2, 2024

Fixes #24922

Brief description of what is fixed or changed

This PR resolves partial issue #24922 by improving the code quality from using ".func is" to "isinstance()" in tests.

Other comments

Changes Made:

  • Replaced .func is with isinstance() in relevant places in the codebase.

Release Notes

  • core
    • Replaced .func is with isinstance() in relevant places in the codebase.

@sympy-bot
Copy link
sympy-bot commented Dec 2, 2024

Hi, I am the SymPy bot. I'm here to help you write a release notes entry. Please read the guide on how to write release notes.

❌ There was an issue with the release notes. Please do not close this pull request; instead edit the description after reading the guide on how to write release notes.

Click here to see the pull request description that was parsed.
<!-- BEGIN RELEASE NOTES -->
Fixes #24922

Brief description of what is fixed or changed

This PR resolves partial issue https://github.com/sympy/sympy/issues/24922 by improving the code quality from using ".func is" to "isinstance()" in tests. 

Other comments

### Changes Made:
- Replaced `.func is` with `isinstance()` in relevant places in the codebase.

Release Notes

* core
   * Replaced `.func is` with `isinstance()` in relevant places in the codebase.
<!-- END RELEASE NOTES -->

AUTHORS Outdated Show resolved Hide resolved
@bjodah
Copy link
Member
bjodah commented Dec 3, 2024

These are actually semantic changes. Is this really a problem that needs fixing?

@Jatinbhardwaj-093
Copy link
Author

It was a code quality suggestion, also it maintain the uniformity in code base for further linting ease.

@oscarbenjamin
Copy link
Collaborator

There is a code quality check that prohibits writing .func is outside of the test suite:

message_func_is = "File contains '.func is': %s, line %s."

if func_is_re.search(line) and not test_file_re.search(fname):
assert False, message_func_is % (fname, idx + 1)

Of course we do need some tests for .func itself in the test suite rather but I don't think that applies to any of the cases here that can use isinstance.

@bjodah
Copy link
Member
bjodah commented Dec 3, 2024

You might be right that it is fine in this case. But making sweeping (semantic) changes across the tests code to please a code linter will always run the risk of introducing unintended changes to the test cases.

I personally would skip the entry in the release notes, since it's only affecting test files. (so the change is not user facing).

After carefully looking though all the changes I think I agree that this is ok. Fine to merge by me.

@oscarbenjamin
Copy link
Collaborator

But making sweeping (semantic) changes across the tests code to please a code linter will always run the risk of introducing unintended changes to the test cases.

I agree. Note in this case though that this is an "in-house" linter i.e. someone specifically implemented this rule for SymPy (without checking the history my guess would be Aaron).

One downside of using isinstance is that it won't work with SymEngine. On the other hand a typechecker requires these things to use isinstance e.g.:

p = Pow(x, 2)
assert isinstance(p, Pow) and p.exp == 2

I personally would skip the entry in the release notes

Agreed. There should be no release note here so it should have NO ENTRY instead.

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.

SymPy-specific linting rules
4 participants