1

I've set up my sqlalchemy table definitions in different modules all within a folder named schemas. For example:

ls -1 schemas/*.py $
schemas/__init__.py
schemas/base.py
schemas/reference.py
schemas/warehouse.py

However, to now use these definitions in a reflective manner by looking at the base._decl_class_registry or base.metadata I need to import the schema modules:

from schemas import base, reference, warehouse, reference

This then causes an unused import warning because I'm not directly referencing the table definitions within those modules and instead pulling out information from the base.

It seems that the issue is sqlalchemy registering these tables by simply doing an import.

I've looked through sqlalchemy documentation and can't quite find out if it's possible to do this registration in some more pythonic way.

Here's an example of what I'm effectively doing.

# removing this means reference is no longer registered to the metadata
from schemas import base, reference 
class SomeOtherClass:

    def printMetadata():
        print(base.Base.metadata)

Is there a better way to import these modules and tables?

I'm hoping to be able to do this without the flake8 warning to conform to my code styling.

SortingHat
  • 727
  • 3
  • 15
  • 30
  • You just need to tell the linter that what it thinks is a problem, isn’t a problem. https://stackoverflow.com/a/45346791/6560549 – SuperShoot Apr 12 '19 at 23:24
  • To me it seems unintuitive to have these imports that are not directly referenced within a file. So that's part of what I'm asking: is there a better way to do this? A more pythonic way? – SortingHat Apr 15 '19 at 16:52

0 Answers0