rules/python/import-alias.md
Renaming a symbol or module on import gives one definition two names across files, so a plain-text search for the alias never lands on its definition. Import the real name, or import the module and qualify the symbol.
diff
| 1 | -from billing.invoices import Invoice as Bill |
| 2 | - |
| 3 | -invoice = Bill(total=42) |
| 4 | +from billing.invoices import Invoice |
| 5 | + |
| 6 | +invoice = Invoice(total=42) |
What the rule reports
The rule reports three forms of import aliasing:
from ... import X as YwhereXandYdiffer, outside standard scientific ecosystem submodule aliases such asfrom plotly import graph_objects as goorfrom hypothesis import strategies as st.import X as YwhereXandYdiffer, outside the standard ecosystem module aliases (pandas as pd,polars as pl,polars.selectors as cs,scipy as sp,matplotlib as mpl,matplotlib.pyplot as plt,seaborn as sns,plotly.express as px,plotly.graph_objects as go,plotly.io as pio,cvxpy as cp,lightgbm as lgb,xgboost as xgb,pymc as pm,arviz as az,pytensor.tensor as pt,statsmodels.api as sm,statsmodels.formula.api as smf,category_encoders as ce,hypothesis.strategies as st,networkx as nx,sqlalchemy as sa,datetime as dt,xml.etree.ElementTree as ET,tensorflow as tf,torch.nn as nn,torch.nn.functional as F, andjax.numpy as jnp). Non-standardnumpyaliases are handled bynumpy/numpy-import-alias.- Same-name
X as Xre-export aliases outside__init__.py.
The rule leaves alone the cases in the list:
- Standard ecosystem aliases listed above, plus
from array_api_compat import numpy as xp. - Same-name
from .client import Client as Clientre-exports inside__init__.py, which PEP 484 type checkers use to mark a package's public exports.
How to fix it
xpd has no automatic fix, so make the change by hand.
Import the symbol under its real name. When two modules define the same name, import both modules (import billing.config and import shipping.config) and qualify each reference with its module name, or rename the colliding symbol in your own codebase.