Ticket #11599: trac_11599_no_circular_imports.py

File trac_11599_no_circular_imports.py, 24.2 KB (added by vbraun, 10 years ago)

Updated patch

Line 
1# HG changeset patch
2# User Volker Braun <vbraun@stp.dias.ie>
3# Date 1313094791 14400
4# Node ID 268ed370739b103f44de17134097a108d7d93af2
5# Parent  d6544a75f0a3579bc0713d8f1d3bb692efe68ebd
6Trac #11599: Make the scheme submodules noncircular.
7
8The file notes/imports.txt describes how the different
9files in sage.schemes.generic should import each other
10to avoid circular imports in the future.
11
12diff --git a/sage/schemes/generic/affine_space.py b/sage/schemes/generic/affine_space.py
13--- a/sage/schemes/generic/affine_space.py
14+++ b/sage/schemes/generic/affine_space.py
15@@ -20,20 +20,14 @@
16     Integer)
17 
18 from sage.misc.all import latex
19+from sage.structure.parent_gens import normalize_names
20 
21-import algebraic_scheme
22-
23-import ambient_space
24-
25+from scheme import AffineScheme
26+from ambient_space import AmbientSpace
27 import homset
28-
29 import morphism
30 
31-import projective_space
32 
33-import scheme
34-
35-from sage.structure.parent_gens import normalize_names
36 
37 def is_AffineSpace(x):
38     r"""
39@@ -110,7 +104,7 @@
40             raise TypeError, "You must specify the variables names of the coordinate ring."
41     return AffineSpace_generic(n, R, names)
42 
43-class AffineSpace_generic(ambient_space.AmbientSpace, scheme.AffineScheme):
44+class AffineSpace_generic(AmbientSpace, AffineScheme):
45     """
46     Affine space of dimension `n` over the ring `R`.
47     
48@@ -166,7 +160,7 @@
49             Affine Space of dimension 3 over 5-adic Ring with capped relative precision 20
50         """
51         names = normalize_names(n, names)
52-        ambient_space.AmbientSpace.__init__(self, n, R)
53+        AmbientSpace.__init__(self, n, R)
54         self._assign_names(names)
55 
56     def __iter__(self):
57@@ -554,7 +548,8 @@
58         except KeyError:
59             pass
60         if PP is None:
61-            PP = projective_space.ProjectiveSpace(n, self.base_ring())
62+            from sage.schemes.generic.projective_space import ProjectiveSpace
63+            PP = ProjectiveSpace(n, self.base_ring())
64         R = self.coordinate_ring()
65         v = list(R.gens())
66         if n < 0 or n >self.dimension_relative():
67@@ -609,4 +604,5 @@
68             sage: X.dimension()
69             0
70         """
71-        return algebraic_scheme.AlgebraicScheme_subscheme_affine(self, X)
72+        from sage.schemes.generic.algebraic_scheme import AlgebraicScheme_subscheme_affine
73+        return AlgebraicScheme_subscheme_affine(self, X)
74diff --git a/sage/schemes/generic/algebraic_scheme.py b/sage/schemes/generic/algebraic_scheme.py
75--- a/sage/schemes/generic/algebraic_scheme.py
76+++ b/sage/schemes/generic/algebraic_scheme.py
77@@ -2081,7 +2081,8 @@
78               Defn: Defined on coordinates by sending [z0 : z1 : z2 : z3] to
79                     [z2 : z1 : z2 : z3]
80         """
81-        return morphism.SchemeMorphism_on_points_toric_variety(*args, **kwds)
82+        from sage.schemes.generic.toric_morphism import SchemeMorphism_on_points_toric_variety
83+        return SchemeMorphism_on_points_toric_variety(*args, **kwds)
84 
85     def affine_patch(self, i):
86         r"""
87diff --git a/sage/schemes/generic/ambient_space.py b/sage/schemes/generic/ambient_space.py
88--- a/sage/schemes/generic/ambient_space.py
89+++ b/sage/schemes/generic/ambient_space.py
90@@ -14,9 +14,9 @@
91 
92 from sage.structure.parent import Parent
93 
94-import algebraic_scheme
95 import scheme
96 
97+
98 def is_AmbientSpace(x):
99     """
100     Return True if `x` is an ambient space.
101diff --git a/sage/schemes/generic/divisor.py b/sage/schemes/generic/divisor.py
102--- a/sage/schemes/generic/divisor.py
103+++ b/sage/schemes/generic/divisor.py
104@@ -46,8 +46,8 @@
105 from sage.rings.all import ZZ
106 from sage.structure.formal_sum import FormalSum
107 
108+from morphism import is_SchemeMorphism
109 from affine_space import is_AffineSpace
110-from morphism import is_SchemeMorphism
111 from projective_space import is_ProjectiveSpace
112 
113 
114diff --git a/sage/schemes/generic/homset.py b/sage/schemes/generic/homset.py
115--- a/sage/schemes/generic/homset.py
116+++ b/sage/schemes/generic/homset.py
117@@ -15,9 +15,10 @@
118 from sage.rings.finite_rings.constructor import is_FiniteField
119 from sage.rings.rational_field import is_RationalField
120 from sage.rings.morphism import is_RingHomomorphism
121+
122 import spec
123 import morphism
124-
125+from sage.schemes.generic.toric_morphism import SchemeMorphism_toric_coordinates_field
126 
127 
128 
129@@ -327,5 +328,5 @@
130         try:
131             return X._point_class(X, arg)
132         except AttributeError:  # should be very rare
133-            return morphism.SchemeMorphism_toric_coordinates_field(self, arg)
134+            return SchemeMorphism_toric_coordinates_field(self, arg)
135 
136diff --git a/sage/schemes/generic/morphism.py b/sage/schemes/generic/morphism.py
137--- a/sage/schemes/generic/morphism.py
138+++ b/sage/schemes/generic/morphism.py
139@@ -693,135 +693,3 @@
140 
141 
142 
143-#*******************************************************************
144-# Toric varieties
145-#*******************************************************************
146-class SchemeMorphism_toric_coordinates_field(SchemeMorphism_coordinates):
147-    """
148-    Construct a morphism determined by giving coordinates in a field.
149-
150-    .. WARNING::
151-
152-        You should not create objects of this class directly.
153-
154-    INPUT:
155-
156-    - ``X`` -- subscheme of a toric variety.
157-
158-    - ``coordinates`` -- list of coordinates in the base field of ``X``.
159-
160-    - ``check`` -- if ``True`` (default), the input will be checked for
161-      correctness.
162-
163-    OUTPUT:
164-
165-    - :class:`SchemeMorphism_toric_coordinates_field`.
166-
167-    TESTS::
168-
169-        sage: fan = FaceFan(lattice_polytope.octahedron(2))
170-        sage: P1xP1 = ToricVariety(fan)
171-        sage: P1xP1(1,2,3,4)
172-        [1 : 2 : 3 : 4]
173-    """
174-    # Mimicking affine/projective classes
175-    def __init__(self, X, coordinates, check=True):
176-        r"""
177-        See :class:`SchemeMorphism_toric_coordinates_field` for documentation.
178-
179-        TESTS::
180-
181-            sage: fan = FaceFan(lattice_polytope.octahedron(2))
182-            sage: P1xP1 = ToricVariety(fan)
183-            sage: P1xP1(1,2,3,4)
184-            [1 : 2 : 3 : 4]
185-        """
186-        # Convert scheme to its set of points over the base ring
187-        if scheme.is_Scheme(X):
188-            X = X(X.base_ring())
189-        super(SchemeMorphism_toric_coordinates_field, self).__init__(X)
190-        if check:
191-            # Verify that there are the right number of coords
192-            # Why is it not done in the parent?
193-            if is_SchemeMorphism(coordinates):
194-                coordinates = list(coordinates)
195-            if not isinstance(coordinates, (list, tuple)):
196-                raise TypeError("coordinates must be a scheme point, list, "
197-                                "or tuple. Got %s" % coordinates)
198-            d = X.codomain().ambient_space().ngens()
199-            if len(coordinates) != d:
200-                raise ValueError("there must be %d coordinates! Got only %d: "
201-                                 "%s" % (d, len(coordinates), coordinates))
202-            # Make sure the coordinates all lie in the appropriate ring
203-            coordinates = Sequence(coordinates, X.value_ring())
204-            # Verify that the point satisfies the equations of X.
205-            X.codomain()._check_satisfies_equations(coordinates)
206-        self._coords = coordinates
207-
208-
209-class SchemeMorphism_on_points_toric_variety(SchemeMorphism_on_points):
210-    """
211-    Construct a morphism determined by action on points.
212-
213-    .. WARNING::
214-
215-        You should not create objects of this class directly.
216-
217-    INPUT:
218-
219-    - same as for
220-      :class:`~sage.schemes.generic.morphism.SchemeMorphism_on_points`.
221-
222-    OUPUT:
223-
224-    - :class:`~sage.schemes.generic.morphism.SchemeMorphism_on_points_toric_variety`.
225-
226-    TESTS::
227-
228-        sage: fan = FaceFan(lattice_polytope.octahedron(2))
229-        sage: P1xP1 = ToricVariety(fan)
230-        sage: P1xP1.inject_variables()
231-        Defining z0, z1, z2, z3
232-        sage: P1 = P1xP1.subscheme(z0-z2)
233-        sage: H = P1xP1.Hom(P1)
234-        sage: import sage.schemes.generic.morphism as MOR
235-        sage: MOR.SchemeMorphism_on_points_toric_variety(H, [z0,z1,z0,z3])
236-        Scheme morphism:
237-          From: 2-d toric variety covered by 4 affine patches
238-          To:   Closed subscheme of 2-d toric variety
239-                covered by 4 affine patches defined by:
240-          z0 - z2
241-          Defn: Defined on coordinates by sending
242-                [z0 : z1 : z2 : z3] to [z0 : z1 : z0 : z3]
243-    """
244-
245-    def __init__(self, parent, polynomials, check=True):
246-        r"""
247-        See :class:`SchemeMorphism_on_points_toric_variety` for documentation.
248-
249-        TESTS::
250-
251-            sage: fan = FaceFan(lattice_polytope.octahedron(2))
252-            sage: P1xP1 = ToricVariety(fan)
253-            sage: P1xP1.inject_variables()
254-            Defining z0, z1, z2, z3
255-            sage: P1 = P1xP1.subscheme(z0-z2)
256-            sage: H = P1xP1.Hom(P1)
257-            sage: import sage.schemes.generic.morphism as MOR
258-            sage: MOR.SchemeMorphism_on_points_toric_variety(H, [z0,z1,z0,z3])
259-            Scheme morphism:
260-              From: 2-d toric variety covered by 4 affine patches
261-              To:   Closed subscheme of 2-d toric variety
262-                    covered by 4 affine patches defined by:
263-              z0 - z2
264-              Defn: Defined on coordinates by sending
265-                    [z0 : z1 : z2 : z3] to [z0 : z1 : z0 : z3]
266-        """
267-        SchemeMorphism_on_points.__init__(self, parent, polynomials, check)
268-        if check:
269-            # Check that defining polynomials are homogeneous (degrees can be
270-            # different if the target uses weighted coordinates)
271-            for p in self.defining_polynomials():
272-                if not self.domain().ambient_space().is_homogeneous(p):
273-                    raise ValueError("%s is not homogeneous!" % p)
274-
275diff --git a/sage/schemes/generic/notes/imports.txt b/sage/schemes/generic/notes/imports.txt
276new file mode 100644
277--- /dev/null
278+++ b/sage/schemes/generic/notes/imports.txt
279@@ -0,0 +1,31 @@
280+In order to avoid circular imports, the schemes should only import
281+from other modules higher in the following hierarchy:
282+
283+1. scheme, point
284+
285+2. spec, ambient_space, morphism
286+
287+3. toric_morphism, glue
288+
289+4. homset
290+
291+5. affine_scheme, projective_scheme, toric_variety
292+
293+6. algebraic_scheme, fano_toric_variety
294+
295+7. hypersurface
296+
297+8. divisor
298+
299+9. divisor_group
300+
301+10. toric_divisor
302+
303+If you nevertheless need something from a module lower in the
304+hierarchy, you should defer the import. That is, put the import at the
305+class/method level and not in the module scope. For example, scheme.py
306+needs spec.py for the default base scheme but contains no "import
307+spec" at the module level.
308+
309+
310+
311diff --git a/sage/schemes/generic/projective_space.py b/sage/schemes/generic/projective_space.py
312--- a/sage/schemes/generic/projective_space.py
313+++ b/sage/schemes/generic/projective_space.py
314@@ -69,20 +69,15 @@
315                             Integer,
316                             ZZ)
317 from sage.modules.all import VectorSpace
318+from sage.misc.all import latex
319+from sage.structure.parent_gens import normalize_names
320+from sage.rings.arith import gcd
321+from sage.combinat.tuple import Tuples
322 
323-from sage.misc.all import latex
324-
325+from ambient_space import AmbientSpace
326 import homset
327 import morphism
328 
329-import ambient_space
330-import affine_space
331-
332-from sage.structure.parent_gens import normalize_names
333-
334-from sage.rings.arith import gcd
335-
336-from sage.combinat.tuple import Tuples
337 
338 def is_ProjectiveSpace(x):
339     r"""
340@@ -169,7 +164,7 @@
341     else:
342         raise TypeError, "R (=%s) must be a commutative ring"%R
343 
344-class ProjectiveSpace_ring(ambient_space.AmbientSpace):
345+class ProjectiveSpace_ring(AmbientSpace):
346     """
347     Projective space of dimension `n` over the ring
348     `R`.
349@@ -202,7 +197,7 @@
350             Projective Space of dimension 3 over 5-adic Ring with capped relative precision 20
351         """
352         names = normalize_names(n+1, names)
353-        ambient_space.AmbientSpace.__init__(self, n, R)
354+        AmbientSpace.__init__(self, n, R)
355         self._assign_names(names)
356 
357     def ngens(self):
358@@ -546,7 +541,8 @@
359             self.__affine_patches = {}
360         except KeyError:
361             pass
362-        AA = affine_space.AffineSpace(n, self.base_ring(), names='x')
363+        from sage.schemes.generic.affine_space import AffineSpace
364+        AA = AffineSpace(n, self.base_ring(), names='x')
365         AA._default_embedding_index = i
366         phi = AA.projective_embedding(i, self)
367         self.__affine_patches[i] = AA
368diff --git a/sage/schemes/generic/scheme.py b/sage/schemes/generic/scheme.py
369--- a/sage/schemes/generic/scheme.py
370+++ b/sage/schemes/generic/scheme.py
371@@ -24,12 +24,6 @@
372                             ZZ, is_RingHomomorphism, GF, PowerSeriesRing,
373                             Rationals)
374 
375-import homset
376-
377-import morphism
378-
379-import spec
380-
381 def is_Scheme(x):
382     """
383     Return True if `x` is a scheme.
384@@ -45,6 +39,7 @@
385     """
386     return isinstance(x, Scheme)
387 
388+
389 # If a derived class sets any of the properties, _base_scheme, _base_ring,
390 # or _base_morphism, it will determine the others.  If none are set,
391 # the base defaults to Spec(Z) with the canonical morphism.
392@@ -60,14 +55,16 @@
393             sage: I = (x^2 - y^2)*R
394             sage: RmodI = R.quotient(I)
395             sage: X = Spec(RmodI)
396-            sage: TestSuite(X).run(skip = ["_test_an_element", "_test_elements", "_test_some_elements", "_test_category"]) # See #7946
397+            sage: TestSuite(X).run(skip = ["_test_an_element", "_test_elements", 
398+            ...                            "_test_some_elements", "_test_category"]) # See #7946
399 
400         A scheme is in the category of all schemes over the base scheme of self::
401 
402             sage: ProjectiveSpace(4, QQ).category()
403             Category of schemes over Spectrum of Rational Field
404         """
405-        if spec.is_Spec(X):
406+        from sage.schemes.generic.spec import is_Spec
407+        if is_Spec(X):
408             self._base_ring = X.coordinate_ring()
409             base = self._base_ring
410         else:
411@@ -79,7 +76,8 @@
412         if category is None:
413             category = default_category
414         else:
415-            assert category.is_subcategory(default_category), "%s is not a subcategory of %s"%(category, default_category)
416+            assert category.is_subcategory(default_category), \
417+                "%s is not a subcategory of %s"%(category, default_category)
418 
419         Parent.__init__(self, base, category = category)
420 
421@@ -204,11 +202,12 @@
422         S = args[0]
423         if is_CommutativeRing(S):
424             return self.point_homset(S)
425-        elif is_Scheme(S):
426+        if is_Scheme(S):
427             return S.Hom(self)
428-        elif isinstance(S, (list, tuple)):
429+        from sage.schemes.generic.morphism import SchemeMorphism_coordinates
430+        if isinstance(S, (list, tuple)):
431             args = S
432-        elif isinstance(S, morphism.SchemeMorphism_coordinates):
433+        elif isinstance(S, SchemeMorphism_coordinates):
434             if S.codomain() == self:
435                 return S
436         else:
437@@ -342,14 +341,15 @@
438         try:
439             return self._base_scheme
440         except AttributeError:
441+            from sage.schemes.generic.spec import Spec, SpecZ
442             if hasattr(self, '_base_morphism'):
443                 self._base_scheme = self._base_morphism.codomain()
444             elif hasattr(self, '_base_ring'):
445                 import spec
446-                self._base_scheme = spec.Spec(self._base_ring)
447+                self._base_scheme = Spec(self._base_ring)
448             else:
449                 import spec               
450-                self._base_scheme = spec.SpecZ
451+                self._base_scheme = SpecZ
452             return self._base_scheme
453 
454     def base_morphism(self):
455@@ -379,13 +379,14 @@
456             return self._base_morphism
457         except AttributeError:
458             from sage.categories.schemes import Schemes
459+            from sage.schemes.generic.spec import Spec, SpecZ
460             SCH = Schemes()
461             if hasattr(self, '_base_scheme'):
462                 self._base_morphism = self.Hom(self._base_scheme, category=SCH).natural_map()
463             elif hasattr(self, '_base_ring'):
464-                self._base_morphism = self.Hom(spec.Spec(self._base_ring), category=SCH).natural_map()
465+                self._base_morphism = self.Hom(Spec(self._base_ring), category=SCH).natural_map()
466             else:
467-                self._base_morphism = self.Hom(spec.SpecZ, category=SCH).natural_map()
468+                self._base_morphism = self.Hom(SpecZ, category=SCH).natural_map()
469             return self._base_morphism
470 
471     structure_morphism = base_morphism
472@@ -457,7 +458,8 @@
473             Scheme endomorphism of Spectrum of Rational Field
474               Defn: Identity map
475         """
476-        return morphism.SchemeMorphism_id(self)
477+        from sage.schemes.generic.morphism import SchemeMorphism_id
478+        return SchemeMorphism_id(self)
479 
480     def hom(self, x, Y=None, check=True):
481         """
482@@ -493,7 +495,8 @@
483             sage: S._Hom_(P)
484             Set of points of Projective Space of dimension 3 over Integer Ring defined over Integer Ring
485         """
486-        return homset.SchemeHomset(self, Y, category=category, check=check)
487+        from sage.schemes.generic.homset import SchemeHomset
488+        return SchemeHomset(self, Y, category=category, check=check)
489 
490     point_set = point_homset
491 
492diff --git a/sage/schemes/generic/toric_morphism.py b/sage/schemes/generic/toric_morphism.py
493new file mode 100644
494--- /dev/null
495+++ b/sage/schemes/generic/toric_morphism.py
496@@ -0,0 +1,157 @@
497+"""
498+Morphisms of Toric Varieties
499+
500+
501+"""
502+
503+
504+#*****************************************************************************
505+#  Copyright (C) 2010 Volker Braun <vbraun.name@gmail.com>
506+#  Copyright (C) 2010 Andrey Novoseltsev <novoselt@gmail.com>
507+#  Copyright (C) 2006 William Stein <wstein@gmail.com>
508+#  Distributed under the terms of the GNU General Public License (GPL)
509+#                  http://www.gnu.org/licenses/
510+#*****************************************************************************
511+
512+from sage.structure.sequence  import Sequence
513+
514+import scheme     
515+from sage.schemes.generic.morphism import (
516+    is_SchemeMorphism,
517+    SchemeMorphism_coordinates, SchemeMorphism_on_points
518+)
519+
520+
521+
522+class SchemeMorphism_toric_coordinates_field(SchemeMorphism_coordinates):
523+    """
524+    Construct a morphism determined by giving coordinates in a field.
525+
526+    .. WARNING::
527+
528+        You should not create objects of this class directly.
529+
530+    INPUT:
531+
532+    - ``X`` -- subscheme of a toric variety.
533+
534+    - ``coordinates`` -- list of coordinates in the base field of ``X``.
535+
536+    - ``check`` -- if ``True`` (default), the input will be checked for
537+      correctness.
538+
539+    OUTPUT:
540+
541+    - :class:`SchemeMorphism_toric_coordinates_field`.
542+
543+    TESTS::
544+
545+        sage: fan = FaceFan(lattice_polytope.octahedron(2))
546+        sage: P1xP1 = ToricVariety(fan)
547+        sage: P1xP1(1,2,3,4)
548+        [1 : 2 : 3 : 4]
549+    """
550+    # Mimicking affine/projective classes
551+    def __init__(self, X, coordinates, check=True):
552+        r"""
553+        See :class:`SchemeMorphism_toric_coordinates_field` for documentation.
554+
555+        TESTS::
556+
557+            sage: fan = FaceFan(lattice_polytope.octahedron(2))
558+            sage: P1xP1 = ToricVariety(fan)
559+            sage: P1xP1(1,2,3,4)
560+            [1 : 2 : 3 : 4]
561+        """
562+        # Convert scheme to its set of points over the base ring
563+        if scheme.is_Scheme(X):
564+            X = X(X.base_ring())
565+        super(SchemeMorphism_toric_coordinates_field, self).__init__(X)
566+        if check:
567+            # Verify that there are the right number of coords
568+            # Why is it not done in the parent?
569+            if is_SchemeMorphism(coordinates):
570+                coordinates = list(coordinates)
571+            if not isinstance(coordinates, (list, tuple)):
572+                raise TypeError("coordinates must be a scheme point, list, "
573+                                "or tuple. Got %s" % coordinates)
574+            d = X.codomain().ambient_space().ngens()
575+            if len(coordinates) != d:
576+                raise ValueError("there must be %d coordinates! Got only %d: "
577+                                 "%s" % (d, len(coordinates), coordinates))
578+            # Make sure the coordinates all lie in the appropriate ring
579+            coordinates = Sequence(coordinates, X.value_ring())
580+            # Verify that the point satisfies the equations of X.
581+            X.codomain()._check_satisfies_equations(coordinates)
582+        self._coords = coordinates
583+
584+
585+
586+class SchemeMorphism_on_points_toric_variety(SchemeMorphism_on_points):
587+    """
588+    Construct a morphism determined by action on points.
589+
590+    .. WARNING::
591+
592+        You should not create objects of this class directly.
593+
594+    INPUT:
595+
596+    - same as for
597+      :class:`~sage.schemes.generic.morphism.SchemeMorphism_on_points`.
598+
599+    OUPUT:
600+
601+    - :class:`~sage.schemes.generic.morphism.SchemeMorphism_on_points_toric_variety`.
602+
603+    TESTS::
604+
605+        sage: fan = FaceFan(lattice_polytope.octahedron(2))
606+        sage: P1xP1 = ToricVariety(fan)
607+        sage: P1xP1.inject_variables()
608+        Defining z0, z1, z2, z3
609+        sage: P1 = P1xP1.subscheme(z0-z2)
610+        sage: H = P1xP1.Hom(P1)
611+        sage: import sage.schemes.generic.toric_morphism as MOR
612+        sage: MOR.SchemeMorphism_on_points_toric_variety(H, [z0,z1,z0,z3])
613+        Scheme morphism:
614+          From: 2-d toric variety covered by 4 affine patches
615+          To:   Closed subscheme of 2-d toric variety
616+                covered by 4 affine patches defined by:
617+          z0 - z2
618+          Defn: Defined on coordinates by sending
619+                [z0 : z1 : z2 : z3] to [z0 : z1 : z0 : z3]
620+    """
621+
622+    def __init__(self, parent, polynomials, check=True):
623+        r"""
624+        See :class:`SchemeMorphism_on_points_toric_variety` for documentation.
625+
626+        TESTS::
627+
628+            sage: fan = FaceFan(lattice_polytope.octahedron(2))
629+            sage: P1xP1 = ToricVariety(fan)
630+            sage: P1xP1.inject_variables()
631+            Defining z0, z1, z2, z3
632+            sage: P1 = P1xP1.subscheme(z0-z2)
633+            sage: H = P1xP1.Hom(P1)
634+            sage: import sage.schemes.generic.toric_morphism as MOR
635+            sage: MOR.SchemeMorphism_on_points_toric_variety(H, [z0,z1,z0,z3])
636+            Scheme morphism:
637+              From: 2-d toric variety covered by 4 affine patches
638+              To:   Closed subscheme of 2-d toric variety
639+                    covered by 4 affine patches defined by:
640+              z0 - z2
641+              Defn: Defined on coordinates by sending
642+                    [z0 : z1 : z2 : z3] to [z0 : z1 : z0 : z3]
643+        """
644+        SchemeMorphism_on_points.__init__(self, parent, polynomials, check)
645+        if check:
646+            # Check that defining polynomials are homogeneous (degrees can be
647+            # different if the target uses weighted coordinates)
648+            for p in self.defining_polynomials():
649+                if not self.domain().ambient_space().is_homogeneous(p):
650+                    raise ValueError("%s is not homogeneous!" % p)
651+
652+
653+
654diff --git a/sage/schemes/generic/toric_variety.py b/sage/schemes/generic/toric_variety.py
655--- a/sage/schemes/generic/toric_variety.py
656+++ b/sage/schemes/generic/toric_variety.py
657@@ -242,16 +242,14 @@
658 from sage.rings.all import PolynomialRing, ZZ, QQ, is_Field, is_FractionField
659 from sage.rings.quotient_ring_element import QuotientRingElement
660 from sage.rings.quotient_ring import QuotientRing_generic
661+from sage.structure.sequence import Sequence
662+from sage.functions.all import factorial
663+
664 from sage.schemes.generic.ambient_space import AmbientSpace
665 from sage.schemes.generic.homset import (SchemeHomset_coordinates,
666                                          SchemeHomset_toric_coordinates_field)
667-from sage.schemes.generic.morphism import (SchemeMorphism_on_points_toric_variety,
668-                                           SchemeMorphism_toric_coordinates_field,
669-                                           SchemeMorphism_coordinates,
670-                                           SchemeMorphism_on_points,
671-                                           is_SchemeMorphism)
672-from sage.structure.sequence import Sequence
673-from sage.functions.all import factorial
674+from sage.schemes.generic.toric_morphism import (SchemeMorphism_on_points_toric_variety,
675+                                                 SchemeMorphism_toric_coordinates_field)
676 
677 
678 # Default prefix for indexed coordinates