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

CI: Check and fix missing __init__.py with flake8-no-pep420 #1461

Merged
merged 8 commits into from
Apr 29, 2023

Conversation

intgr
Copy link
Collaborator

@intgr intgr commented Apr 27, 2023

Related issues

As suggested in #1460 (comment)

@adamchainz
Copy link
Contributor

Ha, I was just working on this, and adding .pyi support to the plugin: adamchainz/flake8-no-pep420#183

.pre-commit-config.yaml Outdated Show resolved Hide resolved
@intgr
Copy link
Collaborator Author

intgr commented Apr 27, 2023

ISTM tests isn't really a package, so I wouldn't add __init__.py there?

Also I renamed django-stubs/contrib/postgres/forms/jsonb.py to .pyi, this was a mistake clearly.

@intgr intgr force-pushed the add-flake8-no-pep420 branch from 99ce4b7 to 0409081 Compare April 27, 2023 16:11
@intgr intgr marked this pull request as ready for review April 27, 2023 16:11
Copy link
Member

@sobolevn sobolevn left a comment

Choose a reason for hiding this comment

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

The next step is to "steal" some checks from typeshed to catch .py file extensions 😆

See https://github.com/python/typeshed/blob/main/tests/check_consistent.py

@adamchainz you made so many awesome things, thank you 👍

@adamchainz
Copy link
Contributor

ISTM tests isn't really a package, so I wouldn't add __init__.py there?

Eh, I normally make my tests folder a package, but it's a bit different here since all the tests are yaml files.

Also I renamed django-stubs/contrib/postgres/forms/jsonb.py to .pyi, this was a mistake clearly.

Right you are!

@adamchainz you made so many awesome things, thank you 👍

Just solving problems I encounter, like yourself! 🫡

@intgr
Copy link
Collaborator Author

intgr commented Apr 28, 2023

Eh, I normally make my tests folder a package, but it's a bit different here since all the tests are yaml files.

Actually you're right. It makes sense that they're a packge, because a test module may want to import code from other tests modules.

@intgr intgr changed the title CI: Check missing __init__.py with flake8-no-pep420 CI: Check and fix missing __init__.py with flake8-no-pep420 Apr 28, 2023
@intgr
Copy link
Collaborator Author

intgr commented Apr 28, 2023

Hrm, adding __init__.py to tests causes errors in CI:

ImportError while importing test module '/home/runner/work/django-stubs/django-stubs/django_stubs_ext/tests/test_aliases.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
/opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/importlib/__init__.py:127: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
E   ModuleNotFoundError: No module named 'tests.test_aliases'

Looks like it causes tests and django_stubs_ext/tests to conflict.

Are there any solutions or should I just revert these __init__.py? I have no strong opinion on this.

@sobolevn
Copy link
Member

sobolevn commented Apr 28, 2023

I never use __init__.py in tests.

@intgr intgr merged commit e60f391 into typeddjango:master Apr 29, 2023
@intgr intgr deleted the add-flake8-no-pep420 branch April 29, 2023 17:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

4 participants