Skip to content

Commit

Permalink
Change 'type(foo) == bar' to 'isinstance(foo, bar)'
Browse files Browse the repository at this point in the history
  • Loading branch information
juancarlospaco committed Jan 15, 2015
1 parent edf201e commit 0000e3f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ before_install: sudo apt-get update -qq; pip install tox --use-mirrors --quiet

install: pip install fhurl>=0.1.7 gunicorn smarturls six Django>=1.3 dj-database-url --use-mirrors --quiet

before_script: rm --recursive --force --verbose *.pyc
before_script: rm --recursive --force --verbose *.py[cod]

script: tox

Expand All @@ -28,4 +28,3 @@ notifications:
on_failure: always

cache: apt

22 changes: 16 additions & 6 deletions importd/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,20 @@
"""ImportD django mini framework."""


__license__ = 'BSD'
__author__ = 'Amit Upadhyay'
__url__ = 'http://amitu.com/importd'
__docformat__ = 'html'


# stdlib imports
import copy
import inspect
import os
import sys
import traceback
from getpass import getuser
from platform import python_version

# 3rd party imports
import dj_database_url
Expand Down Expand Up @@ -46,7 +54,7 @@
COFFIN = False


if sys.version_info >= (3,):
if python_version().startswith('3'):
basestring = unicode = str # lint:ok
# coffin is not python 3 compatible library
COFFIN = False
Expand Down Expand Up @@ -438,12 +446,14 @@ def _configure_django(self, **kw):
kw['INSTALLED_APPS'] = installed

if "DEBUG" not in kw:
kw["DEBUG"] = True
kw["DEBUG"] = kw["TEMPLATE_DEBUG"] = True
if "APP_DIR" not in kw:
kw["APP_DIR"] = self.APP_DIR
if "SECRET_KEY" not in kw:
kw["SECRET_KEY"] = self.get_secret_key()

# admins and managers
+ if "ADMINS" not in kw:
+ kw["ADMINS"] = kw["MANAGERS"] = ((getuser(), ""), )
autoimport = kw.pop("autoimport", True)

kw["SETTINGS_MODULE"] = kw.get("SETTINGS_MODULE", "importd")
Expand Down Expand Up @@ -509,14 +519,14 @@ def __call__(self, *args, **kw):
if args:
if not hasattr(self, "_configured"):
self._configure_django(DEBUG=True)
if type(args[0]) == dict and len(args) == 2:
if isinstance(args[0], dict) and len(args) == 2:
for bp in self.blueprint_list:
self.apply_blueprint(bp)
return self.wsgi_application(*args)
if self._is_management_command(args[0]):
self._handle_management_command(*args, **kw)
return self
if type(args[0]) == list:
if isinstance(args[0], list):
self.update_urls(args[0])
return self
if isinstance(args[0], Callable):
Expand All @@ -526,7 +536,7 @@ def __call__(self, *args, **kw):
def ddecorator(candidate):
from django.forms import forms
# the following is unsafe
if type(candidate) == forms.DeclarativeFieldsMetaclass:
if isinstance(candidate, forms.DeclarativeFieldsMetaclass):
self.add_form(args[0], candidate, *args[1:], **kw)
return candidate
self.add_view(args[0], candidate, *args[1:], **kw)
Expand Down
3 changes: 3 additions & 0 deletions importd/urlconf.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# -*- coding: utf-8 -*-


"""ImportD import helper."""


try:
from django.conf.urls import patterns
except ImportError:
Expand Down

0 comments on commit 0000e3f

Please sign in to comment.