Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 221085d

Browse files
committed
Change all the function attributes from func_* -> __*__. This gets rid
of func_name, func_dict and func_doc as they already exist as __name__, __dict__ and __doc__.
1 parent 27d517b commit 221085d

37 files changed

Lines changed: 160 additions & 184 deletions

Doc/lib/libdis.tex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -622,7 +622,7 @@ \subsection{Python Byte Code Instructions}
622622
\end{opcodedesc}
623623

624624
\begin{opcodedesc}{MAKE_CLOSURE}{argc}
625-
Creates a new function object, sets its \var{func_closure} slot, and
625+
Creates a new function object, sets its \var{__closure__} slot, and
626626
pushes it on the stack. TOS is the code associated with the function.
627627
If the code object has N free variables, the next N items on the stack
628628
are the cells for these variables. The function also has \var{argc}

Doc/lib/libinspect.tex

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,9 @@ \subsection{Types and members
4545
\hline
4646
\lineiv{function}{__doc__}{documentation string}{}
4747
\lineiv{}{__name__}{name with which this function was defined}{}
48-
\lineiv{}{func_code}{code object containing compiled function bytecode}{}
49-
\lineiv{}{func_defaults}{tuple of any default values for arguments}{}
50-
\lineiv{}{func_doc}{(same as __doc__)}{}
51-
\lineiv{}{func_globals}{global namespace in which this function was defined}{}
52-
\lineiv{}{func_name}{(same as __name__)}{}
48+
\lineiv{}{__code__}{code object containing compiled function bytecode}{}
49+
\lineiv{}{__defaults__}{tuple of any default values for arguments}{}
50+
\lineiv{}{__globals__}{global namespace in which this function was defined}{}
5351
\hline
5452
\lineiv{traceback}{tb_frame}{frame object at this level}{}
5553
\lineiv{}{tb_lasti}{index of last attempted instruction in bytecode}{}

Doc/lib/libstdtypes.tex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1964,10 +1964,10 @@ \subsection{Code Objects \label{bltin-code-objects}}
19641964
They differ from function objects because they don't contain a
19651965
reference to their global execution environment. Code objects are
19661966
returned by the built-in \function{compile()} function and can be
1967-
extracted from function objects through their \member{func_code}
1967+
extracted from function objects through their \member{__code__}
19681968
attribute.
19691969
\bifuncindex{compile}
1970-
\withsubitem{(function object attribute)}{\ttindex{func_code}}
1970+
\withsubitem{(function object attribute)}{\ttindex{__code__}}
19711971

19721972
A code object can be executed or evaluated by passing it (instead of a
19731973
source string) to the \function{exec()} or \function{eval()}

Doc/ref/ref3.tex

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -473,42 +473,42 @@ \section{The standard type hierarchy\label{types}}
473473
Special attributes:
474474

475475
\begin{tableiii}{lll}{member}{Attribute}{Meaning}{}
476-
\lineiii{func_doc}{The function's documentation string, or
476+
\lineiii{__doc__}{The function's documentation string, or
477477
\code{None} if unavailable}{Writable}
478478

479-
\lineiii{__doc__}{Another way of spelling
480-
\member{func_doc}}{Writable}
481-
482-
\lineiii{func_name}{The function's name}{Writable}
483-
484-
\lineiii{__name__}{Another way of spelling
485-
\member{func_name}}{Writable}
479+
\lineiii{__name__}{The function's name}{Writable}
486480

487481
\lineiii{__module__}{The name of the module the function was defined
488482
in, or \code{None} if unavailable.}{Writable}
489483

490-
\lineiii{func_defaults}{A tuple containing default argument values
484+
\lineiii{__defaults__}{A tuple containing default argument values
491485
for those arguments that have defaults, or \code{None} if no
492486
arguments have a default value}{Writable}
493487

494-
\lineiii{func_code}{The code object representing the compiled
488+
\lineiii{__code__}{The code object representing the compiled
495489
function body.}{Writable}
496490

497-
\lineiii{func_globals}{A reference to the dictionary that holds the
491+
\lineiii{__globals__}{A reference to the dictionary that holds the
498492
function's global variables --- the global namespace of the module
499493
in which the function was defined.}{Read-only}
500494

501-
\lineiii{func_dict}{The namespace supporting arbitrary function
495+
\lineiii{__dict__}{The namespace supporting arbitrary function
502496
attributes.}{Writable}
503497

504-
\lineiii{func_closure}{\code{None} or a tuple of cells that contain
498+
\lineiii{__closure__}{\code{None} or a tuple of cells that contain
505499
bindings for the function's free variables.}{Read-only}
500+
501+
\lineiii{__annotations__}{A dict containing annotations of parameters.}
502+
{Writable}
503+
504+
\lineiii{__kwdefaults__}{A dict containing defaults for keyword-only
505+
parameters.}{Writable}
506506
\end{tableiii}
507507

508508
Most of the attributes labelled ``Writable'' check the type of the
509509
assigned value.
510510

511-
\versionchanged[\code{func_name} is now writable]{2.4}
511+
\versionchanged[\code{__name__} is now writable]{2.4}
512512

513513
Function objects also support getting and setting arbitrary
514514
attributes, which can be used, for example, to attach metadata to
@@ -521,16 +521,16 @@ \section{The standard type hierarchy\label{types}}
521521
from its code object; see the description of internal types below.
522522

523523
\withsubitem{(function attribute)}{
524-
\ttindex{func_doc}
525524
\ttindex{__doc__}
526525
\ttindex{__name__}
527526
\ttindex{__module__}
528527
\ttindex{__dict__}
529-
\ttindex{func_defaults}
530-
\ttindex{func_closure}
531-
\ttindex{func_code}
532-
\ttindex{func_globals}
533-
\ttindex{func_dict}}
528+
\ttindex{__defaults__}
529+
\ttindex{__closure__}
530+
\ttindex{__code__}
531+
\ttindex{__globals__}
532+
\ttindex{__annotations__}
533+
\ttindex{__kwdefaults__}
534534
\indexii{global}{namespace}
535535

536536
\item[User-defined methods]
@@ -700,7 +700,7 @@ \section{The standard type hierarchy\label{types}}
700700
section~\ref{import}, ``The \keyword{import} statement'').%
701701
\stindex{import}\obindex{module}
702702
A module object has a namespace implemented by a dictionary object
703-
(this is the dictionary referenced by the func_globals attribute of
703+
(this is the dictionary referenced by the __globals__ attribute of
704704
functions defined in the module). Attribute references are translated
705705
to lookups in this dictionary, e.g., \code{m.x} is equivalent to
706706
\code{m.__dict__["x"]}.

Lib/Bastion.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ def total(self):
158158
else:
159159
print "accessible"
160160
try:
161-
print "b._get_.func_defaults =", map(type, b._get_.func_defaults),
161+
print "b._get_.__defaults__ =", map(type, b._get_.__defaults__),
162162
except:
163163
print "inaccessible"
164164
else:

Lib/dis.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ def dis(x=None):
2020
return
2121
if hasattr(x, 'im_func'):
2222
x = x.im_func
23-
if hasattr(x, 'func_code'):
24-
x = x.func_code
23+
if hasattr(x, '__code__'):
24+
x = x.__code__
2525
if hasattr(x, '__dict__'):
2626
items = x.__dict__.items()
2727
items.sort()

Lib/doctest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -831,7 +831,7 @@ def _from_module(self, module, object):
831831
if module is None:
832832
return True
833833
elif inspect.isfunction(object):
834-
return module.__dict__ is object.func_globals
834+
return module.__dict__ is object.__globals__
835835
elif inspect.isclass(object):
836836
return module.__name__ == object.__module__
837837
elif inspect.getmodule(object) is not None:
@@ -969,7 +969,7 @@ def _find_lineno(self, obj, source_lines):
969969

970970
# Find the line number for functions & methods.
971971
if inspect.ismethod(obj): obj = obj.im_func
972-
if inspect.isfunction(obj): obj = obj.func_code
972+
if inspect.isfunction(obj): obj = obj.__code__
973973
if inspect.istraceback(obj): obj = obj.tb_frame
974974
if inspect.isframe(obj): obj = obj.f_code
975975
if inspect.iscode(obj):

Lib/idlelib/CallTips.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -147,15 +147,15 @@ def get_arg_text(ob):
147147
fob = ob
148148
# Try to build one for Python defined functions
149149
if type(fob) in [types.FunctionType, types.LambdaType]:
150-
argcount = fob.func_code.co_argcount
151-
real_args = fob.func_code.co_varnames[arg_offset:argcount]
152-
defaults = fob.func_defaults or []
150+
argcount = fob.__code__.co_argcount
151+
real_args = fob.__code__.co_varnames[arg_offset:argcount]
152+
defaults = fob.__defaults__ or []
153153
defaults = list(map(lambda name: "=%s" % repr(name), defaults))
154154
defaults = [""] * (len(real_args) - len(defaults)) + defaults
155155
items = map(lambda arg, dflt: arg + dflt, real_args, defaults)
156-
if fob.func_code.co_flags & 0x4:
156+
if fob.__code__.co_flags & 0x4:
157157
items.append("...")
158-
if fob.func_code.co_flags & 0x8:
158+
if fob.__code__.co_flags & 0x8:
159159
items.append("***")
160160
arg_text = ", ".join(items)
161161
arg_text = "(%s)" % re.sub("\.\d+", "<tuple>", arg_text)

Lib/inspect.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"""Get useful information from live Python objects.
33
44
This module encapsulates the interface provided by the internal special
5-
attributes (func_*, co_*, im_*, tb_*, etc.) in a friendlier fashion.
5+
attributes (co_*, im_*, tb_*, etc.) in a friendlier fashion.
66
It also provides some help for examining source code and class layout.
77
88
Here are some of the useful functions provided by this module:
@@ -129,11 +129,11 @@ def isfunction(object):
129129
Function objects provide these attributes:
130130
__doc__ documentation string
131131
__name__ name with which this function was defined
132-
func_code code object containing compiled function bytecode
133-
func_defaults tuple of any default values for arguments
134-
func_doc (same as __doc__)
135-
func_globals global namespace in which this function was defined
136-
func_name (same as __name__)"""
132+
__code__ code object containing compiled function bytecode
133+
__defaults__ tuple of any default values for arguments
134+
__globals__ global namespace in which this function was defined
135+
__annotations__ dict of parameter annotations
136+
__kwdefaults__ dict of keyword only parameters with defaults"""
137137
return isinstance(object, types.FunctionType)
138138

139139
def istraceback(object):
@@ -353,7 +353,7 @@ def getfile(object):
353353
if ismethod(object):
354354
object = object.im_func
355355
if isfunction(object):
356-
object = object.func_code
356+
object = object.__code__
357357
if istraceback(object):
358358
object = object.tb_frame
359359
if isframe(object):
@@ -496,7 +496,7 @@ def findsource(object):
496496
if ismethod(object):
497497
object = object.im_func
498498
if isfunction(object):
499-
object = object.func_code
499+
object = object.__code__
500500
if istraceback(object):
501501
object = object.tb_frame
502502
if isframe(object):
@@ -741,8 +741,8 @@ def getargspec(func):
741741
func = func.im_func
742742
if not isfunction(func):
743743
raise TypeError('arg is not a Python function')
744-
args, varargs, varkw = getargs(func.func_code)
745-
return args, varargs, varkw, func.func_defaults
744+
args, varargs, varkw = getargs(func.__code__)
745+
return args, varargs, varkw, func.__defaults__
746746

747747
def getargvalues(frame):
748748
"""Get information about arguments passed into a particular frame.

Lib/pdb.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ def handle_command_def(self,line):
262262
func = getattr(self, 'do_' + cmd)
263263
except AttributeError:
264264
func = self.default
265-
if func.func_name in self.commands_resuming : # one of the resuming commands.
265+
if func.__name__ in self.commands_resuming : # one of the resuming commands.
266266
self.commands_doprompt[self.commands_bnum] = False
267267
self.cmdqueue = []
268268
return 1
@@ -347,7 +347,7 @@ def do_break(self, arg, temporary = 0):
347347
try:
348348
if hasattr(func, 'im_func'):
349349
func = func.im_func
350-
code = func.func_code
350+
code = func.__code__
351351
#use co_name to identify the bkpt (function names
352352
#could be aliased, but co_name is invariant)
353353
funcname = code.co_name
@@ -759,13 +759,13 @@ def do_whatis(self, arg):
759759
return
760760
code = None
761761
# Is it a function?
762-
try: code = value.func_code
762+
try: code = value.__code__
763763
except: pass
764764
if code:
765765
print('Function', code.co_name, file=self.stdout)
766766
return
767767
# Is it an instance method?
768-
try: code = value.im_func.func_code
768+
try: code = value.im_func.__code__
769769
except: pass
770770
if code:
771771
print('Method', code.co_name, file=self.stdout)

0 commit comments

Comments
 (0)