Advertisement
Python253

__future__.py

May 3rd, 2018
386
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.92 KB | None | 0 0
  1. """Record of phased-in incompatible language changes.
  2.  
  3. Each line is of the form:
  4.  
  5. FeatureName = "_Feature(" OptionalRelease "," MandatoryRelease ","
  6.  
  7. CompilerFlag ")"
  8.  
  9. where, normally, OptionalRelease < MandatoryRelease, and both are 5-tuples
  10.  
  11. of the same form as sys.version_info:
  12.  
  13. (PY_MAJOR_VERSION, # the 2 in 2.1.0a3; an int
  14.  
  15. PY_MINOR_VERSION, # the 1; an int
  16.  
  17. PY_MICRO_VERSION, # the 0; an int
  18.  
  19. PY_RELEASE_LEVEL, # "alpha", "beta", "candidate" or "final"; string
  20.  
  21. PY_RELEASE_SERIAL # the 3; an int
  22.  
  23. )
  24.  
  25. OptionalRelease records the first release in which
  26.  
  27. from __future__ import FeatureName
  28.  
  29. was accepted.
  30.  
  31. In the case of MandatoryReleases that have not yet occurred,
  32.  
  33. MandatoryRelease predicts the release in which the feature will become part
  34.  
  35. of the language.
  36.  
  37. Else MandatoryRelease records when the feature became part of the language;
  38.  
  39. in releases at or after that, modules no longer need
  40.  
  41. from __future__ import FeatureName
  42.  
  43. to use the feature in question, but may continue to use such imports.
  44.  
  45. MandatoryRelease may also be None, meaning that a planned feature got
  46.  
  47. dropped.
  48.  
  49. Instances of class _Feature have two corresponding methods,
  50.  
  51. .getOptionalRelease() and .getMandatoryRelease().
  52.  
  53. CompilerFlag is the (bitfield) flag that should be passed in the fourth
  54.  
  55. argument to the builtin function compile() to enable the feature in
  56.  
  57. dynamically compiled code. This flag is stored in the .compiler_flag
  58.  
  59. attribute on _Future instances. These values must match the appropriate
  60.  
  61. #defines of CO_xxx flags in Include/compile.h.
  62.  
  63. No feature line is ever to be deleted from this file.
  64.  
  65. """
  66.  
  67.  
  68. all_feature_names = [
  69.  
  70.     "nested_scopes",
  71.  
  72.     "generators",
  73.  
  74.     "division",
  75.  
  76.     "absolute_import",
  77.  
  78.     "with_statement",
  79.  
  80.     "print_function",
  81.  
  82.     "unicode_literals",
  83.  
  84. ]
  85.  
  86.  
  87. __all__ = ["all_feature_names"] + all_feature_names
  88.  
  89.  
  90. # The CO_xxx symbols are defined here under the same names used by
  91.  
  92. # compile.h, so that an editor search will find them here. However,
  93.  
  94. # they're not exported in __all__, because they don't really belong to
  95.  
  96. # this module.
  97.  
  98. CO_NESTED = 0x0010 # nested_scopes
  99.  
  100. CO_GENERATOR_ALLOWED = 0 # generators (obsolete, was 0x1000)
  101.  
  102. CO_FUTURE_DIVISION = 0x2000 # division
  103.  
  104. CO_FUTURE_ABSOLUTE_IMPORT = 0x4000 # perform absolute imports by default
  105.  
  106. CO_FUTURE_WITH_STATEMENT = 0x8000 # with statement
  107.  
  108. CO_FUTURE_PRINT_FUNCTION = 0x10000 # print function
  109.  
  110. CO_FUTURE_UNICODE_LITERALS = 0x20000 # unicode string literals
  111.  
  112.  
  113. class _Feature:
  114.  
  115.     def __init__(self, optionalRelease, mandatoryRelease, compiler_flag):
  116.  
  117.         self.optional = optionalRelease
  118.  
  119.         self.mandatory = mandatoryRelease
  120.  
  121.         self.compiler_flag = compiler_flag
  122.  
  123.  
  124.     def getOptionalRelease(self):
  125.  
  126.         """Return first release in which this feature was recognized.
  127.  
  128. This is a 5-tuple, of the same form as sys.version_info.
  129.  
  130. """
  131.  
  132.  
  133.         return self.optional
  134.  
  135.  
  136.     def getMandatoryRelease(self):
  137.  
  138.         """Return release in which this feature will become mandatory.
  139.  
  140. This is a 5-tuple, of the same form as sys.version_info, or, if
  141.  
  142. the feature was dropped, is None.
  143.  
  144. """
  145.  
  146.  
  147.         return self.mandatory
  148.  
  149.  
  150.     def __repr__(self):
  151.  
  152.         return "_Feature" + repr((self.optional,
  153.  
  154.                                   self.mandatory,
  155.  
  156.                                   self.compiler_flag))
  157.  
  158.  
  159. nested_scopes = _Feature((2, 1, 0, "beta", 1),
  160.  
  161.                          (2, 2, 0, "alpha", 0),
  162.  
  163.                          CO_NESTED)
  164.  
  165.  
  166. generators = _Feature((2, 2, 0, "alpha", 1),
  167.  
  168.                       (2, 3, 0, "final", 0),
  169.  
  170.                       CO_GENERATOR_ALLOWED)
  171.  
  172.  
  173. division = _Feature((2, 2, 0, "alpha", 2),
  174.  
  175.                     (3, 0, 0, "alpha", 0),
  176.  
  177.                     CO_FUTURE_DIVISION)
  178.  
  179.  
  180. absolute_import = _Feature((2, 5, 0, "alpha", 1),
  181.  
  182.                            (3, 0, 0, "alpha", 0),
  183.  
  184.                            CO_FUTURE_ABSOLUTE_IMPORT)
  185.  
  186.  
  187. with_statement = _Feature((2, 5, 0, "alpha", 1),
  188.  
  189.                           (2, 6, 0, "alpha", 0),
  190.  
  191.                           CO_FUTURE_WITH_STATEMENT)
  192.  
  193.  
  194. print_function = _Feature((2, 6, 0, "alpha", 2),
  195.  
  196.                           (3, 0, 0, "alpha", 0),
  197.  
  198.                           CO_FUTURE_PRINT_FUNCTION)
  199.  
  200.  
  201. unicode_literals = _Feature((2, 6, 0, "alpha", 2),
  202.  
  203.                             (3, 0, 0, "alpha", 0),
  204.  
  205.                             CO_FUTURE_UNICODE_LITERALS)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement