Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc09d4c4

Browse files
authored
gh-119698: deprecatesymtable.Class.get_methods (#121902)
1 parentdc93d11 commitc09d4c4

File tree

5 files changed

+53
-16
lines changed

5 files changed

+53
-16
lines changed

‎Doc/library/symtable.rst‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,19 @@ Examining Symbol Tables
191191

192192
For example:
193193

194+
..testsetup::symtable.Class.get_methods
195+
196+
import warnings
197+
context = warnings.catch_warnings()
198+
context.__enter__()
199+
warnings.simplefilter("ignore", category=DeprecationWarning)
200+
201+
..testcleanup::symtable.Class.get_methods
202+
203+
context.__exit__()
204+
205+
..doctest::symtable.Class.get_methods
206+
194207
>>>import symtable
195208
>>>st= symtable.symtable('''
196209
...defouter():pass
@@ -214,6 +227,9 @@ Examining Symbol Tables
214227
Although ``A().f()`` raises:exc:`TypeError` at runtime, ``A.f`` is still
215228
considered as a method-like function.
216229

230+
..deprecated-removed::3.14 3.16
231+
232+
217233
..class::Symbol
218234

219235
An entry in a:class:`SymbolTable` corresponding to an identifier in the

‎Doc/whatsnew/3.14.rst‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,9 @@ Deprecated
183183
write new code. The:mod:`subprocess` module is recommended instead.
184184
(Contributed by Victor Stinner in:gh:`120743`.)
185185

186+
* Deprecate:meth:`symtable.Class.get_methods` due to the lack of interest.
187+
(Contributed by Bénédikt Tran in:gh:`119698`.)
188+
186189

187190
Removed
188191
=======

‎Lib/symtable.py‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,12 @@ class Class(SymbolTable):
237237
defget_methods(self):
238238
"""Return a tuple of methods declared in the class.
239239
"""
240+
importwarnings
241+
typename=f'{self.__class__.__module__}.{self.__class__.__name__}'
242+
warnings.warn(f'{typename}.get_methods() is deprecated '
243+
f'and will be removed in Python 3.16.',
244+
DeprecationWarning,stacklevel=2)
245+
240246
ifself.__methodsisNone:
241247
d= {}
242248

‎Lib/test/test_symtable.py‎

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
Test the API of the symtable module.
33
"""
44

5+
importre
56
importtextwrap
67
importsymtable
78
importunittest
@@ -359,25 +360,32 @@ def test_name(self):
359360
self.assertEqual(self.Mine.get_name(),"Mine")
360361

361362
deftest_class_get_methods(self):
362-
self.assertEqual(self.Mine.get_methods(), ('a_method',))
363+
deprecation_mess= (
364+
re.escape('symtable.Class.get_methods() is deprecated '
365+
'and will be removed in Python 3.16.')
366+
)
367+
368+
withself.assertWarnsRegex(DeprecationWarning,deprecation_mess):
369+
self.assertEqual(self.Mine.get_methods(), ('a_method',))
363370

364371
top=symtable.symtable(TEST_COMPLEX_CLASS_CODE,"?","exec")
365372
this=find_block(top,"ComplexClass")
366373

367-
self.assertEqual(this.get_methods(), (
368-
'a_method','a_method_pep_695',
369-
'an_async_method','an_async_method_pep_695',
370-
'a_classmethod','a_classmethod_pep_695',
371-
'an_async_classmethod','an_async_classmethod_pep_695',
372-
'a_staticmethod','a_staticmethod_pep_695',
373-
'an_async_staticmethod','an_async_staticmethod_pep_695',
374-
'a_fakemethod','a_fakemethod_pep_695',
375-
'an_async_fakemethod','an_async_fakemethod_pep_695',
376-
'glob_unassigned_meth','glob_unassigned_meth_pep_695',
377-
'glob_unassigned_async_meth','glob_unassigned_async_meth_pep_695',
378-
'glob_assigned_meth','glob_assigned_meth_pep_695',
379-
'glob_assigned_async_meth','glob_assigned_async_meth_pep_695',
380-
))
374+
withself.assertWarnsRegex(DeprecationWarning,deprecation_mess):
375+
self.assertEqual(this.get_methods(), (
376+
'a_method','a_method_pep_695',
377+
'an_async_method','an_async_method_pep_695',
378+
'a_classmethod','a_classmethod_pep_695',
379+
'an_async_classmethod','an_async_classmethod_pep_695',
380+
'a_staticmethod','a_staticmethod_pep_695',
381+
'an_async_staticmethod','an_async_staticmethod_pep_695',
382+
'a_fakemethod','a_fakemethod_pep_695',
383+
'an_async_fakemethod','an_async_fakemethod_pep_695',
384+
'glob_unassigned_meth','glob_unassigned_meth_pep_695',
385+
'glob_unassigned_async_meth','glob_unassigned_async_meth_pep_695',
386+
'glob_assigned_meth','glob_assigned_meth_pep_695',
387+
'glob_assigned_async_meth','glob_assigned_async_meth_pep_695',
388+
))
381389

382390
# Test generator expressions that are of type TYPE_FUNCTION
383391
# but will not be reported by get_methods() since they are
@@ -390,7 +398,8 @@ def check_body(body, expected_methods):
390398
indented=textwrap.indent(body,' '*4)
391399
top=symtable.symtable(f"class A:\n{indented}","?","exec")
392400
this=find_block(top,"A")
393-
self.assertEqual(this.get_methods(),expected_methods)
401+
withself.assertWarnsRegex(DeprecationWarning,deprecation_mess):
402+
self.assertEqual(this.get_methods(),expected_methods)
394403

395404
# statements with 'genexpr' inside it
396405
GENEXPRS= (
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Due to the lack of interest for:meth:`symtable.Class.get_methods`, the
2+
method is marked as deprecated and will be removed in Python 3.16. Patch by
3+
Bénédikt Tran.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp