Fixed assorted flake8 errors.

This commit is contained in:
Tim Graham 2013-10-11 07:25:14 -04:00
parent 695bc0d191
commit b67ab75e82
38 changed files with 92 additions and 73 deletions

View File

@ -101,7 +101,7 @@ class GeoModelAdmin(ModelAdmin):
'num_zoom' : self.num_zoom,
'max_zoom' : self.max_zoom,
'min_zoom' : self.min_zoom,
'units' : self.units, #likely shoud get from object
'units' : self.units, # likely should get from object
'max_resolution' : self.max_resolution,
'max_extent' : self.max_extent,
'modifiable' : self.modifiable,

View File

@ -105,7 +105,7 @@ class SpatialReference(GDALBase):
doesn't exist. Can also take a tuple as a parameter, (target, child),
where child is the index of the attribute in the WKT. For example:
>>> wkt = 'GEOGCS["WGS 84", DATUM["WGS_1984, ... AUTHORITY["EPSG","4326"]]')
>>> wkt = 'GEOGCS["WGS 84", DATUM["WGS_1984, ... AUTHORITY["EPSG","4326"]]'
>>> srs = SpatialReference(wkt) # could also use 'WGS84', or 4326
>>> print(srs['GEOGCS'])
WGS 84

View File

@ -17,12 +17,14 @@ class Polygon(GEOSGeometry):
Examples of initialization, where shell, hole1, and hole2 are
valid LinearRing geometries:
>>> from django.contrib.gis.geos import LinearRing, Polygon
>>> shell = hole1 = hole2 = LinearRing()
>>> poly = Polygon(shell, hole1, hole2)
>>> poly = Polygon(shell, (hole1, hole2))
Example where a tuple parameters are used:
>>> # Example where a tuple parameters are used:
>>> poly = Polygon(((0, 0), (0, 10), (10, 10), (0, 10), (0, 0)),
((4, 4), (4, 6), (6, 6), (6, 4), (4, 4)))
... ((4, 4), (4, 6), (6, 6), (6, 4), (4, 4)))
"""
if not args:
raise TypeError('Must provide at least one LinearRing, or a tuple, to initialize a Polygon.')

View File

@ -16,11 +16,14 @@ class UserListA(ListMixin):
self._list = self._mytype(i_list)
super(UserListA, self).__init__(*args, **kwargs)
def __len__(self): return len(self._list)
def __len__(self):
return len(self._list)
def __str__(self): return str(self._list)
def __str__(self):
return str(self._list)
def __repr__(self): return repr(self._list)
def __repr__(self):
return repr(self._list)
def _set_list(self, length, items):
# this would work:

View File

@ -163,8 +163,10 @@ class LayerMapTest(TestCase):
# Passing in invalid ForeignKey mapping parameters -- must be a dictionary
# mapping for the model the ForeignKey points to.
bad_fk_map1 = copy(co_mapping); bad_fk_map1['state'] = 'name'
bad_fk_map2 = copy(co_mapping); bad_fk_map2['state'] = {'nombre' : 'State'}
bad_fk_map1 = copy(co_mapping)
bad_fk_map1['state'] = 'name'
bad_fk_map2 = copy(co_mapping)
bad_fk_map2['state'] = {'nombre' : 'State'}
self.assertRaises(TypeError, LayerMapping, County, co_shp, bad_fk_map1, transform=False)
self.assertRaises(LayerMapError, LayerMapping, County, co_shp, bad_fk_map2, transform=False)

View File

@ -163,7 +163,7 @@ class SpecializedFieldTest(SimpleTestCase):
self.assertFalse(invalid.is_valid())
self.assertTrue('Invalid geometry value' in str(invalid.errors))
for invalid in [geom for key, geom in self.geometries.items() if key!='point']:
for invalid in [geo for key, geo in self.geometries.items() if key!='point']:
self.assertFalse(PointForm(data={'p': invalid.wkt}).is_valid())
def test_multipointfield(self):
@ -176,7 +176,7 @@ class SpecializedFieldTest(SimpleTestCase):
self.assertMapWidget(form)
self.assertFalse(PointForm().is_valid())
for invalid in [geom for key, geom in self.geometries.items() if key!='multipoint']:
for invalid in [geo for key, geo in self.geometries.items() if key!='multipoint']:
self.assertFalse(PointForm(data={'p': invalid.wkt}).is_valid())
def test_linestringfield(self):
@ -189,7 +189,7 @@ class SpecializedFieldTest(SimpleTestCase):
self.assertMapWidget(form)
self.assertFalse(LineStringForm().is_valid())
for invalid in [geom for key, geom in self.geometries.items() if key!='linestring']:
for invalid in [geo for key, geo in self.geometries.items() if key!='linestring']:
self.assertFalse(LineStringForm(data={'p': invalid.wkt}).is_valid())
def test_multilinestringfield(self):
@ -202,7 +202,7 @@ class SpecializedFieldTest(SimpleTestCase):
self.assertMapWidget(form)
self.assertFalse(LineStringForm().is_valid())
for invalid in [geom for key, geom in self.geometries.items() if key!='multilinestring']:
for invalid in [geo for key, geo in self.geometries.items() if key!='multilinestring']:
self.assertFalse(LineStringForm(data={'p': invalid.wkt}).is_valid())
def test_polygonfield(self):
@ -215,7 +215,7 @@ class SpecializedFieldTest(SimpleTestCase):
self.assertMapWidget(form)
self.assertFalse(PolygonForm().is_valid())
for invalid in [geom for key, geom in self.geometries.items() if key!='polygon']:
for invalid in [geo for key, geo in self.geometries.items() if key!='polygon']:
self.assertFalse(PolygonForm(data={'p': invalid.wkt}).is_valid())
def test_multipolygonfield(self):
@ -228,7 +228,7 @@ class SpecializedFieldTest(SimpleTestCase):
self.assertMapWidget(form)
self.assertFalse(PolygonForm().is_valid())
for invalid in [geom for key, geom in self.geometries.items() if key!='multipolygon']:
for invalid in [geo for key, geo in self.geometries.items() if key!='multipolygon']:
self.assertFalse(PolygonForm(data={'p': invalid.wkt}).is_valid())
def test_geometrycollectionfield(self):
@ -241,7 +241,7 @@ class SpecializedFieldTest(SimpleTestCase):
self.assertMapWidget(form)
self.assertFalse(GeometryForm().is_valid())
for invalid in [geom for key, geom in self.geometries.items() if key!='geometrycollection']:
for invalid in [geo for key, geo in self.geometries.items() if key!='geometrycollection']:
self.assertFalse(GeometryForm(data={'g': invalid.wkt}).is_valid())
def test_osm_widget(self):

View File

@ -10,10 +10,11 @@ def precision_wkt(geom, prec):
integer or a string). If the precision is an integer, then the decimal
places of coordinates WKT will be truncated to that number:
>>> from django.contrib.gis.geos import Point
>>> pnt = Point(5, 23)
>>> pnt.wkt
'POINT (5.0000000000000000 23.0000000000000000)'
>>> precision(geom, 1)
>>> precision_wkt(pnt, 1)
'POINT (5.0 23.0)'
If the precision is a string, it must be valid Python format string

View File

@ -199,6 +199,8 @@ def load_handler(path, *args, **kwargs):
Given a path to a handler, return an instance of that handler.
E.g.::
>>> from django.http import HttpRequest
>>> request = HttpRequest()
>>> load_handler('django.core.files.uploadhandler.TemporaryFileUploadHandler', request)
<TemporaryFileUploadHandler object at 0x...>

View File

@ -164,7 +164,7 @@ class ModelBase(type):
# Basic setup for proxy models.
if is_proxy:
base = None
for parent in [cls for cls in parents if hasattr(cls, '_meta')]:
for parent in [kls for kls in parents if hasattr(kls, '_meta')]:
if parent._meta.abstract:
if parent._meta.fields:
raise TypeError("Abstract base class containing model fields not permitted for proxy model '%s'." % name)

View File

@ -142,11 +142,14 @@ class FileDescriptor(object):
The descriptor for the file attribute on the model instance. Returns a
FieldFile when accessed so you can do stuff like::
>>> from myapp.models import MyModel
>>> instance = MyModel.objects.get(pk=1)
>>> instance.file.size
Assigns a file object on assignment so you can do::
>>> instance.file = File(...)
>>> with open('/tmp/hello.world', 'r') as f:
... instance.file = File(f)
"""
def __init__(self, field):

View File

@ -117,7 +117,7 @@ def media_property(cls):
if definition:
extend = getattr(definition, 'extend', True)
if extend:
if extend == True:
if extend is True:
m = base
else:
m = Media()

View File

@ -60,4 +60,4 @@ def do_cache(parser, token):
return CacheNode(nodelist,
parser.compile_filter(tokens[1]),
tokens[2], # fragment_name can't be a variable.
[parser.compile_filter(token) for token in tokens[3:]])
[parser.compile_filter(t) for t in tokens[3:]])

View File

@ -28,7 +28,11 @@
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import os, sys, time, signal, traceback
import os
import signal
import sys
import time
import traceback
try:
from django.utils.six.moves import _thread as thread

View File

@ -1017,20 +1017,20 @@ class AggregationTests(TestCase):
tests aggregations with generic reverse relations
"""
b = Book.objects.get(name='Practical Django Projects')
ItemTag.objects.create(object_id=b.id, tag='intermediate',
content_type=ContentType.objects.get_for_model(b))
ItemTag.objects.create(object_id=b.id, tag='django',
content_type=ContentType.objects.get_for_model(b))
django_book = Book.objects.get(name='Practical Django Projects')
ItemTag.objects.create(object_id=django_book.id, tag='intermediate',
content_type=ContentType.objects.get_for_model(django_book))
ItemTag.objects.create(object_id=django_book.id, tag='django',
content_type=ContentType.objects.get_for_model(django_book))
# Assign a tag to model with same PK as the book above. If the JOIN
# used in aggregation doesn't have content type as part of the
# condition the annotation will also count the 'hi mom' tag for b.
wmpk = WithManualPK.objects.create(id=b.pk)
wmpk = WithManualPK.objects.create(id=django_book.pk)
ItemTag.objects.create(object_id=wmpk.id, tag='hi mom',
content_type=ContentType.objects.get_for_model(wmpk))
b = Book.objects.get(name__startswith='Paradigms of Artificial Intelligence')
ItemTag.objects.create(object_id=b.id, tag='intermediate',
content_type=ContentType.objects.get_for_model(b))
ai_book = Book.objects.get(name__startswith='Paradigms of Artificial Intelligence')
ItemTag.objects.create(object_id=ai_book.id, tag='intermediate',
content_type=ContentType.objects.get_for_model(ai_book))
self.assertEqual(Book.objects.aggregate(Count('tags')), {'tags__count': 3})
results = Book.objects.annotate(Count('tags')).order_by('-tags__count', 'name')

View File

@ -321,9 +321,9 @@ class GenericRelationTests(TestCase):
[t.created_by for t in TaggedItem.objects.all()])
def test_generic_relation(self):
b = Bookmark.objects.create(url='http://www.djangoproject.com/')
t1 = TaggedItem.objects.create(content_object=b, tag='django')
t2 = TaggedItem.objects.create(content_object=b, tag='python')
bookmark = Bookmark.objects.create(url='http://www.djangoproject.com/')
t1 = TaggedItem.objects.create(content_object=bookmark, tag='django')
t2 = TaggedItem.objects.create(content_object=bookmark, tag='python')
with self.assertNumQueries(2):
tags = [t.tag for b in Bookmark.objects.prefetch_related('tags')

View File

@ -1558,7 +1558,9 @@ class Queries5Tests(TestCase):
# extra()
qs = Ranking.objects.extra(select={'good': 'case when rank > 2 then 1 else 0 end'})
dicts = qs.values().order_by('id')
for d in dicts: del d['id']; del d['author_id']
for d in dicts:
del d['id']
del d['author_id']
self.assertEqual(
[sorted(d.items()) for d in dicts],
[[('good', 0), ('rank', 2)], [('good', 0), ('rank', 1)], [('good', 1), ('rank', 3)]]