Skip to content

Fix the failure to lint modules contained under an identically named directory #7114

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

Merged
merged 3 commits into from
Aug 3, 2022

Conversation

jacobtylerwalls
Copy link
Member

@jacobtylerwalls jacobtylerwalls commented Jul 3, 2022

Type of Changes

Type
βœ“ πŸ› Bug fix

Description

Fixes #4444: modules contained under an identically named directory weren't linted (failed with parse-error).

Notes

This PR causes a test failure in TestImportsChecker.test_relative_beyond_top_level_two, but that test uses epylint to excute pylint (!) which does additional manipulation of cwd, so I don't think it's correct.

Notice that linting the package in the test fails using regular pylint, but the failure is now more accurate on this branch:

main

$ pylint tests/regrtest_data/beyond_top_two
************* Module beyond_top_two
tests/regrtest_data/beyond_top_two/__init__.py:1:0: F0010: error while code parsing: Unable to load file tests/regrtest_data/beyond_top_two/__init__.py:
[Errno 2] No such file or directory: 'tests/regrtest_data/beyond_top_two/__init__.py' (parse-error)

PR

$ pylint tests/regrtest_data/beyond_top_two
************* Module tests/regrtest_data/beyond_top_two
tests/regrtest_data/beyond_top_two:1:0: F0001: No module named tests/regrtest_data/beyond_top_two (fatal)

@github-actions

This comment has been minimized.

@jacobtylerwalls

This comment was marked as outdated.

@jacobtylerwalls jacobtylerwalls changed the title [WIP] Fix #4444 Fix failure to lint packages containing identically named modules Jul 17, 2022
@github-actions

This comment has been minimized.

It uses epylint to run these tests, but since epylint manipulates cwd, that confounds what is under test
@jacobtylerwalls jacobtylerwalls changed the title Fix failure to lint packages containing identically named modules Fix the failure to lint modules contained under an identically named directory Jul 31, 2022
@jacobtylerwalls jacobtylerwalls marked this pull request as ready for review July 31, 2022 20:38
@coveralls
Copy link

Pull Request Test Coverage Report for Build 2770829476

  • 2 of 2 (100.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.006%) to 95.251%

Totals Coverage Status
Change from base Build 2770792790: 0.006%
Covered Lines: 16829
Relevant Lines: 17668

πŸ’› - Coveralls

Copy link
Member

@Pierre-Sassoulas Pierre-Sassoulas left a comment

Choose a reason for hiding this comment

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

Looks pretty good already, I have a question regarding the xfailed test.

@@ -103,9 +105,7 @@ def expand_modules(
)
if filepath is None:
continue
except (ImportError, SyntaxError) as ex:
# The SyntaxError is a Python bug and should be
# removed once we move away from imp.find_module: https://bugs.python.org/issue10588
Copy link
Member

Choose a reason for hiding this comment

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

πŸ‘

@@ -40,6 +41,9 @@ def test_relative_beyond_top_level(self) -> None:
self.checker.visit_importfrom(module.body[2].body[0])

@staticmethod
@pytest.mark.xfail(
reason="epylint manipulates cwd; these tests should not be using epylint"
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't we fix it or remove it ? What's the benefit of keeping xfailed tests ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I just didn't want to block this PR on resolving that. All of the tests in that file probably shouldn't be using epylint. Would you like me to open an issue?

Copy link
Member

Choose a reason for hiding this comment

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

Yeah let's open an issue, I'm not sure emacs is used a lot so it's probably not worth a fix, no one read the emacs documentation at least.

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

Thank you !

with tempdir():
create_files(["identical/identical.py"])
with open("identical/identical.py", "w", encoding="utf-8") as f:
f.write("import imp")
Copy link
Member

Choose a reason for hiding this comment

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

I wonder where the idea for this example came from πŸ˜„

@github-actions
Copy link
Contributor

πŸ€– Effect of this PR on checked open source code: πŸ€–

Effect on django:
The following messages are no longer emitted:

  1. super-init-not-called:
    init method from base class 'UploadFileException' is not called
    https://github.com/django/django/blob/main/django/core/files/uploadhandler.py#L36
  2. super-init-not-called:
    init method from base class 'Exception' is not called
    https://github.com/django/django/blob/main/django/core/serializers/base.py#L66
  3. super-init-not-called:
    init method from base class 'TextIOBase' is not called
    https://github.com/django/django/blob/main/django/core/management/base.py#L150
  4. super-init-not-called:
    init method from base class 'Exception' is not called
    https://github.com/django/django/blob/main/django/middleware/csrf.py#L132
  5. super-init-not-called:
    init method from base class 'Exception' is not called
    https://github.com/django/django/blob/main/django/middleware/csrf.py#L167
  6. super-init-not-called:
    init method from base class 'Exception' is not called
    https://github.com/django/django/blob/main/django/template/base.py#L102
  7. super-init-not-called:
    init method from base class 'LookupError' is not called
    https://github.com/django/django/blob/main/django/db/migrations/exceptions.py#L43
  8. super-init-not-called:
    init method from base class 'Exception' is not called
    https://github.com/django/django/blob/main/django/db/models/sql/datastructures.py#L15
  9. super-init-not-called:
    init method from base class 'str' is not called
    https://github.com/django/django/blob/main/django/conf/__init__.py#L52

Effect on flask:
The following messages are no longer emitted:

  1. super-init-not-called:
    init method from base class 'KeyError' is not called
    https://github.com/pallets/flask/blob/main/src/flask/debughelpers.py#L19
  2. super-init-not-called:
    init method from base class 'AssertionError' is not called
    https://github.com/pallets/flask/blob/main/src/flask/debughelpers.py#L19

Effect on pandas:
The following messages are no longer emitted:

  1. super-init-not-called:
    init method from base class 'BaseBlockManager' is not called
    https://github.com/pandas-dev/pandas/blob/main/pandas/core/internals/managers.py#L888
  2. super-init-not-called:
    init method from base class 'BaseBlockManager' is not called
    https://github.com/pandas-dev/pandas/blob/main/pandas/core/internals/managers.py#L1694
  3. super-init-not-called:
    init method from base class 'BaseArrayManager' is not called
    https://github.com/pandas-dev/pandas/blob/main/pandas/core/internals/array_manager.py#L712
  4. super-init-not-called:
    init method from base class 'BaseArrayManager' is not called
    https://github.com/pandas-dev/pandas/blob/main/pandas/core/internals/array_manager.py#L1201
  5. super-init-not-called:
    init method from base class 'set' is not called
    https://github.com/pandas-dev/pandas/blob/main/pandas/tests/frame/methods/test_set_index.py#L676
  6. super-init-not-called:
    init method from base class 'NotImplementedError' is not called
    https://github.com/pandas-dev/pandas/blob/main/pandas/errors/__init__.py#L188
  7. super-init-not-called:
    init method from base class 'dict' is not called
    https://github.com/pandas-dev/pandas/blob/main/pandas/plotting/_misc.py#L558

Effect on psycopg:
The following messages are no longer emitted:

  1. super-init-not-called:
    init method from base class 'Exception' is not called
    https://github.com/psycopg/psycopg/blob/master/psycopg/psycopg/transaction.py#L40

Effect on pytest:
The following messages are no longer emitted:

  1. super-init-not-called:
    init method from base class 'LookupError' is not called
    https://github.com/pytest-dev/pytest/blob/main/src/_pytest/fixtures.py#L792
  2. super-init-not-called:
    init method from base class 'Exception' is not called
    https://github.com/pytest-dev/pytest/blob/main/src/_pytest/mark/expression.py#L61
  3. super-init-not-called:
    init method from base class 'Exception' is not called
    https://github.com/pytest-dev/pytest/blob/main/src/_pytest/config/argparsing.py#L207

Effect on sentry:
The following messages are no longer emitted:

  1. super-init-not-called:
    init method from base class 'InvalidRequest' is not called
    https://github.com/getsentry/sentry/blob/master/src/sentry/exceptions.py#L17
  2. super-init-not-called:
    init method from base class 'Exception' is not called
    https://github.com/getsentry/sentry/blob/master/src/sentry/coreapi.py#L24
  3. super-init-not-called:
    init method from base class 'Exception' is not called
    https://github.com/getsentry/sentry/blob/master/src/sentry/incidents/logic.py#L850
  4. super-init-not-called:
    init method from base class 'Exception' is not called
    https://github.com/getsentry/sentry/blob/master/src/sentry/api/client.py#L11
  5. super-init-not-called:
    init method from base class 'NodeStorage' is not called
    https://github.com/getsentry/sentry/blob/master/src/sentry/nodestore/bigtable/backend.py#L33
  6. super-init-not-called:
    init method from base class '_local' is not called
    https://github.com/getsentry/sentry/blob/master/src/sentry/metrics/base.py#L10
  7. super-init-not-called:
    init method from base class '_local' is not called
    https://github.com/getsentry/sentry/blob/master/src/sentry/cache/base.py#L22
  8. super-init-not-called:
    init method from base class 'Exception' is not called
    https://github.com/getsentry/sentry/blob/master/src/sentry/tasks/symbolication.py#L43
  9. super-init-not-called:
    init method from base class 'Exception' is not called
    https://github.com/getsentry/sentry/blob/master/src/sentry/utils/sms.py#L13
  10. super-init-not-called:
    init method from base class 'Exception' is not called
    https://github.com/getsentry/sentry/blob/master/src/sentry/utils/auth.py#L79
  11. super-init-not-called:
    init method from base class '_local' is not called
    https://github.com/getsentry/sentry/blob/master/src/sentry/utils/services.py#L251
  12. super-init-not-called:
    init method from base class '_local' is not called
    https://github.com/getsentry/sentry/blob/master/src/sentry/utils/performance/sqlquerycount.py#L12

This comment was generated for commit 759d35e

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.

Linting fails if module contains module of the same name
3 participants