Skip to content

Allow single-character uppercase names to be imported as CapWords - #251

Open
ychampion wants to merge 1 commit into
PyCQA:mainfrom
ychampion:fix/single-char-class-import-232
Open

ychampion wants to merge 1 commit into
PyCQA:mainfrom
ychampion:fix/single-char-class-import-232

Conversation

@ychampion

Copy link
Copy Markdown

Summary

Single-character uppercase identifiers (such as F or Q in
from django.db.models import F as Field) are valid CapWords class names
under PEP 8 (N801), but original_name.isupper() in
ImportAsCheck.visit_importfrom previously treated every uppercase identifier
exclusively as a constant and emitted false-positive N811 errors when
aliased to a CapWords name.

Changes

  1. In ImportAsCheck.visit_importfrom, allow single-character uppercase
    identifiers (len(original_name.strip('_')) == 1) to be imported with a
    CapWords alias (is_capwords(asname)) without triggering N811, while
    continuing to allow UPPER_CASE constant aliases and continuing to flag
    lowercase, mixedCase, or underscore-separated non-constant aliases (as
    well as multi-character constants imported as CapWords).
  2. Added regression test cases in testsuite/N81x.py.

Fixes #232

Single-character uppercase names (such as `F` or `Q`) are valid
CapWords class names under PEP 8. Allow aliasing them to CapWords
names without triggering N811 while still rejecting lowercase,
mixedCase, and underscore-separated non-constant aliases.

Fixes PyCQA#232
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.

N811 one char class name interpreter as const

1 participant