Skip to content

Commit a7ba693

Browse files
committed
Python: delete old deprecations
1 parent a4e5d75 commit a7ba693

File tree

5 files changed

+7
-213
lines changed

5 files changed

+7
-213
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
category: minorAnalysis
3+
---
4+
* Deleted the deprecated `importNode` predicate from the `DataFlowUtil.qll` file.
5+
* Deleted the deprecated features from `PEP249.qll` that were not inside the `PEP249` module.
6+
* Deleted the deprecated `werkzeug` from the `Werkzeug` module in `Werkzeug.qll`.
7+
* Deleted the deprecated `methodResult` predicate from `PEP249::Cursor`.

python/ql/lib/semmle/python/dataflow/new/internal/DataFlowUtil.qll

Lines changed: 0 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -26,67 +26,3 @@ predicate localFlowStep(Node nodeFrom, Node nodeTo) {
2626
*/
2727
pragma[inline]
2828
predicate localFlow(Node source, Node sink) { localFlowStep*(source, sink) }
29-
30-
/**
31-
* DEPRECATED. Use the API graphs library (`semmle.python.ApiGraphs`) instead.
32-
*
33-
* For a drop-in replacement, use `API::moduleImport(name).getAUse()`.
34-
*
35-
* Gets a `Node` that refers to the module referenced by `name`.
36-
* Note that for the statement `import pkg.mod`, the new variable introduced is `pkg` that is a
37-
* reference to the module `pkg`.
38-
*
39-
* This predicate handles (with optional `... as <new-name>`):
40-
* 1. `import <name>`
41-
* 2. `from <package> import <module>` when `<name> = <package> + "." + <module>`
42-
* 3. `from <module> import <member>` when `<name> = <module> + "." + <member>`
43-
*
44-
* Finally, in `from <module> import <member>` we consider the `ImportExpr` corresponding to
45-
* `<module>` to be a reference to that module.
46-
*
47-
* Note:
48-
* While it is technically possible that `import mypkg.foo` and `from mypkg import foo` can give different values,
49-
* it's highly unlikely that this will be a problem in production level code.
50-
* Example: If `mypkg/__init__.py` contains `foo = 42`, then `from mypkg import foo` will not import the module
51-
* `mypkg/foo.py` but the variable `foo` containing `42` -- however, `import mypkg.foo` will always cause `mypkg.foo`
52-
* to refer to the module.
53-
*/
54-
deprecated Node importNode(string name) {
55-
exists(Variable var, Import imp, Alias alias |
56-
alias = imp.getAName() and
57-
alias.getAsname() = var.getAStore() and
58-
(
59-
name = alias.getValue().(ImportMember).getImportedModuleName()
60-
or
61-
name = alias.getValue().(ImportExpr).getImportedModuleName()
62-
) and
63-
result.asExpr() = alias.getValue()
64-
)
65-
or
66-
// Although it may seem superfluous to consider the `foo` part of `from foo import bar as baz` to
67-
// be a reference to a module (since that reference only makes sense locally within the `import`
68-
// statement), it's important for our use of type trackers to consider this local reference to
69-
// also refer to the `foo` module. That way, if one wants to track references to the `bar`
70-
// attribute using a type tracker, one can simply write
71-
//
72-
// ```ql
73-
// DataFlow::Node bar_attr_tracker(TypeTracker t) {
74-
// t.startInAttr("bar") and
75-
// result = foo_module_tracker()
76-
// or
77-
// exists(TypeTracker t2 | result = bar_attr_tracker(t2).track(t2, t))
78-
// }
79-
// ```
80-
//
81-
// Where `foo_module_tracker` is a type tracker that tracks references to the `foo` module.
82-
// Because named imports are modeled as `AttrRead`s, the statement `from foo import bar as baz`
83-
// is interpreted as if it was an assignment `baz = foo.bar`, which means `baz` gets tracked as a
84-
// reference to `foo.bar`, as desired.
85-
exists(ImportExpr imp_expr |
86-
imp_expr.getName() = name and
87-
result.asCfgNode().getNode() = imp_expr and
88-
// in `import foo.bar` we DON'T want to give a result for `importNode("foo.bar")`,
89-
// only for `importNode("foo")`. We exclude those cases with the following clause.
90-
not exists(Import imp | imp.getAName().getValue() = imp_expr)
91-
)
92-
}

python/ql/lib/semmle/python/frameworks/PEP249.qll

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,28 +9,3 @@ private import semmle.python.dataflow.new.RemoteFlowSources
99
private import semmle.python.Concepts
1010
private import semmle.python.ApiGraphs
1111
import semmle.python.frameworks.internal.PEP249Impl
12-
13-
/**
14-
* DEPRECATED: Use `PEP249::PEP249ModuleApiNode` instead.
15-
*/
16-
deprecated class PEP249ModuleApiNode = PEP249::PEP249ModuleApiNode;
17-
18-
/**
19-
* DEPRECATED: Use `PEP249::Connection` instead.
20-
*/
21-
deprecated module Connection = PEP249::Connection;
22-
23-
/**
24-
* DEPRECATED: Use `PEP249::Cursor` instead.
25-
*/
26-
deprecated module cursor = PEP249::Cursor;
27-
28-
/**
29-
* DEPRECATED: Use `PEP249::execute` instead.
30-
*/
31-
deprecated predicate execute = PEP249::execute/0;
32-
33-
/**
34-
* DEPRECATED: Use `PEP249::connect` instead.
35-
*/
36-
deprecated predicate connect = PEP249::connect/0;

python/ql/lib/semmle/python/frameworks/Werkzeug.qll

Lines changed: 0 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -231,119 +231,4 @@ module Werkzeug {
231231
override string getAsyncMethodName() { none() }
232232
}
233233
}
234-
235-
import WerkzeugOld
236-
}
237-
238-
/**
239-
* Old version that contains the deprecated modules.
240-
*/
241-
private module WerkzeugOld {
242-
/**
243-
* DEPRECATED: Use the modeling available directly in the `Werkzeug` module instead.
244-
*
245-
* Provides models for the `werkzeug` module.
246-
*/
247-
deprecated module werkzeug {
248-
/**
249-
* DEPRECATED: Use the modeling available directly in the `Werkzeug` module instead.
250-
*
251-
* Provides models for the `werkzeug.datastructures` module.
252-
*/
253-
deprecated module datastructures {
254-
/**
255-
* DEPRECATED: Use `Werkzeug::MultiDict` instead.
256-
*
257-
* Provides models for the `werkzeug.datastructures.MultiDict` class
258-
*
259-
* See https://werkzeug.palletsprojects.com/en/1.0.x/datastructures/#werkzeug.datastructures.MultiDict.
260-
*/
261-
deprecated module MultiDict {
262-
/**
263-
* DEPRECATED. Use `Werkzeug::MultiDict::InstanceSource` instead.
264-
*
265-
* A source of instances of `werkzeug.datastructures.MultiDict`, extend this class to model new instances.
266-
*
267-
* This can include instantiations of the class, return values from function
268-
* calls, or a special parameter that will be set when functions are called by an external
269-
* library.
270-
*
271-
* Use the predicate `MultiDict::instance()` to get references to instances of `werkzeug.datastructures.MultiDict`.
272-
*/
273-
abstract deprecated class InstanceSourceApiNode extends API::Node { }
274-
275-
/**
276-
* DEPRECATED
277-
*
278-
* Gets a reference to the `getlist` method on an instance of `werkzeug.datastructures.MultiDict`.
279-
*
280-
* See https://werkzeug.palletsprojects.com/en/1.0.x/datastructures/#werkzeug.datastructures.Headers.getlist
281-
*/
282-
deprecated DataFlow::Node getlist() {
283-
result = any(InstanceSourceApiNode a).getMember("getlist").getAValueReachableFromSource()
284-
}
285-
286-
private class MultiDictAdditionalTaintStep extends TaintTracking::AdditionalTaintStep {
287-
override predicate step(DataFlow::Node nodeFrom, DataFlow::Node nodeTo) {
288-
// obj -> obj.getlist
289-
exists(DataFlow::AttrRead read |
290-
read.getObject() = nodeFrom and
291-
nodeTo = read and
292-
nodeTo = getlist()
293-
)
294-
or
295-
// getlist -> getlist()
296-
nodeFrom = getlist() and
297-
nodeTo.(DataFlow::CallCfgNode).getFunction() = nodeFrom
298-
}
299-
}
300-
}
301-
302-
/**
303-
* DEPRECATED: Use `Werkzeug::FileStorage` instead.
304-
*
305-
* Provides models for the `werkzeug.datastructures.FileStorage` class
306-
*
307-
* See https://werkzeug.palletsprojects.com/en/1.0.x/datastructures/#werkzeug.datastructures.FileStorage.
308-
*/
309-
deprecated module FileStorage {
310-
/**
311-
* DEPRECATED. Use `Werkzeug::FileStorage::InstanceSource` instead.
312-
*
313-
* A source of instances of `werkzeug.datastructures.FileStorage`, extend this class to model new instances.
314-
*
315-
* This can include instantiations of the class, return values from function
316-
* calls, or a special parameter that will be set when functions are called by an external
317-
* library.
318-
*
319-
* Use the predicate `FileStorage::instance()` to get references to instances of `werkzeug.datastructures.FileStorage`.
320-
*/
321-
abstract deprecated class InstanceSourceApiNode extends API::Node { }
322-
323-
/** Gets a reference to an instance of `werkzeug.datastructures.FileStorage`. */
324-
deprecated DataFlow::Node instance() {
325-
result = any(InstanceSourceApiNode a).getAValueReachableFromSource()
326-
}
327-
328-
private class FileStorageAdditionalTaintStep extends TaintTracking::AdditionalTaintStep {
329-
override predicate step(DataFlow::Node nodeFrom, DataFlow::Node nodeTo) {
330-
nodeFrom = instance() and
331-
exists(DataFlow::AttrRead read | nodeTo = read |
332-
read.getAttributeName() in [
333-
// str
334-
"filename", "name", "content_type", "mimetype",
335-
// file-like
336-
"stream",
337-
// TODO: werkzeug.datastructures.Headers
338-
"headers",
339-
// dict[str, str]
340-
"mimetype_params"
341-
] and
342-
read.getObject() = nodeFrom
343-
)
344-
}
345-
}
346-
}
347-
}
348-
}
349234
}

python/ql/lib/semmle/python/frameworks/internal/PEP249Impl.qll

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -129,15 +129,6 @@ module PEP249 {
129129
or
130130
exists(DataFlow::TypeTracker t2 | result = methodResult(t2).track(t2, t))
131131
}
132-
133-
/**
134-
* DEPRECATED: Use `Cursor::instance()` to get references to database cursors instead.
135-
*
136-
* Gets a reference to a result of calling the `cursor` method on a database connection.
137-
*/
138-
deprecated DataFlow::Node methodResult() {
139-
methodResult(DataFlow::TypeTracker::end()).flowsTo(result)
140-
}
141132
}
142133

143134
/**

0 commit comments

Comments
 (0)