summaryrefslogtreecommitdiff
path: root/examples/custom_attributes
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2023-02-28 11:05:48 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2023-02-28 11:50:54 -0500
commitda70478eb2eafe9c76b836217371e029c3c820e3 (patch)
tree96f7310c68fd659ab472832e45107095c70081f6 /examples/custom_attributes
parenta7f3dad6c93ab43a11521a2ecd240b5e023367fc (diff)
downloadsqlalchemy-da70478eb2eafe9c76b836217371e029c3c820e3.tar.gz
ensure single import per line
This adds the very small plugin flake8-import-single which will prevent us from having an import with more than one symbol on a line. Flake8 by itself prevents this pattern with E401: import collections, os, sys However does not do anything with this: from sqlalchemy import Column, text Both statements have the same issues generating merge artifacts as well as presenting a manual decision to be made. While zimports generally cleans up such imports at the top level, we don't enforce zimports / pre-commit use. the plugin finds the same issue for imports that are inside of test methods. We shouldn't usually have imports in test methods so most of them here are moved to be top level. The version is pinned at 0.1.5; the project seems to have no activity since 2019, however there are three 0.1.6dev releases on pypi which stopped in September 2019, they seem to be experiments with packaging. The source for 0.1.5 is extremely simple and only reveals one method to flake8 (the run() method). Change-Id: Icea894e43bad9c0b5d4feb5f49c6c666d6ea6aa1
Diffstat (limited to 'examples/custom_attributes')
-rw-r--r--examples/custom_attributes/active_column_defaults.py13
-rw-r--r--examples/custom_attributes/listen_for_events.py10
2 files changed, 14 insertions, 9 deletions
diff --git a/examples/custom_attributes/active_column_defaults.py b/examples/custom_attributes/active_column_defaults.py
index dea79ee95..d5322d331 100644
--- a/examples/custom_attributes/active_column_defaults.py
+++ b/examples/custom_attributes/active_column_defaults.py
@@ -5,7 +5,15 @@ when an un-set attribute is accessed.
"""
+import datetime
+
+from sqlalchemy import Column
+from sqlalchemy import create_engine
+from sqlalchemy import DateTime
from sqlalchemy import event
+from sqlalchemy import Integer
+from sqlalchemy.ext.declarative import declarative_base
+from sqlalchemy.orm import Session
def configure_listener(mapper, class_):
@@ -67,11 +75,6 @@ def default_listener(col_attr, default):
if __name__ == "__main__":
- from sqlalchemy import Column, Integer, DateTime, create_engine
- from sqlalchemy.orm import Session
- from sqlalchemy.ext.declarative import declarative_base
- import datetime
-
Base = declarative_base()
event.listen(Base, "mapper_configured", configure_listener, propagate=True)
diff --git a/examples/custom_attributes/listen_for_events.py b/examples/custom_attributes/listen_for_events.py
index b2d2b690b..a94a3dab2 100644
--- a/examples/custom_attributes/listen_for_events.py
+++ b/examples/custom_attributes/listen_for_events.py
@@ -3,7 +3,13 @@ and listen for change events.
"""
+from sqlalchemy import Column
from sqlalchemy import event
+from sqlalchemy import ForeignKey
+from sqlalchemy import Integer
+from sqlalchemy import String
+from sqlalchemy.ext.declarative import declarative_base
+from sqlalchemy.orm import relationship
def configure_listener(class_, key, inst):
@@ -23,10 +29,6 @@ def configure_listener(class_, key, inst):
if __name__ == "__main__":
- from sqlalchemy import Column, Integer, String, ForeignKey
- from sqlalchemy.orm import relationship
- from sqlalchemy.ext.declarative import declarative_base
-
class Base:
def receive_change_event(self, verb, key, value, oldvalue):
s = "Value '%s' %s on attribute '%s', " % (value, verb, key)