PageRenderTime 40ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/lib-python/2.7/__future__.py

https://bitbucket.org/quangquach/pypy
Python | 128 lines | 124 code | 0 blank | 4 comment | 0 complexity | 9dd0341ccd8e9051ca9b11ca4917c1c5 MD5 | raw file
  1. """Record of phased-in incompatible language changes.
  2. Each line is of the form:
  3. FeatureName = "_Feature(" OptionalRelease "," MandatoryRelease ","
  4. CompilerFlag ")"
  5. where, normally, OptionalRelease < MandatoryRelease, and both are 5-tuples
  6. of the same form as sys.version_info:
  7. (PY_MAJOR_VERSION, # the 2 in 2.1.0a3; an int
  8. PY_MINOR_VERSION, # the 1; an int
  9. PY_MICRO_VERSION, # the 0; an int
  10. PY_RELEASE_LEVEL, # "alpha", "beta", "candidate" or "final"; string
  11. PY_RELEASE_SERIAL # the 3; an int
  12. )
  13. OptionalRelease records the first release in which
  14. from __future__ import FeatureName
  15. was accepted.
  16. In the case of MandatoryReleases that have not yet occurred,
  17. MandatoryRelease predicts the release in which the feature will become part
  18. of the language.
  19. Else MandatoryRelease records when the feature became part of the language;
  20. in releases at or after that, modules no longer need
  21. from __future__ import FeatureName
  22. to use the feature in question, but may continue to use such imports.
  23. MandatoryRelease may also be None, meaning that a planned feature got
  24. dropped.
  25. Instances of class _Feature have two corresponding methods,
  26. .getOptionalRelease() and .getMandatoryRelease().
  27. CompilerFlag is the (bitfield) flag that should be passed in the fourth
  28. argument to the builtin function compile() to enable the feature in
  29. dynamically compiled code. This flag is stored in the .compiler_flag
  30. attribute on _Future instances. These values must match the appropriate
  31. #defines of CO_xxx flags in Include/compile.h.
  32. No feature line is ever to be deleted from this file.
  33. """
  34. all_feature_names = [
  35. "nested_scopes",
  36. "generators",
  37. "division",
  38. "absolute_import",
  39. "with_statement",
  40. "print_function",
  41. "unicode_literals",
  42. ]
  43. __all__ = ["all_feature_names"] + all_feature_names
  44. # The CO_xxx symbols are defined here under the same names used by
  45. # compile.h, so that an editor search will find them here. However,
  46. # they're not exported in __all__, because they don't really belong to
  47. # this module.
  48. CO_NESTED = 0x0010 # nested_scopes
  49. CO_GENERATOR_ALLOWED = 0 # generators (obsolete, was 0x1000)
  50. CO_FUTURE_DIVISION = 0x2000 # division
  51. CO_FUTURE_ABSOLUTE_IMPORT = 0x4000 # perform absolute imports by default
  52. CO_FUTURE_WITH_STATEMENT = 0x8000 # with statement
  53. CO_FUTURE_PRINT_FUNCTION = 0x10000 # print function
  54. CO_FUTURE_UNICODE_LITERALS = 0x20000 # unicode string literals
  55. class _Feature:
  56. def __init__(self, optionalRelease, mandatoryRelease, compiler_flag):
  57. self.optional = optionalRelease
  58. self.mandatory = mandatoryRelease
  59. self.compiler_flag = compiler_flag
  60. def getOptionalRelease(self):
  61. """Return first release in which this feature was recognized.
  62. This is a 5-tuple, of the same form as sys.version_info.
  63. """
  64. return self.optional
  65. def getMandatoryRelease(self):
  66. """Return release in which this feature will become mandatory.
  67. This is a 5-tuple, of the same form as sys.version_info, or, if
  68. the feature was dropped, is None.
  69. """
  70. return self.mandatory
  71. def __repr__(self):
  72. return "_Feature" + repr((self.optional,
  73. self.mandatory,
  74. self.compiler_flag))
  75. nested_scopes = _Feature((2, 1, 0, "beta", 1),
  76. (2, 2, 0, "alpha", 0),
  77. CO_NESTED)
  78. generators = _Feature((2, 2, 0, "alpha", 1),
  79. (2, 3, 0, "final", 0),
  80. CO_GENERATOR_ALLOWED)
  81. division = _Feature((2, 2, 0, "alpha", 2),
  82. (3, 0, 0, "alpha", 0),
  83. CO_FUTURE_DIVISION)
  84. absolute_import = _Feature((2, 5, 0, "alpha", 1),
  85. (2, 7, 0, "alpha", 0),
  86. CO_FUTURE_ABSOLUTE_IMPORT)
  87. with_statement = _Feature((2, 5, 0, "alpha", 1),
  88. (2, 6, 0, "alpha", 0),
  89. CO_FUTURE_WITH_STATEMENT)
  90. print_function = _Feature((2, 6, 0, "alpha", 2),
  91. (3, 0, 0, "alpha", 0),
  92. CO_FUTURE_PRINT_FUNCTION)
  93. unicode_literals = _Feature((2, 6, 0, "alpha", 2),
  94. (3, 0, 0, "alpha", 0),
  95. CO_FUTURE_UNICODE_LITERALS)