-
Notifications
You must be signed in to change notification settings - Fork 206
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
metaclasses and functions returning classes #5
Comments
So the snippet you posted happens within a function, right ? Something like this def function():
from sqlalchemy.orm import sessionmaker
Session = sessionmaker(bind=engine) Are you suggesting to disable the whole 'VariablesInFunctionCheck' ? I mean PEP-8 is clear regarding instance variables, but not about variables in functions. |
well, i suggest that functions have
so the following code should be allowed, but arbitrary names of course not. from . import MyMetaClass, DB_PATH
import sqlalchemy
ENGINE = sqlalchemy.create_engine(DB_PATH)
Session = sessionmaker(bind=ENGINE)
def commit_stuff():
MyClass = MyMetaClass()
my_object = MyClass()
my_session = Session()
my_session.add(my_object)
my_session.commit() |
So we currently have a special case for namedtuple. I wouldn't be adverse to eliminating that special case and allowing top-level variables to have all caps or "ClassNames" as you described them. I'm pretty sure it won't be easy though. |
I just tried adding FooBar = apps.get_model("foobars", "FooBar") Where I can add
|
Tools don't complain, they tell you information you asked them to give you
Except for the cases we've already caught and helped standardize for projects and the sudden lack of a computer telling someone they're violating the project/team's agreed upon convention.
No analysis of the AST will tell us this. Please don't spread misinformation.
Yep, let's depend on a language server or mypy to give us that information, otherwise let's rebuild the core of those projects to do it.
This might be workable but is as useful as a noqa - both of which are silencing a tool.
|
Thanks for your feedback. Just to be clear, |
python is a dynamic language. functions may return classes, and instantiating metaclasses also yields classes.
since we can’t know what a function returns,
VariablesInFunctionCheck
should not yield an error if a variable name matchesMIXEDCASE_REGEX
, e.g.:The text was updated successfully, but these errors were encountered: