You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

134 lines
4.5 KiB

  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. "barry_as_FLUFL",
  43. ]
  44. __all__ = ["all_feature_names"] + all_feature_names
  45. # The CO_xxx symbols are defined here under the same names used by
  46. # compile.h, so that an editor search will find them here. However,
  47. # they're not exported in __all__, because they don't really belong to
  48. # this module.
  49. CO_NESTED = 0x0010 # nested_scopes
  50. CO_GENERATOR_ALLOWED = 0 # generators (obsolete, was 0x1000)
  51. CO_FUTURE_DIVISION = 0x2000 # division
  52. CO_FUTURE_ABSOLUTE_IMPORT = 0x4000 # perform absolute imports by default
  53. CO_FUTURE_WITH_STATEMENT = 0x8000 # with statement
  54. CO_FUTURE_PRINT_FUNCTION = 0x10000 # print function
  55. CO_FUTURE_UNICODE_LITERALS = 0x20000 # unicode string literals
  56. CO_FUTURE_BARRY_AS_BDFL = 0x40000
  57. class _Feature:
  58. def __init__(self, optionalRelease, mandatoryRelease, compiler_flag):
  59. self.optional = optionalRelease
  60. self.mandatory = mandatoryRelease
  61. self.compiler_flag = compiler_flag
  62. def getOptionalRelease(self):
  63. """Return first release in which this feature was recognized.
  64. This is a 5-tuple, of the same form as sys.version_info.
  65. """
  66. return self.optional
  67. def getMandatoryRelease(self):
  68. """Return release in which this feature will become mandatory.
  69. This is a 5-tuple, of the same form as sys.version_info, or, if
  70. the feature was dropped, is None.
  71. """
  72. return self.mandatory
  73. def __repr__(self):
  74. return "_Feature" + repr((self.optional,
  75. self.mandatory,
  76. self.compiler_flag))
  77. nested_scopes = _Feature((2, 1, 0, "beta", 1),
  78. (2, 2, 0, "alpha", 0),
  79. CO_NESTED)
  80. generators = _Feature((2, 2, 0, "alpha", 1),
  81. (2, 3, 0, "final", 0),
  82. CO_GENERATOR_ALLOWED)
  83. division = _Feature((2, 2, 0, "alpha", 2),
  84. (3, 0, 0, "alpha", 0),
  85. CO_FUTURE_DIVISION)
  86. absolute_import = _Feature((2, 5, 0, "alpha", 1),
  87. (2, 7, 0, "alpha", 0),
  88. CO_FUTURE_ABSOLUTE_IMPORT)
  89. with_statement = _Feature((2, 5, 0, "alpha", 1),
  90. (2, 6, 0, "alpha", 0),
  91. CO_FUTURE_WITH_STATEMENT)
  92. print_function = _Feature((2, 6, 0, "alpha", 2),
  93. (3, 0, 0, "alpha", 0),
  94. CO_FUTURE_PRINT_FUNCTION)
  95. unicode_literals = _Feature((2, 6, 0, "alpha", 2),
  96. (3, 0, 0, "alpha", 0),
  97. CO_FUTURE_UNICODE_LITERALS)
  98. barry_as_FLUFL = _Feature((3, 1, 0, "alpha", 2),
  99. (3, 9, 0, "alpha", 0),
  100. CO_FUTURE_BARRY_AS_BDFL)