Skip to content

Commit eae7bcc

Browse files
yoffshati-patel
andauthored
Apply suggestions from code review
Co-authored-by: Shati Patel <[email protected]>
1 parent f04ac87 commit eae7bcc

File tree

3 files changed

+25
-23
lines changed

3 files changed

+25
-23
lines changed

docs/codeql/codeql-language-guides/analyzing-data-flow-in-python.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ Python has builtin functionality for reading and writing files, such as the func
9999
100100
➤ `See this in the query console on LGTM.com <https://lgtm.com/query/8635258505893505141/>`__. Two of the demo projects make use of this low-level API.
101101

102-
Notice the use of the ``API`` module for referring to library functions. It is further described in ":doc:`Using API graphs in Python <using-api-graphs-in-python>`."
102+
Notice the use of the ``API`` module for referring to library functions. For more information, see ":doc:`Using API graphs in Python <using-api-graphs-in-python>`."
103103

104104
Unfortunately this will only give the expression in the argument, not the values which could be passed to it. So we use local data flow to find all expressions that flow into the argument:
105105

docs/codeql/codeql-language-guides/codeql-library-for-python.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ The CodeQL library for Python incorporates a large number of classes. Each class
2323
- **Data flow** - classes that represent entities from the data flow graphs.
2424
- **API graphs** - classes that represent entities from the API graphs.
2525

26-
The first two categories are described below. See ":doc:`Analyzing data flow in Python <analyzing-data-flow-in-python>`" for a description of data flow and associated classes and ":doc:`Using API graphs in Python <using-api-graphs-in-python>`" for a description of API graphs and their use.
26+
The first two categories are described below.
27+
For a description of data flow and associated classes, see ":doc:`Analyzing data flow in Python <analyzing-data-flow-in-python>`".
28+
For a description of API graphs and their use, see ":doc:`Using API graphs in Python <using-api-graphs-in-python>`."
2729

2830
Syntactic classes
2931
-----------------

docs/codeql/codeql-language-guides/using-api-graphs-in-python.rst

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@ About this article
1010
------------------
1111

1212
This article describes how to use API graphs to reference classes and functions defined in library
13-
code. This can be used to conveniently refer to external library functions when defining things like
13+
code. You can use API graphs to conveniently refer to external library functions when defining things like
1414
remote flow sources.
1515

1616

1717
Module imports
1818
--------------
1919

2020
The most common entry point into the API graph will be the point where an external module or package is
21-
imported. The API graph node corresponding to the ``re`` library, for instance, can be accessed
22-
using the ``API::moduleImport`` method defined in the ``semmle.python.ApiGraphs`` module, as the
21+
imported. For example, you can access the API graph node corresponding to the ``re`` library
22+
by using the ``API::moduleImport`` method defined in the ``semmle.python.ApiGraphs`` module, as the
2323
following snippet demonstrates.
2424

2525
.. code-block:: ql
@@ -31,8 +31,8 @@ following snippet demonstrates.
3131
3232
➤ `See this in the query console on LGTM.com <https://lgtm.com/query/1876172022264324639/>`__.
3333

34-
On its own, this only selects the API graph node corresponding to the ``re`` module. To find
35-
where this module is referenced, we use the ``getAUse`` method. Thus, the following query selects
34+
This query only selects the API graph node corresponding to the ``re`` module. To find
35+
where this module is referenced, you can use the ``getAUse`` method. The following query selects
3636
all references to the ``re`` module in the current database.
3737

3838
.. code-block:: ql
@@ -56,8 +56,8 @@ correctly recognized as a reference to the ``re.compile`` function.
5656
5757
r = my_re_compile(".*")
5858
59-
If only immediate uses are required, without taking local flow into account, then the method
60-
``getAnImmediateUse`` may be used instead.
59+
If you only require immediate uses, without taking local flow into account, then you can use
60+
the ``getAnImmediateUse`` method instead.
6161

6262
Note that the given module name *must not* contain any dots. Thus, something like
6363
``API::moduleImport("flask.views")`` will not do what you expect. Instead, this should be decomposed
@@ -67,8 +67,8 @@ section.
6767
Accessing attributes
6868
--------------------
6969

70-
Given a node in the API graph, we may access its attributes by using the ``getMember`` method. Using
71-
the above ``re.compile`` example, we may now find references to ``re.compile`` by doing
70+
Given a node in the API graph, you can access its attributes by using the ``getMember`` method. Using
71+
the above ``re.compile`` example, you can now find references to ``re.compile``.
7272

7373
.. code-block:: ql
7474
@@ -79,15 +79,15 @@ the above ``re.compile`` example, we may now find references to ``re.compile`` b
7979
8080
➤ `See this in the query console on LGTM.com <https://lgtm.com/query/7970570434725297676/>`__.
8181

82-
In addition to ``getMember``, the method ``getUnknownMember`` can be used to find references to API
83-
components where the name is not known statically, and the ``getAMember`` method can be used to
82+
In addition to ``getMember``, you can use the ``getUnknownMember`` method to find references to API
83+
components where the name is not known statically. You can use the ``getAMember`` method to
8484
access all members, both known and unknown.
8585

8686
Calls and class instantiations
8787
------------------------------
8888

8989
To track instances of classes defined in external libraries, or the results of calling externally
90-
defined functions, we may use the ``getReturn`` method. Thus, the following snippet finds all places
90+
defined functions, you can use the ``getReturn`` method. The following snippet finds all places
9191
where the return value of ``re.compile`` is used:
9292

9393
.. code-block:: ql
@@ -100,8 +100,8 @@ where the return value of ``re.compile`` is used:
100100
➤ `See this in the query console on LGTM.com <https://lgtm.com/query/4346050399960356921/>`__.
101101

102102
Note that this includes all uses of the result of ``re.compile``, including those reachable via
103-
local flow. To get just the *calls* to ``re.compile``, we can use ``getAnImmediateUse`` instead of
104-
``getAUse``. As this is a common occurrence, the method ``getACall`` can be used instead of
103+
local flow. To get just the *calls* to ``re.compile``, you can use ``getAnImmediateUse`` instead of
104+
``getAUse``. As this is a common occurrence, you can use ``getACall`` instead of
105105
``getReturn`` followed by ``getAnImmediateUse``.
106106

107107
➤ `See this in the query console on LGTM.com <https://lgtm.com/query/8143347716552092926/>`__.
@@ -113,14 +113,14 @@ Subclasses
113113
----------
114114

115115
For many libraries, the main mode of usage is to extend one or more library classes. To track this
116-
in the API graph, we can use the ``getASubclass`` method to get the API graph node corresponding to
116+
in the API graph, you can use the ``getASubclass`` method to get the API graph node corresponding to
117117
all the immediate subclasses of this node. To find *all* subclasses, use ``*`` or ``+`` to apply the
118-
method repeatedly, as in `getASubclass*`.
118+
method repeatedly, as in ``getASubclass*``.
119119

120120
Note that ``getASubclass`` does not account for any subclassing that takes place in library code
121121
that has not been extracted. Thus, it may be necessary to account for this in the models you write.
122-
For example, the ``flask.views.View`` class has a predefined subclass ``MethodView``, and so to find
123-
all subclasses of ``View``, we must explicitly include the subclasses of ``MethodView`` as well.
122+
For example, the ``flask.views.View`` class has a predefined subclass ``MethodView``. To find
123+
all subclasses of ``View``, you must explicitly include the subclasses of ``MethodView`` as well.
124124

125125
.. code-block:: ql
126126
@@ -132,7 +132,7 @@ all subclasses of ``View``, we must explicitly include the subclasses of ``Metho
132132
API::moduleImport("flask").getMember("views").getMember(["View", "MethodView"]).getASubclass*()
133133
}
134134
135-
select viewClass()
135+
select viewClass().getAUse()
136136
137137
➤ `See this in the query console on LGTM.com <https://lgtm.com/query/288293322319747121/>`__.
138138

@@ -141,10 +141,10 @@ Note the use of the set literal ``["View", "MethodView"]`` to match both classes
141141
Built-in functions and classes
142142
------------------------------
143143

144-
Built-in functions and classes can be accessed using the ``API::builtin`` method, giving the name of
144+
You can access built-in functions and classes using the ``API::builtin`` method, giving the name of
145145
the built-in as an argument.
146146

147-
To find all calls to the built-in ``open`` function, for instance, can be done using the following snippet
147+
For example, to find all calls to the built-in ``open`` function, you can use the following snippet.
148148

149149
.. code-block:: ql
150150

0 commit comments

Comments
 (0)