From: Mike Bayer Date: Fri, 4 Jan 2019 03:28:09 +0000 (-0500) Subject: Prep for flake8 refactoring X-Git-Tag: rel_1_3_0b2~48 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d229360a8d4071c2f150558897f37e13eb09f430;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git Prep for flake8 refactoring a few code changes ahead of time to handle some __all__ issues better. also include new flake8 rules, since the existing flake8 doesn't pass in any case. Change-Id: I1efdf75124ae7bcac719c22e505bb5b13db06c04 --- diff --git a/.gitignore b/.gitignore index 761785207e..eaf5c1c91a 100644 --- a/.gitignore +++ b/.gitignore @@ -20,4 +20,9 @@ sqlnet.log /mapping_setup.py /test.py /.cache/ +/.mypy_cache *.sw[o,p] +/test?.py +/test.py +/mapping_setup.py +*.rej \ No newline at end of file diff --git a/lib/sqlalchemy/orm/descriptor_props.py b/lib/sqlalchemy/orm/descriptor_props.py index 24a12193bc..fefd2d2a11 100644 --- a/lib/sqlalchemy/orm/descriptor_props.py +++ b/lib/sqlalchemy/orm/descriptor_props.py @@ -76,7 +76,7 @@ class DescriptorProperty(MapperProperty): mapper.class_manager.instrument_attribute(self.key, proxy_attr) -@util.langhelpers.dependency_for("sqlalchemy.orm.properties") +@util.langhelpers.dependency_for("sqlalchemy.orm.properties", add_to_all=True) class CompositeProperty(DescriptorProperty): """Defines a "composite" mapped attribute, representing a collection of columns as one attribute. @@ -465,7 +465,7 @@ class CompositeProperty(DescriptorProperty): return str(self.parent.class_.__name__) + "." + self.key -@util.langhelpers.dependency_for("sqlalchemy.orm.properties") +@util.langhelpers.dependency_for("sqlalchemy.orm.properties", add_to_all=True) class ConcreteInheritedProperty(DescriptorProperty): """A 'do nothing' :class:`.MapperProperty` that disables an attribute on a concrete subclass that is only present @@ -516,7 +516,7 @@ class ConcreteInheritedProperty(DescriptorProperty): self.descriptor = NoninheritedConcreteProp() -@util.langhelpers.dependency_for("sqlalchemy.orm.properties") +@util.langhelpers.dependency_for("sqlalchemy.orm.properties", add_to_all=True) class SynonymProperty(DescriptorProperty): def __init__(self, name, map_column=None, @@ -693,7 +693,7 @@ class SynonymProperty(DescriptorProperty): self.parent = parent -@util.langhelpers.dependency_for("sqlalchemy.orm.properties") +@util.langhelpers.dependency_for("sqlalchemy.orm.properties", add_to_all=True) class ComparableProperty(DescriptorProperty): """Instruments a Python property for use in query expressions.""" diff --git a/lib/sqlalchemy/orm/properties.py b/lib/sqlalchemy/orm/properties.py index 01ce7043a0..ca47fe7eaa 100644 --- a/lib/sqlalchemy/orm/properties.py +++ b/lib/sqlalchemy/orm/properties.py @@ -20,8 +20,7 @@ from .util import _orm_full_deannotate from .interfaces import PropComparator, StrategizedProperty -__all__ = ['ColumnProperty', 'CompositeProperty', 'SynonymProperty', - 'ComparableProperty', 'RelationshipProperty'] +__all__ = ['ColumnProperty'] @log.class_logger diff --git a/lib/sqlalchemy/util/langhelpers.py b/lib/sqlalchemy/util/langhelpers.py index 6a1db7a988..7e387f4f25 100644 --- a/lib/sqlalchemy/util/langhelpers.py +++ b/lib/sqlalchemy/util/langhelpers.py @@ -853,7 +853,7 @@ class MemoizedSlots(object): return self._fallback_getattr(key) -def dependency_for(modulename): +def dependency_for(modulename, add_to_all=False): def decorate(obj): # TODO: would be nice to improve on this import silliness, # unfortunately importlib doesn't work that great either @@ -862,6 +862,8 @@ def dependency_for(modulename): ".".join(tokens[0:-1]), globals(), locals(), [tokens[-1]]) mod = getattr(mod, tokens[-1]) setattr(mod, obj.__name__, obj) + if add_to_all and hasattr(mod, "__all__"): + mod.__all__.append(obj.__name__) return obj return decorate diff --git a/setup.cfg b/setup.cfg index d61babc673..ec6da6057f 100644 --- a/setup.cfg +++ b/setup.cfg @@ -18,6 +18,26 @@ python_files=test/*test_*.py sign = 1 identity = C4DAFEE1 +[flake8] +show-source = true +enable-extensions = G +# E203 is due to https://github.com/PyCQA/pycodestyle/issues/373 +# F841 is "variable assigned but never used". lots of these are in +# code examples, as well as in tests where sometimes they serve to keep +# an object in scope. It would be nice to have less of these but at the +# same time some are needed and some make code more readable +ignore = + A003, + D, + E203,E305,E711,E712,E721,E722,E741, + F841, + N801,N802,N806, + RST304,RST303,RST299,RST399, + W503,W504 +exclude = .venv,.git,.tox,dist,doc,*egg,build +import-order-style = google +application-import-names = sqlalchemy,test + [sqla_testing] requirement_cls=test.requirements:DefaultRequirements diff --git a/test/sql/test_types.py b/test/sql/test_types.py index 3fdc6169f2..b379ebdec0 100644 --- a/test/sql/test_types.py +++ b/test/sql/test_types.py @@ -16,8 +16,6 @@ from sqlalchemy.sql import visitors from sqlalchemy import inspection from sqlalchemy import exc, types, util, dialects from sqlalchemy.util import OrderedDict -for name in dialects.__all__: # noqa - __import__("sqlalchemy.dialects.%s" % name) from sqlalchemy.sql import operators, column, table, null from sqlalchemy.schema import CheckConstraint, AddConstraint from sqlalchemy.engine import default @@ -31,15 +29,15 @@ from sqlalchemy.testing import fixtures from sqlalchemy.testing import mock from sqlalchemy.sql import column import operator +import importlib class AdaptTest(fixtures.TestBase): def _all_dialect_modules(self): return [ - getattr(dialects, d) - for d in dialects.__all__ - if not d.startswith('_') + importlib.import_module("sqlalchemy.dialects.%s" % d) + for d in dialects.__all__ if not d.startswith("_") ] def _all_dialects(self): diff --git a/tox.ini b/tox.ini index bcdcf72d41..8e62884683 100644 --- a/tox.ini +++ b/tox.ini @@ -77,11 +77,14 @@ commands= {env:BASECOMMAND} {env:WORKERS} {env:SQLITE:} {env:POSTGRESQL:} {env:MYSQL:} {env:ORACLE:} {env:MSSQL:} {env:BACKENDONLY:} {env:IDENTS:} {env:NOMEMORY:} {env:COVERAGE:} {posargs} oracle,oracle6,oracle5,mssql: python reap_dbs.py db_idents.txt +# thanks to https://julien.danjou.info/the-best-flake8-extensions/ [testenv:pep8] -deps=flake8 -commands = python -m flake8 {posargs} - -[flake8] -show-source = True -ignore = E711,E712,E721,N806,D -exclude=.venv,.git,.tox,dist,doc,*egg,build +deps= + flake8 + flake8-import-order + flake8-builtins + flake8-docstrings + flake8-rst-docstrings + # used by flake8-rst-docstrings + pygments +commands = flake8 ./lib/ ./test/ ./examples/ setup.py