Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,12 @@ These error codes are emitted:
+---------+-----------------------------------------------------------------+
| _`N807` | function name should not start and end with '__' |
+---------+-----------------------------------------------------------------+
| _`N810` | package or module imported as non lowercase |
| | (`package and module names`_) |
+---------+-----------------------------------------------------------------+
| _`N811` | constant imported as non constant (`constants`_) |
+---------+-----------------------------------------------------------------+
| _`N812` | lowercase imported as non-lowercase |
| _`N812` | lowercase imported as non lowercase |
+---------+-----------------------------------------------------------------+
| _`N813` | camelcase imported as lowercase |
+---------+-----------------------------------------------------------------+
Expand All @@ -80,7 +83,7 @@ These error codes are emitted:
.. _function names: https://www.python.org/dev/peps/pep-0008/#function-and-variable-names
.. _function arguments: https://www.python.org/dev/peps/pep-0008/#function-and-method-arguments
.. _method names: https://www.python.org/dev/peps/pep-0008/#method-names-and-instance-variables

.. _package and module names: https://peps.python.org/pep-0008/#package-and-module-names
Options
-------

Expand Down
11 changes: 9 additions & 2 deletions src/pep8ext_naming.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,12 +385,21 @@ class ImportAsCheck(BaseASTCheck):
"""
Don't change the naming convention via an import
"""
N810 = "package or module '{name}' imported as non lowercase '{asname}'"
N811 = "constant '{name}' imported as non constant '{asname}'"
N812 = "lowercase '{name}' imported as non lowercase '{asname}'"
N813 = "camelcase '{name}' imported as lowercase '{asname}'"
N814 = "camelcase '{name}' imported as constant '{asname}'"
N817 = "camelcase '{name}' imported as acronym '{asname}'"

def visit_import(self, node, parents, ignore=None):
for name in node.names:
asname = name.asname
if not asname:
continue
if asname.lower() != asname:
yield self.err(node, 'N810', name=name.name, asname=asname)

def visit_importfrom(self, node, parents, ignore=None):
for name in node.names:
asname = name.asname
Expand All @@ -412,8 +421,6 @@ def visit_importfrom(self, node, parents, ignore=None):
else:
yield self.err(node, 'N814', **err_kwargs)

visit_import = visit_importfrom


class VariablesCheck(BaseASTCheck):
"""
Expand Down
18 changes: 18 additions & 0 deletions testsuite/N810.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#: N810:1:1
import os as OS
#: Okay
import os as myos
#: Okay
import good as good
#: Okay
import GOOD as good
#: N810:1:1
import good as BAD
#: N810:1:1
import good as Bad
#: Okay
import underscore as _
#: Okay
import good as γ
#: N810:1:1
import GOOD as Γ
14 changes: 3 additions & 11 deletions testsuite/N81x.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
#: N812:1:1
import os as OS
#: Okay
import os as myos
#: Okay
import good as good
#: Okay
import underscore as _
from mod import underscore as _
#: Okay
from mod import good as nice, NICE as GOOD, Camel as Memel
#: N811:1:1
from mod import GOOD as bad
#: N812:1:1
from mod import good as BAD
#: N812:1:1
from mod import good as Bad
#: N813:1:1
from mod import CamelCase as noncamle
Expand All @@ -19,12 +15,8 @@
#: N817:1:1
from mod import CamelCase as CC
#: Okay
import good as γ
#: Okay
from mod import good as γ
#: Okay
import GOOD as Γ
#: Okay
from mod import GOOD as Γ
#: Okay
from mod import GOOD as Γ1