Skip to content

Commit 4e9f730

Browse files
tornariamatusvalo
authored andcommitted
Fix warnings for "implicit noexcept" when using legacy_implicit_noexcept=True (#6087)
1 parent c73eb9e commit 4e9f730

File tree

7 files changed

+85
-75
lines changed

7 files changed

+85
-75
lines changed

Cython/Compiler/Nodes.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -711,6 +711,19 @@ def analyse(self, return_type, env, nonempty=0, directive_locals=None, visibilit
711711

712712
exc_val = None
713713
exc_check = 0
714+
715+
if (env.directives["legacy_implicit_noexcept"]
716+
and not return_type.is_pyobject
717+
and not self.has_explicit_exc_clause
718+
and self.exception_check
719+
and visibility != 'extern'):
720+
# implicit noexcept, with a warning
721+
self.exception_check = False
722+
warning(self.pos,
723+
"Implicit noexcept declaration is deprecated."
724+
" Function declaration should contain 'noexcept' keyword.",
725+
level=2)
726+
714727
if self.exception_check == '+':
715728
env.add_include_file('ios') # for std::ios_base::failure
716729
env.add_include_file('new') # for std::bad_alloc

Cython/Compiler/Parsing.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3128,9 +3128,7 @@ def p_exception_value_clause(s, is_extern):
31283128
exc_check = False
31293129
# exc_val can be non-None even if exc_check is False, c.f. "except -1"
31303130
exc_val = p_test(s)
3131-
if not is_extern and not exc_clause and s.context.legacy_implicit_noexcept:
3132-
exc_check = False
3133-
warning(s.position(), "Implicit noexcept declaration is deprecated. Function declaration should contain 'noexcept' keyword.", level=2)
3131+
31343132
return exc_val, exc_check, exc_clause
31353133

31363134
c_arg_list_terminators = cython.declare(frozenset, frozenset((

Cython/Includes/cpython/array.pxd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,6 @@ cdef inline int extend(array self, array other) except -1:
169169
PyErr_BadArgument()
170170
return extend_buffer(self, other.data.as_chars, Py_SIZE(other))
171171

172-
cdef inline void zero(array self):
172+
cdef inline void zero(array self) noexcept:
173173
""" set all elements of array to zero. """
174174
memset(self.data.as_chars, 0, Py_SIZE(self) * self.ob_descr.itemsize)

Cython/Includes/cpython/complex.pxd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ cdef extern from "Python.h":
1616
cdef Py_complex cval
1717

1818
@property
19-
cdef inline double real(self):
19+
cdef inline double real(self) noexcept:
2020
return self.cval.real
2121

2222
@property
23-
cdef inline double imag(self):
23+
cdef inline double imag(self) noexcept:
2424
return self.cval.imag
2525

2626
# PyTypeObject PyComplex_Type

Cython/Includes/cpython/datetime.pxd

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -69,92 +69,92 @@ cdef extern from "datetime.h":
6969

7070
ctypedef extern class datetime.date[object PyDateTime_Date]:
7171
@property
72-
cdef inline int year(self):
72+
cdef inline int year(self) noexcept:
7373
return PyDateTime_GET_YEAR(self)
7474

7575
@property
76-
cdef inline int month(self):
76+
cdef inline int month(self) noexcept:
7777
return PyDateTime_GET_MONTH(self)
7878

7979
@property
80-
cdef inline int day(self):
80+
cdef inline int day(self) noexcept:
8181
return PyDateTime_GET_DAY(self)
8282

8383
ctypedef extern class datetime.time[object PyDateTime_Time]:
8484
@property
85-
cdef inline int hour(self):
85+
cdef inline int hour(self) noexcept:
8686
return PyDateTime_TIME_GET_HOUR(self)
8787

8888
@property
89-
cdef inline int minute(self):
89+
cdef inline int minute(self) noexcept:
9090
return PyDateTime_TIME_GET_MINUTE(self)
9191

9292
@property
93-
cdef inline int second(self):
93+
cdef inline int second(self) noexcept:
9494
return PyDateTime_TIME_GET_SECOND(self)
9595

9696
@property
97-
cdef inline int microsecond(self):
97+
cdef inline int microsecond(self) noexcept:
9898
return PyDateTime_TIME_GET_MICROSECOND(self)
9999

100100
@property
101101
cdef inline object tzinfo(self):
102102
return <object>PyDateTime_TIME_GET_TZINFO(self)
103103

104104
@property
105-
cdef inline int fold(self):
105+
cdef inline int fold(self) noexcept:
106106
# For Python < 3.6 this returns 0 no matter what
107107
return PyDateTime_TIME_GET_FOLD(self)
108108

109109
ctypedef extern class datetime.datetime[object PyDateTime_DateTime]:
110110
@property
111-
cdef inline int year(self):
111+
cdef inline int year(self) noexcept:
112112
return PyDateTime_GET_YEAR(self)
113113

114114
@property
115-
cdef inline int month(self):
115+
cdef inline int month(self) noexcept:
116116
return PyDateTime_GET_MONTH(self)
117117

118118
@property
119-
cdef inline int day(self):
119+
cdef inline int day(self) noexcept:
120120
return PyDateTime_GET_DAY(self)
121121

122122
@property
123-
cdef inline int hour(self):
123+
cdef inline int hour(self) noexcept:
124124
return PyDateTime_DATE_GET_HOUR(self)
125125

126126
@property
127-
cdef inline int minute(self):
127+
cdef inline int minute(self) noexcept:
128128
return PyDateTime_DATE_GET_MINUTE(self)
129129

130130
@property
131-
cdef inline int second(self):
131+
cdef inline int second(self) noexcept:
132132
return PyDateTime_DATE_GET_SECOND(self)
133133

134134
@property
135-
cdef inline int microsecond(self):
135+
cdef inline int microsecond(self) noexcept:
136136
return PyDateTime_DATE_GET_MICROSECOND(self)
137137

138138
@property
139139
cdef inline object tzinfo(self):
140140
return <object>PyDateTime_DATE_GET_TZINFO(self)
141141

142142
@property
143-
cdef inline int fold(self):
143+
cdef inline int fold(self) noexcept:
144144
# For Python < 3.6 this returns 0 no matter what
145145
return PyDateTime_DATE_GET_FOLD(self)
146146

147147
ctypedef extern class datetime.timedelta[object PyDateTime_Delta]:
148148
@property
149-
cdef inline int day(self):
149+
cdef inline int day(self) noexcept:
150150
return PyDateTime_DELTA_GET_DAYS(self)
151151

152152
@property
153-
cdef inline int second(self):
153+
cdef inline int second(self) noexcept:
154154
return PyDateTime_DELTA_GET_SECONDS(self)
155155

156156
@property
157-
cdef inline int microsecond(self):
157+
cdef inline int microsecond(self) noexcept:
158158
return PyDateTime_DELTA_GET_MICROSECONDS(self)
159159

160160
ctypedef extern class datetime.tzinfo[object PyDateTime_TZInfo]:
@@ -279,7 +279,7 @@ cdef extern from "datetime.h":
279279

280280
# Datetime C API initialization function.
281281
# You have to call it before any usage of DateTime CAPI functions.
282-
cdef inline void import_datetime():
282+
cdef inline void import_datetime() noexcept:
283283
PyDateTime_IMPORT
284284

285285
# Create date object using DateTime CAPI factory function.
@@ -337,84 +337,84 @@ cdef inline object datetime_tzinfo(object o):
337337
return <object>PyDateTime_DATE_GET_TZINFO(o)
338338

339339
# Get year of date
340-
cdef inline int date_year(object o):
340+
cdef inline int date_year(object o) noexcept:
341341
return PyDateTime_GET_YEAR(o)
342342

343343
# Get month of date
344-
cdef inline int date_month(object o):
344+
cdef inline int date_month(object o) noexcept:
345345
return PyDateTime_GET_MONTH(o)
346346

347347
# Get day of date
348-
cdef inline int date_day(object o):
348+
cdef inline int date_day(object o) noexcept:
349349
return PyDateTime_GET_DAY(o)
350350

351351
# Get year of datetime
352-
cdef inline int datetime_year(object o):
352+
cdef inline int datetime_year(object o) noexcept:
353353
return PyDateTime_GET_YEAR(o)
354354

355355
# Get month of datetime
356-
cdef inline int datetime_month(object o):
356+
cdef inline int datetime_month(object o) noexcept:
357357
return PyDateTime_GET_MONTH(o)
358358

359359
# Get day of datetime
360-
cdef inline int datetime_day(object o):
360+
cdef inline int datetime_day(object o) noexcept:
361361
return PyDateTime_GET_DAY(o)
362362

363363
# Get hour of time
364-
cdef inline int time_hour(object o):
364+
cdef inline int time_hour(object o) noexcept:
365365
return PyDateTime_TIME_GET_HOUR(o)
366366

367367
# Get minute of time
368-
cdef inline int time_minute(object o):
368+
cdef inline int time_minute(object o) noexcept:
369369
return PyDateTime_TIME_GET_MINUTE(o)
370370

371371
# Get second of time
372-
cdef inline int time_second(object o):
372+
cdef inline int time_second(object o) noexcept:
373373
return PyDateTime_TIME_GET_SECOND(o)
374374

375375
# Get microsecond of time
376-
cdef inline int time_microsecond(object o):
376+
cdef inline int time_microsecond(object o) noexcept:
377377
return PyDateTime_TIME_GET_MICROSECOND(o)
378378

379379
# Get fold of time
380-
cdef inline int time_fold(object o):
380+
cdef inline int time_fold(object o) noexcept:
381381
# For Python < 3.6 this returns 0 no matter what
382382
return PyDateTime_TIME_GET_FOLD(o)
383383

384384
# Get hour of datetime
385-
cdef inline int datetime_hour(object o):
385+
cdef inline int datetime_hour(object o) noexcept:
386386
return PyDateTime_DATE_GET_HOUR(o)
387387

388388
# Get minute of datetime
389-
cdef inline int datetime_minute(object o):
389+
cdef inline int datetime_minute(object o) noexcept:
390390
return PyDateTime_DATE_GET_MINUTE(o)
391391

392392
# Get second of datetime
393-
cdef inline int datetime_second(object o):
393+
cdef inline int datetime_second(object o) noexcept:
394394
return PyDateTime_DATE_GET_SECOND(o)
395395

396396
# Get microsecond of datetime
397-
cdef inline int datetime_microsecond(object o):
397+
cdef inline int datetime_microsecond(object o) noexcept:
398398
return PyDateTime_DATE_GET_MICROSECOND(o)
399399

400400
# Get fold of datetime
401-
cdef inline int datetime_fold(object o):
401+
cdef inline int datetime_fold(object o) noexcept:
402402
# For Python < 3.6 this returns 0 no matter what
403403
return PyDateTime_DATE_GET_FOLD(o)
404404

405405
# Get days of timedelta
406-
cdef inline int timedelta_days(object o):
406+
cdef inline int timedelta_days(object o) noexcept:
407407
return (<PyDateTime_Delta*>o).days
408408

409409
# Get seconds of timedelta
410-
cdef inline int timedelta_seconds(object o):
410+
cdef inline int timedelta_seconds(object o) noexcept:
411411
return (<PyDateTime_Delta*>o).seconds
412412

413413
# Get microseconds of timedelta
414-
cdef inline int timedelta_microseconds(object o):
414+
cdef inline int timedelta_microseconds(object o) noexcept:
415415
return (<PyDateTime_Delta*>o).microseconds
416416

417-
cdef inline double total_seconds(timedelta obj):
417+
cdef inline double total_seconds(timedelta obj) noexcept:
418418
# Mirrors the "timedelta.total_seconds()" method.
419419
# Note that this implementation is not guaranteed to give *exactly* the same
420420
# result as the original method, due to potential differences in floating point rounding.

Cython/Includes/cpython/time.pxd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ from libc.time cimport (
1717
)
1818

1919

20-
cdef inline double time() nogil:
20+
cdef inline double time() noexcept nogil:
2121
cdef:
2222
_PyTime_t tic
2323

0 commit comments

Comments
 (0)