Skip to content

[BUG] Prevent domain names from triggering WPS347#3657

Open
webknjaz wants to merge 1 commit into
wemake-services:masterfrom
webknjaz:patch-2
Open

[BUG] Prevent domain names from triggering WPS347#3657
webknjaz wants to merge 1 commit into
wemake-services:masterfrom
webknjaz:patch-2

Conversation

@webknjaz
Copy link
Copy Markdown
Contributor

When having flake8-typing-as-t that enforces a pallets-originating convention of doing import t as t. I have it configured with the import t as _t enforcement mode. To follow the same convention with typing-only imports from other modules, I also import the collections.abc module similarly:

import typing as _t

if _t.TYPE_CHECKING:
    from collections import abc as _c

That from collections import abc as _c line incorrectly trips the WPS347 rule check claiming that it's vague.

I however correctly set the _c as a domain name as follows:

# .flake8

# flake8-typing-as-t
# TYT02:
typing-as-t-imported-name = _t

# wemake-python-styleguide
# WPS111:
# `_t` will be enforced by `flake8-typing-as-t`
allowed-domain-names =
  _t,
  _c,

This patch makes the check respect the allowed-domain-names setting thus preventing WPS from reporting a false-positive match.

This is a promptly checked change via a local site-packages modification but is coded in-browser without any additional validation or testing. Feel free to push additional tests into the branch.


Checklist

  • I have double checked that there are no unrelated changes in this pull request (old patches, accidental config files, etc)
  • I have created at least one test case for the changes I have made
  • I have updated the documentation for the changes I have made
  • I have added my changes to the CHANGELOG.md

When having `flake8-typing-as-t` that enforces a pallets-originating convention of doing `import t as t`. I have it configured with the `import t as _t` enforcement mode. To follow the same convention with typing-only imports from other modules, I also import the `collections.abc` module similarly:

```python
import typing as _t

if _t.TYPE_CHECKING:
    from collections import abc as _c
```

That `from collections import abc as _c` line incorrectly trips the WPS347 rule check claiming that it's vague.

I however correctly set the `_c` as a domain name as follows:
```ini
# .flake8

# flake8-typing-as-t
# TYT02:
typing-as-t-imported-name = _t

# wemake-python-styleguide
# WPS111:
# `_t` will be enforced by `flake8-typing-as-t`
allowed-domain-names =
  _t,
  _c,
```

This patch makes the check respect the `allowed-domain-names` setting thus preventing WPS from reporting a false-positive match.

This is a promptly checked change via a local `site-packages` modification but is coded in-browser without any additional validation or testing. Feel free to push additional tests into the branch.
@webknjaz webknjaz moved this to 🏌️🚗💨 Drive-bys 🪽🐦‍🔥🦸🫡🤝🤲🍀🍃 in 📅 Procrastinating in public 😵‍💫 May 29, 2026
Copy link
Copy Markdown
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.

Sounds like a good idea :)
Please, fix the CI.

@webknjaz
Copy link
Copy Markdown
Contributor Author

I marked it as a drive-by since it's not a priority.

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.

2 participants