[doc] add scope introduction and examples

This commit is contained in:
Jimmy Lai 2019-09-16 17:48:21 -07:00 committed by jimmylai
parent ec68bdb147
commit b4851a60a1
3 changed files with 330 additions and 19 deletions

View file

@ -0,0 +1,285 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="132.62682mm"
height="103.25121mm"
viewBox="0 0 132.62682 103.2512"
version="1.1"
id="svg8"
inkscape:version="0.92.4 (5da689c313, 2019-01-14)"
sodipodi:docname="python-scopes.svg"
inkscape:export-filename="/home/bgw/Documents/lint-docs-pycon/python-scopes.png"
inkscape:export-xdpi="200.09"
inkscape:export-ydpi="200.09"
enable-background="new">
<defs
id="defs2">
<filter
inkscape:collect="always"
style="color-interpolation-filters:sRGB"
id="filter862">
<feBlend
inkscape:collect="always"
mode="lighten"
in2="BackgroundImage"
id="feBlend864" />
</filter>
</defs>
<sodipodi:namedview
id="base"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1.0"
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:zoom="0.7071068"
inkscape:cx="114.72171"
inkscape:cy="244.35769"
inkscape:document-units="mm"
inkscape:current-layer="layer2"
showgrid="false"
inkscape:window-width="1574"
inkscape:window-height="978"
inkscape:window-x="474"
inkscape:window-y="327"
inkscape:window-maximized="0" />
<metadata
id="metadata5">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title />
</cc:Work>
</rdf:RDF>
</metadata>
<g
inkscape:groupmode="layer"
id="layer2"
inkscape:label="Layer 2"
transform="translate(-5.9299994,-39.669584)"
style="filter:url(#filter862)">
<rect
style="opacity:1;fill:#b8d9f8;fill-opacity:1;stroke:#3e99ed;stroke-width:0.84;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1"
id="rect846"
width="131.78682"
height="102.41121"
x="6.3499994"
y="40.089584" />
<rect
style="opacity:1;fill:#e7c2ee;fill-opacity:1;stroke:#a132b8;stroke-width:0.83999997;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1"
id="rect846-3"
width="127.44389"
height="79.862946"
x="8.0697889"
y="52.789581" />
<rect
style="opacity:1;fill:#f7b9be;fill-opacity:1;stroke:#eb4b59;stroke-width:0.83999997;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;paint-order:normal"
id="rect846-3-9"
width="112.51761"
height="56.470001"
x="20.108335"
y="73.691681" />
<g
id="g851"
transform="translate(5.4713964,-0.41999999)">
<rect
y="40.089584"
x="94.592438"
height="8.467"
width="38.492985"
id="rect846-9"
style="opacity:1;fill:#3e99ed;fill-opacity:1;stroke:none;stroke-width:0.21471134;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:0.64413405, 0.21471134;stroke-dashoffset:0;stroke-opacity:1" />
<text
id="text880"
y="45.703152"
x="130.23187"
style="font-style:normal;font-variant:normal;font-weight:300;font-stretch:normal;font-size:5.64444447px;line-height:125%;font-family:'Source Sans Pro';-inkscape-font-specification:'Source Sans Pro Light';text-align:end;letter-spacing:0px;word-spacing:0px;text-anchor:end;fill:#ffffff;fill-opacity:1;stroke:none;stroke-width:0.26458332px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
xml:space="preserve"><tspan
style="font-style:normal;font-variant:normal;font-weight:500;font-stretch:normal;font-family:'Helvetica Neue';-inkscape-font-specification:'Helvetica Neue Medium';text-align:end;text-anchor:end;fill:#ffffff;fill-opacity:1;stroke-width:0.26458332px"
y="45.703152"
x="130.23187"
id="tspan878"
sodipodi:role="line">global scope</tspan></text>
</g>
<g
id="g841"
transform="translate(5.0972261,-2.5366649)">
<rect
y="54.906246"
x="95.938049"
height="8.467"
width="34.898407"
id="rect846-3-0"
style="opacity:1;fill:#a132b8;fill-opacity:1;stroke:none;stroke-width:0.20444053;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:0.61332162, 0.20444055;stroke-dashoffset:0;stroke-opacity:1" />
<text
id="text880-4"
y="60.584724"
x="128.49477"
style="font-style:normal;font-variant:normal;font-weight:500;font-stretch:normal;font-size:5.64444447px;line-height:125%;font-family:'Helvetica Neue';-inkscape-font-specification:'Helvetica Neue Medium';font-variant-ligatures:normal;font-variant-position:normal;font-variant-caps:normal;font-variant-numeric:normal;font-variant-alternates:normal;font-feature-settings:normal;text-indent:0;text-align:end;text-decoration:none;text-decoration-line:none;text-decoration-style:solid;text-decoration-color:#000000;letter-spacing:0px;word-spacing:0px;text-transform:none;writing-mode:lr-tb;direction:ltr;text-orientation:mixed;dominant-baseline:auto;baseline-shift:baseline;text-anchor:end;white-space:normal;shape-padding:0;opacity:1;vector-effect:none;fill:#ffffff;fill-opacity:1;stroke:none;stroke-width:0.26458332px;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1"
xml:space="preserve"><tspan
style="font-style:normal;font-variant:normal;font-weight:500;font-stretch:normal;font-size:5.64444447px;line-height:125%;font-family:'Helvetica Neue';-inkscape-font-specification:'Helvetica Neue Medium';font-variant-ligatures:normal;font-variant-position:normal;font-variant-caps:normal;font-variant-numeric:normal;font-variant-alternates:normal;font-feature-settings:normal;text-indent:0;text-align:end;text-decoration:none;text-decoration-line:none;text-decoration-style:solid;text-decoration-color:#000000;letter-spacing:0px;word-spacing:0px;text-transform:none;writing-mode:lr-tb;direction:ltr;text-orientation:mixed;dominant-baseline:auto;baseline-shift:baseline;text-anchor:end;white-space:normal;shape-padding:0;vector-effect:none;fill:#ffffff;fill-opacity:1;stroke:none;stroke-width:0.26458332px;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1"
y="60.584724"
x="128.49477"
id="tspan878-5"
sodipodi:role="line">class scope</tspan></text>
</g>
<g
id="g846"
transform="translate(4.72303,-0.41999999)">
<rect
y="73.691681"
x="84.802856"
height="8.4666672"
width="43.520058"
id="rect846-3-9-9"
style="opacity:1;fill:#eb4b59;fill-opacity:1;stroke:none;stroke-width:0.22829711;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:0.68489136, 0.22829713;stroke-dashoffset:0;stroke-opacity:1" />
<text
transform="scale(1.0012369,0.99876463)"
id="text880-2"
y="79.502075"
x="125.36142"
style="font-style:normal;font-variant:normal;font-weight:500;font-stretch:normal;font-size:5.64444447px;line-height:125%;font-family:'Helvetica Neue';-inkscape-font-specification:'Helvetica Neue Medium';font-variant-ligatures:normal;font-variant-position:normal;font-variant-caps:normal;font-variant-numeric:normal;font-variant-alternates:normal;font-feature-settings:normal;text-indent:0;text-align:end;text-decoration:none;text-decoration-line:none;text-decoration-style:solid;text-decoration-color:#000000;letter-spacing:0px;word-spacing:0px;text-transform:none;writing-mode:lr-tb;direction:ltr;text-orientation:mixed;dominant-baseline:auto;baseline-shift:baseline;text-anchor:end;white-space:normal;shape-padding:0;opacity:1;vector-effect:none;fill:#ffffff;fill-opacity:1;stroke:none;stroke-width:0.26458332px;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1"
xml:space="preserve"><tspan
style="font-style:normal;font-variant:normal;font-weight:500;font-stretch:normal;font-size:5.64444447px;line-height:125%;font-family:'Helvetica Neue';-inkscape-font-specification:'Helvetica Neue Medium';font-variant-ligatures:normal;font-variant-position:normal;font-variant-caps:normal;font-variant-numeric:normal;font-variant-alternates:normal;font-feature-settings:normal;text-indent:0;text-align:end;text-decoration:none;text-decoration-line:none;text-decoration-style:solid;text-decoration-color:#000000;letter-spacing:0px;word-spacing:0px;text-transform:none;writing-mode:lr-tb;direction:ltr;text-orientation:mixed;dominant-baseline:auto;baseline-shift:baseline;text-anchor:end;white-space:normal;shape-padding:0;vector-effect:none;fill:#ffffff;fill-opacity:1;stroke:none;stroke-width:0.26458332px;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1"
y="79.502075"
x="125.36142"
id="tspan878-0"
sodipodi:role="line">function scope</tspan></text>
</g>
<rect
style="opacity:1;fill:#fdd2b3;fill-opacity:1;stroke:#fb8d3f;stroke-width:0.83999997;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;paint-order:normal"
id="rect846-3-9-3"
width="95.492546"
height="26.722916"
x="34.081287"
y="101.19372" />
<g
id="g846-6"
transform="translate(1.6709308,27.08203)">
<rect
y="73.691681"
x="65.532722"
height="8.4666672"
width="62.79018"
id="rect846-3-9-9-7"
style="opacity:1;fill:#fb8d3f;fill-opacity:1;stroke:none;stroke-width:0.23110457;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:0.69331375, 0.23110459;stroke-dashoffset:0;stroke-opacity:1" />
<text
transform="scale(1.0012369,0.99876463)"
id="text880-2-5"
y="79.502075"
x="125.36142"
style="font-style:normal;font-variant:normal;font-weight:500;font-stretch:normal;font-size:5.64444447px;line-height:125%;font-family:'Helvetica Neue';-inkscape-font-specification:'Helvetica Neue Medium';font-variant-ligatures:normal;font-variant-position:normal;font-variant-caps:normal;font-variant-numeric:normal;font-variant-alternates:normal;font-feature-settings:normal;text-indent:0;text-align:end;text-decoration:none;text-decoration-line:none;text-decoration-style:solid;text-decoration-color:#000000;letter-spacing:0px;word-spacing:0px;text-transform:none;writing-mode:lr-tb;direction:ltr;text-orientation:mixed;dominant-baseline:auto;baseline-shift:baseline;text-anchor:end;white-space:normal;shape-padding:0;opacity:1;vector-effect:none;fill:#ffffff;fill-opacity:1;stroke:none;stroke-width:0.26458332px;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1"
xml:space="preserve"><tspan
style="font-style:normal;font-variant:normal;font-weight:500;font-stretch:normal;font-size:5.64444447px;line-height:125%;font-family:'Helvetica Neue';-inkscape-font-specification:'Helvetica Neue Medium';font-variant-ligatures:normal;font-variant-position:normal;font-variant-caps:normal;font-variant-numeric:normal;font-variant-alternates:normal;font-feature-settings:normal;text-indent:0;text-align:end;text-decoration:none;text-decoration-line:none;text-decoration-style:solid;text-decoration-color:#000000;letter-spacing:0px;word-spacing:0px;text-transform:none;writing-mode:lr-tb;direction:ltr;text-orientation:mixed;dominant-baseline:auto;baseline-shift:baseline;text-anchor:end;white-space:normal;shape-padding:0;vector-effect:none;fill:#ffffff;fill-opacity:1;stroke:none;stroke-width:0.26458332px;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1"
y="79.502075"
x="125.36142"
id="tspan878-0-3"
sodipodi:role="line">comprehension scope</tspan></text>
</g>
</g>
<g
inkscape:label="Layer 1"
inkscape:groupmode="layer"
id="layer1"
transform="translate(-5.9299994,-39.669584)"
sodipodi:insensitive="true">
<text
xml:space="preserve"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:5.64444447px;line-height:125%;font-family:'Source Sans Pro';-inkscape-font-specification:'Source Sans Pro';letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.26458332px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
x="14.287499"
y="18.393749"
id="text817"><tspan
sodipodi:role="line"
id="tspan815"
x="14.287499"
y="23.332638"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-family:'Source Sans Pro';-inkscape-font-specification:'Source Sans Pro';stroke-width:0.26458332px" /></text>
<text
xml:space="preserve"
style="font-style:normal;font-variant:normal;font-weight:300;font-stretch:normal;font-size:5.64444447px;line-height:125%;font-family:'Source Sans Pro';-inkscape-font-specification:'Source Sans Pro Light';letter-spacing:0px;word-spacing:0px;fill:#1c1e20;fill-opacity:1;stroke:none;stroke-width:0.26458332px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
x="9.260417"
y="47.233334"
id="text821"><tspan
sodipodi:role="line"
x="9.260417"
y="47.233334"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-family:'Source Code Pro';-inkscape-font-specification:'Source Code Pro';fill:#1c1e20;fill-opacity:1;stroke-width:0.26458332px"
id="tspan823">ITERATIONS = 10</tspan><tspan
sodipodi:role="line"
x="9.260417"
y="54.288891"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-family:'Source Code Pro';-inkscape-font-specification:'Source Code Pro';fill:#1c1e20;fill-opacity:1;stroke-width:0.26458332px"
id="tspan837" /><tspan
sodipodi:role="line"
x="9.260417"
y="61.344444"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-family:'Source Code Pro';-inkscape-font-specification:'Source Code Pro';fill:#1c1e20;fill-opacity:1;stroke-width:0.26458332px"
id="tspan843">class Cls:</tspan><tspan
sodipodi:role="line"
x="9.260417"
y="68.400002"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-family:'Source Code Pro';-inkscape-font-specification:'Source Code Pro';fill:#1c1e20;fill-opacity:1;stroke-width:0.26458332px"
id="tspan939"> class_attribute = 20</tspan><tspan
sodipodi:role="line"
x="9.260417"
y="75.455559"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-family:'Source Code Pro';-inkscape-font-specification:'Source Code Pro';fill:#1c1e20;fill-opacity:1;stroke-width:0.26458332px"
id="tspan918" /><tspan
sodipodi:role="line"
x="9.260417"
y="82.511108"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-family:'Source Code Pro';-inkscape-font-specification:'Source Code Pro';fill:#1c1e20;fill-opacity:1;stroke-width:0.26458332px"
id="tspan827"> def fn():</tspan><tspan
sodipodi:role="line"
x="9.260417"
y="89.566666"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-family:'Source Code Pro';-inkscape-font-specification:'Source Code Pro';fill:#1c1e20;fill-opacity:1;stroke-width:0.26458332px"
id="tspan829"> for i in range(ITERATIONS):</tspan><tspan
sodipodi:role="line"
x="9.260417"
y="96.622223"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-family:'Source Code Pro';-inkscape-font-specification:'Source Code Pro';fill:#1c1e20;fill-opacity:1;stroke-width:0.26458332px"
id="tspan831"> ...</tspan><tspan
sodipodi:role="line"
x="9.260417"
y="103.67778"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-family:'Source Code Pro';-inkscape-font-specification:'Source Code Pro';fill:#1c1e20;fill-opacity:1;stroke-width:0.26458332px"
id="tspan876" /><tspan
sodipodi:role="line"
x="9.260417"
y="110.73334"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-family:'Source Code Pro';-inkscape-font-specification:'Source Code Pro';fill:#1c1e20;fill-opacity:1;stroke-width:0.26458332px"
id="tspan833"> return [</tspan><tspan
sodipodi:role="line"
x="9.260417"
y="117.78889"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-family:'Source Code Pro';-inkscape-font-specification:'Source Code Pro';fill:#1c1e20;fill-opacity:1;stroke-width:0.26458332px"
id="tspan870"> i for i in range(10)</tspan><tspan
sodipodi:role="line"
x="9.260417"
y="124.84444"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-family:'Source Code Pro';-inkscape-font-specification:'Source Code Pro';fill:#1c1e20;fill-opacity:1;stroke-width:0.26458332px"
id="tspan872"> ]</tspan><tspan
sodipodi:role="line"
x="9.260417"
y="131.89999"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-family:'Source Code Pro';-inkscape-font-specification:'Source Code Pro';fill:#1c1e20;fill-opacity:1;stroke-width:0.26458332px"
id="tspan879" /><tspan
sodipodi:role="line"
x="9.260417"
y="138.95555"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-family:'Source Code Pro';-inkscape-font-specification:'Source Code Pro';fill:#1c1e20;fill-opacity:1;stroke-width:0.26458332px"
id="tspan841">Cls().fn()</tspan></text>
</g>
</svg>

After

Width:  |  Height:  |  Size: 19 KiB

View file

@ -67,7 +67,6 @@ your provider does not use the visitor pattern for computing metadata for a tree
Metadata Providers
------------------
Position Metadata
-----------------
@ -78,8 +77,8 @@ Accessing position metadata through the :class:`~libcst.MetadataDepedent`
interface will return a :class:`~libcst.CodeRange` object. See
:ref:`the above example<libcst-metadata-position-example>`.
.. autoclass:: libcst.BasicPositionProvider
.. autoclass:: libcst.SyntacticPositionProvider
.. autoclass:: libcst.metadata.BasicPositionProvider
.. autoclass:: libcst.metadata.SyntacticPositionProvider
.. autoclass:: libcst.CodeRange
.. autoclass:: libcst.CodePosition
@ -87,30 +86,57 @@ interface will return a :class:`~libcst.CodeRange` object. See
Expression Context Metadata
---------------------------
.. autoclass:: libcst.ExpressionContextProvider
.. autoclass:: libcst.metadata.ExpressionContextProvider
:no-undoc-members:
.. autoclass:: libcst.ExpressionContext
.. autoclass:: libcst.metadata.ExpressionContext
Scope Metadata
--------------
.. autoclass:: libcst.ScopeProvider
Scope is the block of naming binding. The bind name is not available
after existing the bind block. Pyhon is
`function-scoped <https://en.wikipedia.org/wiki/Scope_(computer_science)#Function_scope>`_.
New scopes are created for classes and functions, but not other block constructs like
conditional statements, loops, or try…except, don't create their own scope. E.g.::
ITERATIONS = 10
class Cls:
class_attribute = 20
def fn():
for i in range(ITERATIONS):
...
return [
i for i in range(10)
]
Cls().fn()
The scopes of each name assignments and class/function definitinos are visualized:
.. image:: _static/img/python_scopes.svg
:alt: LibCST
There were four different type of scope in Python: :class:`libcst.metadata.GlobalScope`,
:class:`libcst.metadata.ClassScope`, :class:`libcst.metadata.FunctionScope` and
:class:`libcst.metadata.ComprehensionScope`.
.. autoclass:: libcst.metadata.ScopeProvider
:no-undoc-members:
.. autoclass:: libcst.BaseAssignment
.. autoclass:: libcst.metadata.BaseAssignment
:no-undoc-members:
.. autoclass:: libcst.Access
.. autoclass:: libcst.Assignment
.. autoclass:: libcst.BuiltinAssignmemt
.. autoclass:: libcst.metadata.Access
.. autoclass:: libcst.metadata.Assignment
.. autoclass:: libcst.metadata.BuiltinAssignment
.. autoclass:: libcst.Scope
.. autoclass:: libcst.metadata.Scope
:no-undoc-members:
.. autoclass:: libcst.GlobalScope
.. autoclass:: libcst.metadata.GlobalScope
:no-undoc-members:
.. autoclass:: libcst.FunctionScope
.. autoclass:: libcst.ClassScope
.. autoclass:: libcst.ComprehensionScope
.. autoclass:: libcst.metadata.FunctionScope
.. autoclass:: libcst.metadata.ClassScope
.. autoclass:: libcst.metadata.ComprehensionScope

View file

@ -25,7 +25,7 @@ from libcst.metadata.expression_context_provider import (
@dataclass(frozen=True)
class Access:
"""
An Access records an access of an assignment.
An Access records an access of an assignment.
"""
#: The name node of the access. A name is an access when the expression context is
@ -523,10 +523,10 @@ class ScopeVisitor(cst.CSTVisitor):
class ScopeProvider(BatchableMetadataProvider[Optional[Scope]]):
"""
ScopeProvider traversed the entire module and create the scope inheritance
structure. It provides the scope of name assignment and accesses. It's useful for
ScopeProvider traverses the entire module and creates the scope inheritance
structure. It provides the scope of name assignment and accesses. It is useful for
more advanced static analysis. E.g. given a :class:`~libcst.FunctionDef`
node, we can check the type of its Scope to figure out whether it's a class method
node, we can check the type of its Scope to figure out whether it is a class method
(:class:`ClassScope`) or a regular function (:class:`GlobalScope`).
"""