Skip to content

Commit 9e3ed21

Browse files
Python: ObjectAPI to ValueAPI: Foresight Additions (github#2819)
* Adds the...Type() predicates as foresight modernizations. * Removes predicates that are not currently ported/portable * Adds range types * Update python/ql/src/semmle/python/objects/ObjectAPI.qll Co-Authored-By: Rasmus Wriedt Larsen <[email protected]> * Update python/ql/src/semmle/python/objects/ObjectAPI.qll Co-Authored-By: Rasmus Wriedt Larsen <[email protected]> * Swaps xType for just x, at least when it's new Co-authored-by: Rasmus Wriedt Larsen <[email protected]>
1 parent cc4c780 commit 9e3ed21

File tree

1 file changed

+131
-18
lines changed

1 file changed

+131
-18
lines changed

python/ql/src/semmle/python/objects/ObjectAPI.qll

Lines changed: 131 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -698,40 +698,57 @@ module ClassValue {
698698
ClassValue bool() {
699699
result = TBuiltinClassObject(Builtin::special("bool"))
700700
}
701-
701+
702+
/** Get the `ClassValue` for the `tuple` class. */
703+
ClassValue tuple() {
704+
result = TBuiltinClassObject(Builtin::special("tuple"))
705+
}
706+
707+
/** Get the `ClassValue` for the `list` class. */
708+
ClassValue list() {
709+
result = TBuiltinClassObject(Builtin::special("list"))
710+
}
711+
712+
/** Get the `ClassValue` for `xrange` (Python 2), or `range` (only Python 3) */
713+
ClassValue range() {
714+
major_version() = 2 and result = TBuiltinClassObject(Builtin::special("xrange"))
715+
or
716+
major_version() = 3 and result = TBuiltinClassObject(Builtin::special("range"))
717+
}
718+
702719
/** Get the `ClassValue` for the `dict` class. */
703720
ClassValue dict() {
704721
result = TBuiltinClassObject(Builtin::special("dict"))
705722
}
706-
707-
/** Get the `ClassValue` for the class of Python functions. */
708-
ClassValue function() {
709-
result = TBuiltinClassObject(Builtin::special("FunctionType"))
723+
724+
/** Get the `ClassValue` for the `set` class. */
725+
ClassValue set() {
726+
result = TBuiltinClassObject(Builtin::special("set"))
710727
}
711-
712-
/** Get the `ClassValue` for the `type` class. */
713-
ClassValue type() {
714-
result = TType()
715-
}
716-
717-
/** Get the `ClassValue` for the class of builtin functions. */
718-
ClassValue builtinFunction() {
719-
result = Value::named("len").getClass()
728+
729+
/** Get the `ClassValue` for the `object` class. */
730+
ClassValue object() {
731+
result = TBuiltinClassObject(Builtin::special("object"))
720732
}
721733

722734
/** Get the `ClassValue` for the `int` class. */
723735
ClassValue int_() {
724736
result = TBuiltinClassObject(Builtin::special("int"))
725737
}
738+
739+
/** Get the `ClassValue` for the `long` class. */
740+
ClassValue long() {
741+
result = TBuiltinClassObject(Builtin::special("long"))
742+
}
726743

727744
/** Get the `ClassValue` for the `float` class. */
728745
ClassValue float_() {
729746
result = TBuiltinClassObject(Builtin::special("float"))
730747
}
731-
732-
/** Get the `ClassValue` for the `list` class. */
733-
ClassValue list() {
734-
result = TBuiltinClassObject(Builtin::special("list"))
748+
749+
/** Get the `ClassValue` for the `complex` class. */
750+
ClassValue complex() {
751+
result = TBuiltinClassObject(Builtin::special("complex"))
735752
}
736753

737754
/** Get the `ClassValue` for the `bytes` class (also called `str` in Python 2). */
@@ -753,7 +770,47 @@ module ClassValue {
753770
else
754771
result = unicode()
755772
}
773+
774+
/** Get the `ClassValue` for the `property` class. */
775+
ClassValue property() {
776+
result = TBuiltinClassObject(Builtin::special("property"))
777+
}
778+
779+
/** Get the `ClassValue` for the class of Python functions. */
780+
ClassValue functionType() {
781+
result = TBuiltinClassObject(Builtin::special("FunctionType"))
782+
}
756783

784+
/** Get the `ClassValue` for the class of builtin functions. */
785+
ClassValue builtinFunction() {
786+
result = Value::named("len").getClass()
787+
}
788+
789+
/** Get the `ClassValue` for the `generatorType` class. */
790+
ClassValue generator() {
791+
result = TBuiltinClassObject(Builtin::special("generator"))
792+
}
793+
794+
/** Get the `ClassValue` for the `type` class. */
795+
ClassValue type() {
796+
result = TType()
797+
}
798+
799+
/** Get the `ClassValue` for `ClassType`. */
800+
ClassValue classType() {
801+
result = TBuiltinClassObject(Builtin::special("ClassType"))
802+
}
803+
804+
/** Get the `ClassValue` for `InstanceType`. */
805+
ClassValue instanceType() {
806+
result = TBuiltinClassObject(Builtin::special("InstanceType"))
807+
}
808+
809+
/** Get the `ClassValue` for `super`. */
810+
ClassValue super_() {
811+
result = TBuiltinClassObject(Builtin::special("super"))
812+
}
813+
757814
/** Get the `ClassValue` for the `classmethod` class. */
758815
ClassValue classmethod() {
759816
result = TBuiltinClassObject(Builtin::special("ClassMethod"))
@@ -763,21 +820,77 @@ module ClassValue {
763820
ClassValue staticmethod() {
764821
result = TBuiltinClassObject(Builtin::special("StaticMethod"))
765822
}
823+
824+
/** Get the `ClassValue` for the `MethodType` class. */
825+
pragma [noinline]
826+
ClassValue methodType() {
827+
result = TBuiltinClassObject(Builtin::special("MethodType"))
828+
}
829+
830+
/** Get the `ClassValue` for the `MethodDescriptorType` class. */
831+
ClassValue methodDescriptorType() {
832+
result = TBuiltinClassObject(Builtin::special("MethodDescriptorType"))
833+
}
834+
835+
/** Get the `ClassValue` for the `GetSetDescriptorType` class. */
836+
ClassValue getSetDescriptorType() {
837+
result = TBuiltinClassObject(Builtin::special("GetSetDescriptorType"))
838+
}
839+
840+
/** Get the `ClassValue` for the `StopIteration` class. */
841+
ClassValue stopIteration() {
842+
result = TBuiltinClassObject(Builtin::special("StopIteration"))
843+
}
766844

767845
/** Get the `ClassValue` for the class of modules. */
768846
ClassValue module_() {
769847
result = TBuiltinClassObject(Builtin::special("ModuleType"))
770848
}
771849

850+
/** Get the `ClassValue` for the `Exception` class. */
851+
ClassValue exception() {
852+
result = TBuiltinClassObject(Builtin::special("Exception"))
853+
}
854+
855+
/** Get the `ClassValue` for the `BaseException` class. */
856+
ClassValue baseException() {
857+
result = TBuiltinClassObject(Builtin::special("BaseException"))
858+
}
859+
772860
/** Get the `ClassValue` for the `NoneType` class. */
773861
ClassValue nonetype() {
774862
result = TBuiltinClassObject(Builtin::special("NoneType"))
775863
}
864+
865+
/** Get the `ClassValue` for the `TypeError` class */
866+
ClassValue typeError() {
867+
result = TBuiltinClassObject(Builtin::special("TypeError"))
868+
}
776869

777870
/** Get the `ClassValue` for the `NameError` class. */
778871
ClassValue nameError() {
779872
result = TBuiltinClassObject(Builtin::builtin("NameError"))
780873
}
874+
875+
/** Get the `ClassValue` for the `AttributeError` class. */
876+
ClassValue attributeError() {
877+
result = TBuiltinClassObject(Builtin::builtin("AttributeError"))
878+
}
879+
880+
/** Get the `ClassValue` for the `KeyError` class. */
881+
ClassValue keyError() {
882+
result = TBuiltinClassObject(Builtin::builtin("KeyError"))
883+
}
884+
885+
/** Get the `ClassValue` for the `IOError` class. */
886+
ClassValue ioError() {
887+
result = TBuiltinClassObject(Builtin::builtin("IOError"))
888+
}
889+
890+
/** Get the `ClassValue` for the `NotImplementedError` class. */
891+
ClassValue notImplementedError() {
892+
result = TBuiltinClassObject(Builtin::builtin("NotImplementedError"))
893+
}
781894

782895
/** Get the `ClassValue` for the `ImportError` class. */
783896
ClassValue importError() {

0 commit comments

Comments
 (0)