| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -353,6 +353,10 @@ Deprecated | |||
| 353 | 353 | in :data:`~dis.hasarg` instead. | |
| 354 | 354 | (Contributed by Irit Katriel in :gh:`109319`.) | |
| 355 | 355 | ||
| 356 | + * Deprecate non-standard format specifier "N" for :class:`decimal.Decimal`. | ||
| 357 | + It was not documented and only supported in the C implementation. | ||
| 358 | + (Contributed by Serhiy Storchaka in :gh:`89902`.) | ||
| 359 | + | ||
| 356 | 360 | ||
| 357 | 361 | Pending Removal in Python 3.14 | |
| 358 | 362 | ------------------------------ | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1222,6 +1222,23 @@ def get_fmt(x, override=None, fmt='n'): | |||
| 1222 | 1222 | self.assertEqual(get_fmt(Decimal('-1.5'), dotsep_wide, '020n'), | |
| 1223 | 1223 | '-0\u00b4000\u00b4000\u00b4000\u00b4001\u00bf5') | |
| 1224 | 1224 | ||
| 1225 | + def test_deprecated_N_format(self): | ||
| 1226 | + Decimal = self.decimal.Decimal | ||
| 1227 | + h = Decimal('6.62607015e-34') | ||
| 1228 | + if self.decimal == C: | ||
| 1229 | + with self.assertWarns(DeprecationWarning) as cm: | ||
| 1230 | + r = format(h, 'N') | ||
| 1231 | + self.assertEqual(cm.filename, __file__) | ||
| 1232 | + self.assertEqual(r, format(h, 'n').upper()) | ||
| 1233 | + with self.assertWarns(DeprecationWarning) as cm: | ||
| 1234 | + r = format(h, '010.3N') | ||
| 1235 | + self.assertEqual(cm.filename, __file__) | ||
| 1236 | + self.assertEqual(r, format(h, '010.3n').upper()) | ||
| 1237 | + else: | ||
| 1238 | + self.assertRaises(ValueError, format, h, 'N') | ||
| 1239 | + self.assertRaises(ValueError, format, h, '010.3N') | ||
| 1240 | + | ||
| 1241 | + | ||
| 1225 | 1242 | @run_with_locale('LC_ALL', 'ps_AF') | |
| 1226 | 1243 | def test_wide_char_separator_decimal_point(self): | |
| 1227 | 1244 | # locale with wide char separator and decimal point | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,2 @@ | |||
| 1 | + Deprecate non-standard format specifier "N" for :class:`decimal.Decimal`. It | ||
| 2 | + was not documented and only supported in the C implementation. | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3593,6 +3593,12 @@ dec_format(PyObject *dec, PyObject *args) | |||
| 3593 | 3593 | if (replace_fillchar) { | |
| 3594 | 3594 | dec_replace_fillchar(decstring); | |
| 3595 | 3595 | } | |
| 3596 | + if (strchr(fmt, 'N') != NULL) { | ||
| 3597 | + if (PyErr_WarnEx(PyExc_DeprecationWarning, | ||
| 3598 | + "Format specifier 'N' is deprecated", 1) < 0) { | ||
| 3599 | + goto finish; | ||
| 3600 | + } | ||
| 3601 | + } | ||
| 3596 | 3602 | ||
| 3597 | 3603 | result = PyUnicode_DecodeUTF8(decstring, size, NULL); | |
| 3598 | 3604 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments