from fastdebug.utils import *
from fastdebug.core import *
from fastcore.meta import *
04_rm_self
imports
from fastcore.meta import _rm_self
set up
= locals()
g = Fastdb(_rm_self, outloc = g) fdb
print() fdb.
========================================================= Investigating _rm_self =========================================================
============================================================== on line None ==============================================================
============================================================= with example ==============================================================
def _rm_self(sig):========================================================================(0)
sigd = dict(sig.parameters)===========================================================(1)
sigd.pop('self')======================================================================(2)
return sig.replace(parameters=sigd.values())==========================================(3)
(4)
class Foo:
def __init__(self, a, b:int=1): pass
__init__))
pprint(inspect.signature(Foo.__init__))) pprint(_rm_self(inspect.signature(Foo.
<Signature (self, a, b: int = 1)>
<Signature (a, b: int = 1)>
= """
fdb.eg class Foo:
def __init__(self, a, b:int=1): pass
pprint(inspect.signature(Foo.__init__))
pprint(_rm_self(inspect.signature(Foo.__init__)))
"""
document
0, "remove parameter self from a signature which has self;")
fdb.docsrc(1, "how to access parameters from a signature; how is parameters stored in sig; how to turn parameters into a dict;", \
fdb.docsrc("sig", "sig.parameters", "dict(sig.parameters)")
2, "how to remove the self parameter from the dict of sig;")
fdb.docsrc(3, "how to update a sig using a updated dict of sig's parameters", "sigd", "sigd.values()") fdb.docsrc(
========================================================= Investigating _rm_self =========================================================
=============================================================== on line 0 ================================================================
with example
class Foo:
def __init__(self, a, b:int=1): pass
pprint(inspect.signature(Foo.__init__))
pprint(_rm_self(inspect.signature(Foo.__init__)))
print selected srcline with expands below--------
def _rm_self(sig):======================================================================================================================================(0)
remove parameter self from a signature which has self;
sigd = dict(sig.parameters) (1)
sigd.pop('self') (2)
<Signature (self, a, b: int = 1)>
<Signature (a, b: int = 1)>
========================================================= Investigating _rm_self =========================================================
=============================================================== on line 1 ================================================================
with example
class Foo:
def __init__(self, a, b:int=1): pass
pprint(inspect.signature(Foo.__init__))
pprint(_rm_self(inspect.signature(Foo.__init__)))
print selected srcline with expands below--------
def _rm_self(sig): (0)
sigd = dict(sig.parameters)=========================================================================================================================(1)
how to access parameters from a signature; how is parameters stored in sig; how to turn parameters into a dict;
sigd.pop('self') (2)
return sig.replace(parameters=sigd.values()) (3)
<Signature (self, a, b: int = 1)>
==================================================================================================================Start of my srcline exploration:
sig => sig : (self, a, b: int = 1)
sig.parameters => sig.parameters : OrderedDict([('self', <Parameter "self">), ('a', <Parameter "a">), ('b', <Parameter "b: int = 1">)])
dict(sig.parameters) => dict(sig.parameters) : {'self': <Parameter "self">, 'a': <Parameter "a">, 'b': <Parameter "b: int = 1">}
====================================================================================================================End of my srcline exploration:
<Signature (a, b: int = 1)>
Review srcode with all comments added so far======================================================================================================
def _rm_self(sig):========================================================================(0) # remove parameter self from a signature which has self;;
sigd = dict(sig.parameters)===========================================================(1) # how to access parameters from a signature; how is parameters stored in sig; how to turn parameters into a dict;;
sigd.pop('self')======================================================================(2)
return sig.replace(parameters=sigd.values())==========================================(3)
(4)
part No.1 out of 1 parts
========================================================= Investigating _rm_self =========================================================
=============================================================== on line 2 ================================================================
with example
class Foo:
def __init__(self, a, b:int=1): pass
pprint(inspect.signature(Foo.__init__))
pprint(_rm_self(inspect.signature(Foo.__init__)))
print selected srcline with expands below--------
def _rm_self(sig): (0)
sigd = dict(sig.parameters) (1)
sigd.pop('self')====================================================================================================================================(2)
how to remove the self parameter from the dict of sig;
return sig.replace(parameters=sigd.values()) (3)
(4)
<Signature (self, a, b: int = 1)>
<Signature (a, b: int = 1)>
Review srcode with all comments added so far======================================================================================================
def _rm_self(sig):========================================================================(0) # remove parameter self from a signature which has self;;
sigd = dict(sig.parameters)===========================================================(1) # how to access parameters from a signature; how is parameters stored in sig; how to turn parameters into a dict;;
sigd.pop('self')======================================================================(2) # how to remove the self parameter from the dict of sig;;
return sig.replace(parameters=sigd.values())==========================================(3)
(4)
part No.1 out of 1 parts
========================================================= Investigating _rm_self =========================================================
=============================================================== on line 3 ================================================================
with example
class Foo:
def __init__(self, a, b:int=1): pass
pprint(inspect.signature(Foo.__init__))
pprint(_rm_self(inspect.signature(Foo.__init__)))
print selected srcline with expands below--------
sigd = dict(sig.parameters) (1)
sigd.pop('self') (2)
return sig.replace(parameters=sigd.values())========================================================================================================(3)
how to update a sig using a updated dict of sig's parameters
(4)
<Signature (self, a, b: int = 1)>
==================================================================================================================Start of my srcline exploration:
sigd => sigd : {'a': <Parameter "a">, 'b': <Parameter "b: int = 1">}
sigd.values() => sigd.values() : dict_values([<Parameter "a">, <Parameter "b: int = 1">])
====================================================================================================================End of my srcline exploration:
<Signature (a, b: int = 1)>
Review srcode with all comments added so far======================================================================================================
def _rm_self(sig):========================================================================(0) # remove parameter self from a signature which has self;;
sigd = dict(sig.parameters)===========================================================(1) # how to access parameters from a signature; how is parameters stored in sig; how to turn parameters into a dict;;
sigd.pop('self')======================================================================(2) # how to remove the self parameter from the dict of sig;;
return sig.replace(parameters=sigd.values())==========================================(3) # how to update a sig using a updated dict of sig's parameters;
(4)
part No.1 out of 1 parts
snoop
fdb.snoop()
06:38:56.81 >>> Call to _rm_self in File "/tmp/_rm_self.py", line 3
06:38:56.81 ...... sig = <Signature (self, a, b: int = 1)>
06:38:56.81 3 | def _rm_self(sig):
06:38:56.81 4 | sigd = dict(sig.parameters)
06:38:56.81 .......... sigd = {'self': <Parameter "self">, 'a': <Parameter "a">, 'b': <Parameter "b: int = 1">}
06:38:56.81 .......... len(sigd) = 3
06:38:56.81 5 | sigd.pop('self')
06:38:56.81 .......... sigd = {'a': <Parameter "a">, 'b': <Parameter "b: int = 1">}
06:38:56.81 .......... len(sigd) = 2
06:38:56.81 6 | return sig.replace(parameters=sigd.values())
06:38:56.81 <<< Return value from _rm_self: <Signature (a, b: int = 1)>
========================================================= Investigating _rm_self =========================================================
============================================================== on line None ==============================================================
with example
class Foo:
def __init__(self, a, b:int=1): pass
pprint(inspect.signature(Foo.__init__))
pprint(_rm_self(inspect.signature(Foo.__init__)))
<Signature (self, a, b: int = 1)>
<Signature (a, b: int = 1)>
print() fdb.
========================================================= Investigating _rm_self =========================================================
============================================================== on line None ==============================================================
with example
class Foo:
def __init__(self, a, b:int=1): pass
pprint(inspect.signature(Foo.__init__))
pprint(_rm_self(inspect.signature(Foo.__init__)))
def _rm_self(sig):========================================================================(0) # remove parameter self from a signature which has self;;
sigd = dict(sig.parameters)===========================================================(1) # how to access parameters from a signature; how is parameters stored in sig; how to turn parameters into a dict;;
sigd.pop('self')======================================================================(2) # how to remove the self parameter from the dict of sig;;
return sig.replace(parameters=sigd.values())==========================================(3) # how to update a sig using a updated dict of sig's parameters;
(4)