Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Improved 'inspectdb' handling of Python keywords from [2271] to use t…

…he 'keywords' module rather than hard-coding the list of keywords.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@2272 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit c59901a4679faff44844bffdf877dc859fd1351a 1 parent 9423c4e
Adrian Holovaty authored February 04, 2006

Showing 1 changed file with 2 additions and 3 deletions. Show diff stats Hide diff stats

  1. 5  django/core/management.py
5  django/core/management.py
@@ -562,13 +562,12 @@ def inspectdb(db_name):
562 562
     "Generator that introspects the tables in the given database name and returns a Django model, one line at a time."
563 563
     from django.core import db
564 564
     from django.conf import settings
  565
+    import keyword
565 566
 
566 567
     def table2model(table_name):
567 568
         object_name = table_name.title().replace('_', '')
568 569
         return object_name.endswith('s') and object_name[:-1] or object_name
569 570
 
570  
-    reserved_python_words = set(['and', 'assert', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except', 'exec', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'not', 'or', 'pass', 'print', 'raise', 'return', 'try', 'while'])
571  
-
572 571
     settings.DATABASE_NAME = db_name
573 572
     cursor = db.db.cursor()
574 573
     yield "# This is an auto-generated Django model module."
@@ -593,7 +592,7 @@ def table2model(table_name):
593 592
             comment_notes = [] # Holds Field notes, to be displayed in a Python comment.
594 593
             extra_params = {}  # Holds Field parameters such as 'db_column'.
595 594
 
596  
-            if column_name in reserved_python_words:
  595
+            if keyword.iskeyword(column_name):
597 596
                 extra_params['db_column'] = column_name
598 597
                 column_name += '_field'
599 598
                 comment_notes.append('Field renamed because it was a Python reserved word.')

0 notes on commit c59901a

Please sign in to comment.
Something went wrong with that request. Please try again.