[reader] stop providing base types without import (closes #287000)

5 years of deprecation warnings ought to be enough.

authorJulien Cristau <julien.cristau@logilab.fr>
changeset80421d81b547
branchdefault
phasepublic
hiddenno
parent revision#8131437862cc [reader] display schema file name when exec fails
child revision#22e4a1412db7 [reader] fix syntax error introduced in previous changeset
files modified by this revision
reader.py
# HG changeset patch
# User Julien Cristau <julien.cristau@logilab.fr>
# Date 1423755077 -3600
# Thu Feb 12 16:31:17 2015 +0100
# Node ID 80421d81b5473e839f8572682c074950c0e5989b
# Parent 8131437862cc75fd71ee8a13e3712f929908dda4
[reader] stop providing base types without import (closes #287000)

5 years of deprecation warnings ought to be enough.

diff --git a/reader.py b/reader.py
@@ -50,18 +50,10 @@
1              CONSTRAINTS[objname] = obj
2      except TypeError:
3          continue
4 
5 
6 -def obsolete(cls):
7 -    def wrapped(*args, **kwargs):
8 -        reason = '%s should be explictly imported from %s' % (
9 -            cls.__name__, cls.__module__)
10 -        warn(reason, DeprecationWarning, stacklevel=2)
11 -        return cls(*args, **kwargs)
12 -    return wrapped
13 -
14  def fill_schema(schema, erdefs, register_base_types=True,
15                  remove_unused_rtypes=False, post_build_callbacks=[]):
16      if register_base_types:
17          buildobjs.register_base_types(schema)
18      # relation definitions may appear multiple times
@@ -205,24 +197,10 @@
19          """
20          if not issubclass(defobject, buildobjs.Definition):
21              raise BadSchemaDefinition(filepath, 'invalid definition object')
22          defobject.expand_type_definitions(self.defined)
23 
24 -    def import_erschema(self, ertype, schemamod=None, instantiate=True):
25 -        warn('import_erschema is deprecated, use explicit import once schema '
26 -             'is turned into a proper python module (eg not expecting '
27 -             'predefined context in globals)', DeprecationWarning, stacklevel=3)
28 -        try:
29 -            erdef = self.defined[ertype]
30 -            name = getattr(erdef, 'name', erdef.__name__)
31 -            if name == ertype:
32 -                assert instantiate, 'can\'t get class of an already registered type'
33 -                return erdef
34 -        except KeyError:
35 -            pass
36 -        assert False, 'ooups'
37 -
38      def exec_file(self, filepath):
39          try:
40              modname = '.'.join(modpath_from_file(filepath, self.extrapath))
41              doimport = True
42          except ImportError:
@@ -240,47 +218,22 @@
43              module = sys.modules[modname]
44              # NOTE: don't test raw equality to avoid .pyc / .py comparisons
45              assert abspath(module.__file__).startswith(abspath(filepath)), (
46                  modname, filepath, module.__file__)
47          else:
48 -            # XXX until bw compat is gone, put context into builtins to allow proper
49 -            # control of deprecation warning
50 -            from six.moves import builtins
51              fglobals = {} # self.context.copy()
52 -            # wrap callable that should be imported
53 -            for key, val in self.context.items():
54 -                if key in BASE_TYPES or key == 'RichString' or key in CONSTRAINTS or \
55 -                       key in ('SubjectRelation', 'ObjectRelation'):
56 -                    val = obsolete(val)
57 -                setattr(builtins, key, val)
58 -            builtins.import_erschema = self.import_erschema
59              fglobals['__file__'] = filepath
60              fglobals['__name__'] = modname
61              package = '.'.join(modname.split('.')[:-1])
62              if package and not package in sys.modules:
63                  __import__(package)
64              with open(filepath) as f:
65                  try:
66                      exec(f.read(), fglobals)
67                  except:
68                      print('exception while reading %s' % filepath, file=sys.stderr)
69 -                    raise
70 -            # check for use of classes that should be imported, without
71 -            # importing them
72 -            for name, obj in fglobals.items():
73 -                if isinstance(obj, type) and \
74 -                       issubclass(obj, buildobjs.Definition) and \
75 -                       obj.__module__ == modname:
76 -                    for parent in obj.__bases__:
77 -                        pname = parent.__name__
78 -                        if pname in fglobals or not pname in self.context:
79 -                            # imported
80 -                            continue
81 -                        warn('%s: please explicitly import %s (%s)'
82 -                             % (filepath, pname, name), DeprecationWarning)
83 -            #for key in self.context:
84 -            #    fglobals.pop(key, None)
85 +                   raise
86              fglobals['__file__'] = filepath
87              module = types.ModuleType(str(modname))
88              module.__dict__.update(fglobals)
89              sys.modules[modname] = module
90              if package: