SQLAlchemy seems to give me a ton of errors on pylint that I can't resolve.
The first problem is that each table must be defined as a new class.
Example:
class Person(BASE):
"""Person Table Definition"""
__tablename__ = 'person'
id = Column(Integer, primary_key=True)
name = Column(String(30))
...causes these errors for each table I define:
W: 20, 0: Class has no __init__ method (no-init)
R: 20, 0: Too few public methods (0/2) (too-few-public-methods)
The second problem is using a global variable for the SQLAlchemy engine
and BASE
constructs. I'm not sure how I can refactor this code to make these variables not global, since the parameter BASE
must be passed into the table class definitions above.
BASE = sqlalchemy.ext.declarative.declarative_base()
global engine
...
def create_sqla_engine():
"""Create the SQLA engine"""
global engine
engine = create_engine('mysql+mysqlconnector://root:@127.0.0.1:3306/sqlalchemy_example')
I'm new to python but this seems ugly. pylint complains about it, too:
C: 51, 0: Invalid constant name "engine" (invalid-name)
Finally, pylint thinks I'm not using the imports that I am clearly using in this code.
W: 15, 0: Unused declarative_base imported from sqlalchemy.ext.declarative (unused-import)
W: 16, 0: Unused sessionmaker imported from sqlalchemy.orm (unused-import)
...why? Is pylint not compatible with python3? Should I be importing the modules I need within the methods they are used, instead of at the top of the file?