Skip to content
This repository has been archived by the owner on Jan 8, 2019. It is now read-only.

Commit

Permalink
Fixed "redefinition of unused 'foo' from line X" pyflakes warnings.
Browse files Browse the repository at this point in the history
  • Loading branch information
timgraham committed Oct 10, 2013
1 parent cec11a3 commit adedc31
Show file tree
Hide file tree
Showing 12 changed files with 27 additions and 34 deletions.
1 change: 0 additions & 1 deletion django/contrib/auth/tests/test_basic.py
Expand Up @@ -23,7 +23,6 @@
def user_model_swapped(**kwargs):
if kwargs['setting'] == 'AUTH_USER_MODEL':
from django.db.models.manager import ensure_default_manager
from django.contrib.auth.models import User
# Reset User manager
setattr(User, 'objects', User._default_manager)
ensure_default_manager(User)
Expand Down
2 changes: 1 addition & 1 deletion django/contrib/gis/geos/prototypes/__init__.py
Expand Up @@ -24,7 +24,7 @@
from django.contrib.gis.geos.prototypes.predicates import (geos_hasz, geos_isempty,
geos_isring, geos_issimple, geos_isvalid, geos_contains, geos_crosses,
geos_disjoint, geos_equals, geos_equalsexact, geos_intersects,
geos_intersects, geos_overlaps, geos_relatepattern, geos_touches, geos_within)
geos_overlaps, geos_relatepattern, geos_touches, geos_within)

# Topology routines
from django.contrib.gis.geos.prototypes.topology import *
1 change: 0 additions & 1 deletion django/contrib/sitemaps/__init__.py
Expand Up @@ -30,7 +30,6 @@ def ping_google(sitemap_url=None, ping_url=PING_URL):
if sitemap_url is None:
raise SitemapNotFound("You didn't provide a sitemap_url, and the sitemap URL couldn't be auto-detected.")

from django.contrib.sites.models import Site
current_site = Site.objects.get_current()
url = "http://%s%s" % (current_site.domain, sitemap_url)
params = urlencode({'sitemap':url})
Expand Down
1 change: 0 additions & 1 deletion django/db/backends/mysql/base.py
Expand Up @@ -43,7 +43,6 @@
from django.db.backends.mysql.validation import DatabaseValidation
from django.utils.encoding import force_str, force_text
from django.db.backends.mysql.schema import DatabaseSchemaEditor
from django.utils.encoding import force_str
from django.utils.functional import cached_property
from django.utils.safestring import SafeBytes, SafeText
from django.utils import six
Expand Down
6 changes: 3 additions & 3 deletions django/db/migrations/state.py
Expand Up @@ -53,11 +53,11 @@ def render(self):
@classmethod
def from_app_cache(cls, app_cache):
"Takes in an AppCache and returns a ProjectState matching it"
models = {}
app_models = {}
for model in app_cache.get_models():
model_state = ModelState.from_model(model)
models[(model_state.app_label, model_state.name.lower())] = model_state
return cls(models)
app_models[(model_state.app_label, model_state.name.lower())] = model_state
return cls(app_models)

def __eq__(self, other):
if set(self.models.keys()) != set(other.models.keys()):
Expand Down
2 changes: 1 addition & 1 deletion django/db/models/base.py
Expand Up @@ -276,7 +276,7 @@ def __new__(cls, name, bases, attrs):
def copy_managers(cls, base_managers):
# This is in-place sorting of an Options attribute, but that's fine.
base_managers.sort()
for _, mgr_name, manager in base_managers:
for _, mgr_name, manager in base_managers: # NOQA (redefinition of _)
val = getattr(cls, mgr_name, None)
if not val or val is manager:
new_manager = manager._copy_to_model(cls)
Expand Down
5 changes: 0 additions & 5 deletions tests/admin_views/admin.py
Expand Up @@ -567,11 +567,6 @@ class AlbumAdmin(admin.ModelAdmin):
list_filter = ['title']


class WorkHourAdmin(admin.ModelAdmin):
list_display = ('datum', 'employee')
list_filter = ('employee',)


class PrePopulatedPostLargeSlugAdmin(admin.ModelAdmin):
prepopulated_fields = {
'slug' : ('title',)
Expand Down
2 changes: 1 addition & 1 deletion tests/base/models.py
Expand Up @@ -20,6 +20,6 @@ class MyModel(six.with_metaclass(CustomBaseModel, models.Model)):
# still does not fail to create the model.

if six.PY2:
class MyModel(models.Model):
class MyPython2Model(models.Model):
"""Model subclass with a custom base using __metaclass__."""
__metaclass__ = CustomBaseModel
2 changes: 1 addition & 1 deletion tests/forms_tests/tests/test_media.py
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
from django.forms import TextInput, Media, TextInput, CharField, Form, MultiWidget
from django.forms import Media, TextInput, CharField, Form, MultiWidget
from django.template import Template, Context
from django.test import TestCase
from django.test.utils import override_settings
Expand Down
3 changes: 1 addition & 2 deletions tests/m2m_and_m2o/tests.py
Expand Up @@ -74,7 +74,7 @@ def test_m2m_and_m2o(self):
lambda i: i.num
)

class RelatedObjectTests(TestCase):
class RelatedObjectUnicodeTests(TestCase):
def test_m2m_with_unicode_reference(self):
"""
Regression test for #6045: references to other models can be unicode
Expand All @@ -85,4 +85,3 @@ def test_m2m_with_unicode_reference(self):
m2.others.add(m1) # used to cause an error (see ticket #6045)
m2.save()
list(m2.others.all()) # Force retrieval.

24 changes: 13 additions & 11 deletions tests/mail/tests.py
Expand Up @@ -2,7 +2,7 @@
from __future__ import unicode_literals

import asyncore
import email
from email import message_from_file, message_from_string
from email.mime.text import MIMEText
import os
import shutil
Expand All @@ -24,6 +24,11 @@
from django.utils.six import PY3, StringIO, string_types
from django.utils.translation import ugettext_lazy

if PY3:
from email.utils import parseaddr
else:
from email.Utils import parseaddr


class HeadersCheckMixin(object):

Expand Down Expand Up @@ -244,7 +249,7 @@ def test_attachments(self):
msg.attach_alternative(html_content, "text/html")
msg.attach("an attachment.pdf", b"%PDF-1.4.%...", mimetype="application/pdf")
msg_str = msg.message().as_string()
message = email.message_from_string(msg_str)
message = message_from_string(msg_str)
self.assertTrue(message.is_multipart())
self.assertEqual(message.get_content_type(), 'multipart/mixed')
self.assertEqual(message.get_default_type(), 'text/plain')
Expand All @@ -261,7 +266,7 @@ def test_non_ascii_attachment_filename(self):
# Unicode in file name
msg.attach("une pièce jointe.pdf", b"%PDF-1.4.%...", mimetype="application/pdf")
msg_str = msg.message().as_string()
message = email.message_from_string(msg_str)
message = message_from_string(msg_str)
payload = message.get_payload()
self.assertEqual(payload[1].get_filename(), 'une pièce jointe.pdf')

Expand Down Expand Up @@ -689,7 +694,7 @@ def get_mailbox_content(self):
for filename in os.listdir(self.tmp_dir):
with open(os.path.join(self.tmp_dir, filename), 'r') as fp:
session = force_text(fp.read()).split('\n' + ('-' * 79) + '\n')
messages.extend(email.message_from_string(force_str(m)) for m in session if m)
messages.extend(message_from_string(force_str(m)) for m in session if m)
return messages

def test_file_sessions(self):
Expand All @@ -700,7 +705,7 @@ def test_file_sessions(self):

self.assertEqual(len(os.listdir(self.tmp_dir)), 1)
with open(os.path.join(self.tmp_dir, os.listdir(self.tmp_dir)[0])) as fp:
message = email.message_from_file(fp)
message = message_from_file(fp)
self.assertEqual(message.get_content_type(), 'text/plain')
self.assertEqual(message.get('subject'), 'Subject')
self.assertEqual(message.get('from'), 'from@example.com')
Expand Down Expand Up @@ -742,7 +747,7 @@ def flush_mailbox(self):

def get_mailbox_content(self):
messages = force_text(self.stream.getvalue()).split('\n' + ('-' * 79) + '\n')
return [email.message_from_string(force_str(m)) for m in messages if m]
return [message_from_string(force_str(m)) for m in messages if m]

def test_console_stream_kwarg(self):
"""
Expand Down Expand Up @@ -788,11 +793,8 @@ def __init__(self, *args, **kwargs):
self.sink_lock = threading.Lock()

def process_message(self, peer, mailfrom, rcpttos, data):
m = email.message_from_string(data)
if PY3:
maddr = email.utils.parseaddr(m.get('from'))[1]
else:
maddr = email.Utils.parseaddr(m.get('from'))[1]
m = message_from_string(data)
maddr = parseaddr(m.get('from'))[1]
if mailfrom != maddr:
return "553 '%s' != '%s'" % (mailfrom, maddr)
with self.sink_lock:
Expand Down
12 changes: 6 additions & 6 deletions tests/multiple_database/tests.py
Expand Up @@ -928,21 +928,21 @@ class ConnectionRouterTestCase(TestCase):
'multiple_database.tests.TestRouter',
'multiple_database.tests.WriteRouter'])
def test_router_init_default(self):
router = ConnectionRouter()
self.assertListEqual([r.__class__.__name__ for r in router.routers],
connection_router = ConnectionRouter()
self.assertListEqual([r.__class__.__name__ for r in connection_router.routers],
['TestRouter', 'WriteRouter'])

def test_router_init_arg(self):
router = ConnectionRouter([
connection_router = ConnectionRouter([
'multiple_database.tests.TestRouter',
'multiple_database.tests.WriteRouter'
])
self.assertListEqual([r.__class__.__name__ for r in router.routers],
self.assertListEqual([r.__class__.__name__ for r in connection_router.routers],
['TestRouter', 'WriteRouter'])

# Init with instances instead of strings
router = ConnectionRouter([TestRouter(), WriteRouter()])
self.assertListEqual([r.__class__.__name__ for r in router.routers],
connection_router = ConnectionRouter([TestRouter(), WriteRouter()])
self.assertListEqual([r.__class__.__name__ for r in connection_router.routers],
['TestRouter', 'WriteRouter'])


Expand Down

0 comments on commit adedc31

Please sign in to comment.