From 87a9f51c78c083673d3906abffb3806f2634626a Mon Sep 17 00:00:00 2001 From: Taus Brock-Nannestad Date: Mon, 30 Mar 2020 11:59:10 +0200 Subject: [PATCH] Python: Autoformat all `.ql` files. --- python/ql/examples/snippets/builtin_object.ql | 2 +- python/ql/examples/snippets/call.ql | 2 +- .../ql/examples/snippets/catch_exception.ql | 4 +- .../snippets/conditional_expression.ql | 7 +- python/ql/examples/snippets/emptyblock.ql | 2 +- python/ql/examples/snippets/emptythen.ql | 6 +- python/ql/examples/snippets/eq_true.ql | 2 +- python/ql/examples/snippets/equalitystmt.ql | 2 +- python/ql/examples/snippets/extend_class.ql | 4 +- python/ql/examples/snippets/filename.ql | 2 +- python/ql/examples/snippets/generator.ql | 2 +- .../ql/examples/snippets/integer_literal.ql | 2 +- python/ql/examples/snippets/method_call.ql | 4 +- python/ql/examples/snippets/new_instance.ql | 2 +- .../ql/examples/snippets/override_method.ql | 2 +- python/ql/examples/snippets/print.ql | 4 +- python/ql/examples/snippets/private_access.ql | 11 +- .../ql/examples/snippets/raise_exception.ql | 6 +- python/ql/examples/snippets/raw_string.ql | 4 +- python/ql/examples/snippets/store_none.ql | 4 +- python/ql/examples/snippets/tryfinally.ql | 5 +- .../ConflictingAttributesInBaseClasses.ql | 46 +-- .../DefineEqualsWhenAddingAttributes.ql | 25 +- python/ql/src/Classes/EqualsOrHash.ql | 31 +- python/ql/src/Classes/EqualsOrNotEquals.ql | 34 +-- python/ql/src/Classes/IncompleteOrdering.ql | 42 ++- python/ql/src/Classes/InconsistentMRO.ql | 11 +- .../ql/src/Classes/InitCallsSubclassMethod.ql | 33 +- .../Classes/MaybeUndefinedClassAttribute.ql | 21 +- python/ql/src/Classes/MissingCallToDel.ql | 8 +- python/ql/src/Classes/MissingCallToInit.ql | 6 +- python/ql/src/Classes/MutatingDescriptor.ql | 11 +- .../OverwritingAttributeInSuperClass.ql | 93 +++--- .../ql/src/Classes/PropertyInOldStyleClass.ql | 4 +- .../ql/src/Classes/ShouldBeContextManager.ql | 4 +- python/ql/src/Classes/SubclassShadowing.ql | 32 +- python/ql/src/Classes/SuperInOldStyleClass.ql | 11 +- .../SuperclassDelCalledMultipleTimes.ql | 23 +- .../SuperclassInitCalledMultipleTimes.ql | 23 +- .../ql/src/Classes/UndefinedClassAttribute.ql | 1 - python/ql/src/Classes/UselessClass.ql | 77 ++--- ...rongNameForArgumentInClassInstantiation.ql | 11 +- ...rongNumberArgumentsInClassInstantiation.ql | 18 +- .../src/Exceptions/CatchingBaseException.ql | 15 +- python/ql/src/Exceptions/EmptyExcept.ql | 44 ++- python/ql/src/Exceptions/IllegalRaise.ql | 10 +- .../NotImplementedIsNotAnException.ql | 1 - python/ql/src/Exceptions/RaisingTuple.ql | 13 +- .../Exceptions/UnguardedNextInGenerator.ql | 28 +- .../src/Expressions/CallToSuperWrongClass.ql | 18 +- python/ql/src/Expressions/CompareConstants.ql | 4 +- .../CompareIdenticalValuesMissingSelf.ql | 3 +- .../Comparisons/UselessComparisonTest.ql | 17 +- .../DuplicateKeyInDictionaryLiteral.ql | 25 +- .../ql/src/Expressions/ExplicitCallToDel.ql | 31 +- .../MixedExplicitImplicitIn3101Format.ql | 2 +- .../Formatting/UnusedArgumentIn3101Format.ql | 16 +- .../UnusedNamedArgumentIn3101Format.ql | 26 +- .../WrongNameInArgumentsFor3101Format.ql | 14 +- .../WrongNumberArgumentsFor3101Format.ql | 20 +- python/ql/src/Expressions/HashedButNoHash.ql | 27 +- .../Expressions/IncorrectComparisonUsingIs.ql | 15 +- .../ql/src/Expressions/NonCallableCalled.ql | 15 +- .../NonPortableComparisonUsingIs.ql | 16 +- .../src/Expressions/Regex/BackspaceEscape.ql | 11 +- .../Regex/DuplicateCharacterInSet.ql | 24 +- .../Regex/MissingPartSpecialGroup.ql | 2 - .../src/Expressions/Regex/UnmatchableCaret.ql | 7 +- .../Expressions/Regex/UnmatchableDollar.ql | 8 +- .../ql/src/Expressions/TruncatedDivision.ql | 51 ++-- ...nintentionalImplicitStringConcatenation.ql | 19 +- .../ql/src/Expressions/UnnecessaryLambda.ql | 60 ++-- .../Expressions/WrongNameForArgumentInCall.ql | 13 +- .../WrongNumberArgumentsForFormat.ql | 31 +- .../Expressions/WrongNumberArgumentsInCall.ql | 29 +- python/ql/src/Filters/ClassifyFiles.ql | 5 +- python/ql/src/Filters/NotGenerated.ql | 1 + python/ql/src/Filters/NotTest.ql | 1 + python/ql/src/Functions/ConsistentReturns.ql | 17 +- .../ql/src/Functions/DeprecatedSliceMethod.ql | 14 +- .../IncorrectRaiseInSpecialMethod.ql | 123 +++++--- .../Functions/IncorrectlyOverriddenMethod.ql | 24 +- .../IncorrectlySpecifiedOverriddenMethod.ql | 36 +-- python/ql/src/Functions/InitIsGenerator.ql | 5 +- python/ql/src/Functions/IterReturnsNonSelf.ql | 19 +- python/ql/src/Functions/NonCls.ql | 8 +- python/ql/src/Functions/NonSelf.ql | 6 +- .../src/Functions/OverlyComplexDelMethod.ql | 7 +- .../Functions/ReturnConsistentTupleSizes.ql | 7 +- python/ql/src/Functions/ReturnValueIgnored.ql | 62 ++-- .../Functions/SignatureOverriddenMethod.ql | 34 +-- .../src/Functions/SignatureSpecialMethods.ql | 286 +++++++++--------- .../Functions/UseImplicitNoneReturnValue.ql | 22 +- python/ql/src/Imports/DeprecatedModule.ql | 6 +- python/ql/src/Imports/EncodingError.ql | 2 +- .../ql/src/Imports/ImportShadowedByLoopVar.ql | 7 +- python/ql/src/Imports/ImportStarUsed.ql | 1 - python/ql/src/Imports/ImportandImportFrom.ql | 7 +- python/ql/src/Imports/Imports.ql | 13 +- python/ql/src/Imports/ModuleImportsItself.ql | 3 +- python/ql/src/Imports/MultipleImports.ql | 34 ++- python/ql/src/Imports/SyntaxError.ql | 2 +- python/ql/src/Imports/UnintentionalImport.ql | 6 +- python/ql/src/Lexical/CommentedOutCode.ql | 1 - python/ql/src/Lexical/FCommentedOutCode.ql | 4 +- python/ql/src/Lexical/OldOctalLiteral.ql | 3 +- python/ql/src/Metrics/CLinesOfCode.ql | 4 +- .../ql/src/Metrics/ClassAfferentCoupling.ql | 4 +- .../ql/src/Metrics/ClassEfferentCoupling.ql | 4 +- python/ql/src/Metrics/CommentRatio.ql | 5 +- python/ql/src/Metrics/CyclomaticComplexity.ql | 4 +- .../Dependencies/ExternalDependencies.ql | 28 +- .../ExternalDependenciesSourceLinks.ql | 11 +- python/ql/src/Metrics/DirectImports.ql | 1 + python/ql/src/Metrics/DocStringRatio.ql | 8 +- .../Metrics/External/CommitDisplayStrings.ql | 2 + .../src/Metrics/External/CommitSourceLinks.ql | 2 + python/ql/src/Metrics/FClasses.ql | 3 +- python/ql/src/Metrics/FFunctionsAndMethods.ql | 3 +- python/ql/src/Metrics/FLines.ql | 4 +- python/ql/src/Metrics/FLinesOfCode.ql | 4 +- python/ql/src/Metrics/FLinesOfComments.ql | 7 +- .../ql/src/Metrics/FLinesOfDuplicatedCode.ql | 22 +- python/ql/src/Metrics/FLinesOfSimilarCode.ql | 22 +- python/ql/src/Metrics/FNumberOfTests.ql | 5 +- .../ql/src/Metrics/FunctionNumberOfCalls.ql | 6 +- .../Metrics/FunctionStatementNestingDepth.ql | 4 +- python/ql/src/Metrics/History/HChurn.ql | 14 +- python/ql/src/Metrics/History/HLinesAdded.ql | 14 +- .../ql/src/Metrics/History/HLinesDeleted.ql | 14 +- .../src/Metrics/History/HNumberOfAuthors.ql | 2 +- .../src/Metrics/History/HNumberOfCoCommits.ql | 13 +- .../src/Metrics/History/HNumberOfCommits.ql | 1 + .../src/Metrics/History/HNumberOfReCommits.ql | 23 +- .../Metrics/History/HNumberOfRecentAuthors.ql | 12 +- .../History/HNumberOfRecentChangedFiles.ql | 11 +- .../Metrics/History/HNumberOfRecentCommits.ql | 2 +- .../Internal/CallableDisplayStrings.ql | 1 + .../src/Metrics/Internal/CallableExtents.ql | 1 + .../Metrics/Internal/CallableSourceLinks.ql | 1 + .../Metrics/Internal/ClassDisplayStrings.ql | 1 + .../ql/src/Metrics/Internal/ClassExtents.ql | 1 + .../src/Metrics/Internal/ClassSourceLinks.ql | 1 + .../src/Metrics/LackofCohesionInMethodsCK.ql | 6 +- .../src/Metrics/LackofCohesionInMethodsHM.ql | 6 +- .../ql/src/Metrics/ModuleAfferentCoupling.ql | 4 +- .../ql/src/Metrics/ModuleEfferentCoupling.ql | 4 +- .../NumberOfParametersWithoutDefault.ql | 4 +- python/ql/src/Metrics/NumberOfStatements.ql | 4 +- python/ql/src/Metrics/TransitiveImports.ql | 1 + python/ql/src/Numerics/Pythagorean.ql | 41 ++- .../CWE-020/IncompleteHostnameRegExp.ql | 3 +- .../Security/CWE-079/Jinja2WithoutEscaping.ql | 8 +- .../ql/src/Security/CWE-089/SqlInjection.ql | 4 +- .../CWE-295/MissingHostKeyValidation.ql | 6 +- .../src/Security/CWE-327/InsecureProtocol.ql | 4 +- .../Statements/IterableStringOrSequence.ql | 6 +- .../ql/src/Statements/ModificationOfLocals.ql | 4 +- .../ql/src/Statements/RedundantAssignment.ql | 9 +- python/ql/src/Testing/ImpreciseAssert.ql | 33 +- python/ql/src/analysis/AlertSuppression.ql | 65 ++-- python/ql/src/analysis/CallGraphEfficiency.ql | 32 +- .../analysis/CallGraphMarginalEfficiency.ql | 40 +-- python/ql/src/analysis/ContextEfficiency.ql | 33 +- .../src/analysis/ContextMarginalEfficiency.ql | 24 +- python/ql/src/analysis/Definitions.ql | 11 +- python/ql/src/analysis/Efficiency.ql | 31 +- python/ql/src/analysis/FailedInference.ql | 7 +- python/ql/src/analysis/ImportFailure.ql | 74 ++--- python/ql/src/analysis/KeyPointsToFailure.ql | 15 +- python/ql/src/analysis/PointsToFailure.ql | 8 +- python/ql/src/analysis/Pruned.ql | 9 +- python/ql/src/analysis/RatioOfDefinitions.ql | 17 +- python/ql/src/analysis/Sanity.ql | 214 ++++++++----- python/ql/src/analysis/Summary.ql | 67 ++-- .../ql/src/analysis/TypeHierarchyFailure.ql | 4 +- .../ql/src/analysis/TypeInferenceFailure.ql | 9 +- python/ql/src/external/DuplicateBlock.ql | 22 +- python/ql/src/external/DuplicateFunction.ql | 20 +- .../ql/src/external/MostlyDuplicateClass.ql | 9 +- python/ql/src/external/MostlyDuplicateFile.ql | 1 + python/ql/src/external/MostlySimilarFile.ql | 2 +- python/ql/src/external/SimilarFunction.ql | 15 +- .../ControlFlow/Exceptions/Handles.ql | 3 +- .../ControlFlow/Exceptions/Known.ql | 3 +- .../ControlFlow/Exceptions/Likely.ql | 8 +- .../ControlFlow/Exceptions/Unknown.ql | 3 +- .../PointsTo/import_time/Pruned.ql | 11 +- .../library-tests/PointsTo/imports/Runtime.ql | 11 +- .../library-tests/PointsTo/metaclass/test.ql | 1 - .../PointsTo/origin_uniqueness/Origin.ql | 15 +- .../library-tests/classes/attr/class_attr.ql | 10 +- .../classes/attr/class_has_attr.ql | 8 +- .../2/library-tests/classes/attr/list_attr.ql | 12 +- .../ql/test/2/library-tests/classes/mro/C3.ql | 8 +- .../test/2/library-tests/classes/mro/mro.ql | 7 +- .../comprehensions/SanityCheck.ql | 4 +- .../locations/general/AllLocations.ql | 7 +- .../locations/general/Locations.ql | 3 +- .../library-tests/locations/general/Prefix.ql | 5 +- .../locations/keywords/Locations.ql | 3 +- .../2/library-tests/locations/strings/test.ql | 2 +- .../modules/general/import_test.ql | 10 +- .../modules/general/moduleobject_test.ql | 1 - .../package_members/module_import_as.ql | 2 +- .../test/2/library-tests/objects/Literals.ql | 8 +- .../2/library-tests/types/classes/mro_test.ql | 2 - .../library-tests/types/classes/new_style.ql | 13 +- .../types/exceptions/ExitRaises.ql | 1 - .../library-tests/types/exceptions/Raises.ql | 9 +- .../2/library-tests/types/functions/Calls.ql | 1 - .../2/library-tests/types/functions/Never.ql | 2 +- .../types/functions/ReturnTypes.ql | 2 - .../types/properties/BuiltinProperties.ql | 9 +- .../ControlFlow/Exceptions/Handles.ql | 3 +- .../ControlFlow/Exceptions/Known.ql | 3 +- .../ControlFlow/Exceptions/Likely.ql | 8 +- .../ControlFlow/Exceptions/Unknown.ql | 3 +- .../library-tests/PointsTo/attributes/Test.ql | 2 - .../PointsTo/attributes/TestWithType.ql | 5 +- .../PointsTo/consts/BooleanConstants.ql | 15 +- .../PointsTo/import_time/Pruned.ql | 6 +- .../PointsTo/inheritance/Calls.ql | 3 - .../library-tests/PointsTo/metaclass/test.ql | 1 - .../subprocess-assert/ClassValue.ql | 5 +- .../PointsTo/typehints/Values.ql | 5 +- .../library-tests/classes/attr/class_attr.ql | 10 +- .../classes/attr/class_has_attr.ql | 8 +- .../test/3/library-tests/classes/meta/meta.ql | 2 +- .../3/library-tests/classes/meta/meta_obj.ql | 2 +- .../test/3/library-tests/classes/mro/mro.ql | 5 +- .../3/library-tests/classes/mro/mro_index.ql | 5 +- .../locations/annotations/Locations.ql | 3 +- .../locations/general/AllLocations.ql | 7 +- .../locations/general/Locations.ql | 3 +- .../library-tests/locations/general/Prefix.ql | 5 +- .../locations/keywords/Locations.ql | 3 +- .../modules/general/import_test.ql | 10 +- .../modules/general/moduleobject_test.ql | 1 - .../taint/unpacking/TestTaint.ql | 3 +- .../3/library-tests/types/classes/mro_test.ql | 2 - .../library-tests/types/exceptions/Raises.ql | 9 +- .../library-tests/types/exceptions/Viable.ql | 5 +- .../3/library-tests/types/functions/Calls.ql | 2 - .../3/library-tests/types/functions/Never.ql | 2 +- .../types/functions/ReturnTypes.ql | 2 - .../types/namespaces/NameSpace.ql | 28 +- .../types/properties/BuiltinProperties.ql | 9 +- .../PointsToSupport/UseFromDefinition.ql | 14 +- .../ControlFlow/augassign/AugAssignFlow.ql | 10 +- .../ControlFlow/augassign/Kind.ql | 19 +- .../ControlFlow/augassign/SSA.ql | 5 +- .../ControlFlow/comparison/Compare.ql | 13 +- .../library-tests/ControlFlow/delete/test.ql | 3 +- .../ControlFlow/dominators/DominatesSanity.ql | 13 +- .../ControlFlow/dominators/idom.ql | 7 +- .../ControlFlow/general/Comments.ql | 1 - .../ControlFlow/general/Cyclo.ql | 2 - .../general/ImmediateDominatorCheck.ql | 23 +- .../ControlFlow/general/Lines.ql | 7 +- .../ControlFlow/general/Reaches.ql | 5 +- .../ControlFlow/raising_stmts/RaisingFlow.ql | 16 +- .../ControlFlow/splitting/NodeCount.ql | 13 +- .../ControlFlow/splitting/SuccessorCount.ql | 11 +- .../ControlFlow/ssa/defns/test.ql | 4 +- .../ControlFlow/ssa/deletions/test.ql | 19 +- .../ssa/phi-nodes/phi_input_test.ql | 5 +- .../ControlFlow/ssa/phi-nodes/test.ql | 5 +- .../ControlFlow/ssa/undefined/test.ql | 4 +- .../ControlFlow/ssa/uses/test.ql | 4 +- .../ControlFlow/ssa/vars/test.ql | 5 +- .../ControlFlow/successors/Successors.ql | 25 +- .../truefalse/ExceptionalSuccessors.ql | 8 +- .../truefalse/TrueAndFalseSuccessor.ql | 4 +- .../truefalse/TrueFalseSuccessors.ql | 9 +- .../library-tests/ControlFlow/try/test_ssa.ql | 5 +- .../test/library-tests/DefUse/Definitions.ql | 2 +- python/ql/test/library-tests/DefUse/Uses.ql | 2 +- .../library-tests/DuplicateCode/Duplicate.ql | 16 +- .../DuplicateCode/DuplicateStatements.ql | 19 +- .../library-tests/DuplicateCode/Similar.ql | 13 +- .../library-tests/PointsTo/absent/Absent.ql | 2 - .../library-tests/PointsTo/api/ClassValue.ql | 3 +- .../library-tests/PointsTo/api/Constants.ql | 24 +- .../PointsTo/api/QualifedNames.ql | 25 +- .../test/library-tests/PointsTo/api/Value.ql | 13 +- .../library-tests/PointsTo/calls/Argument.ql | 2 +- .../test/library-tests/PointsTo/calls/Call.ql | 4 +- .../PointsTo/comparisons/PointsTo.ql | 1 - .../library-tests/PointsTo/customise/test.ql | 22 +- .../library-tests/PointsTo/decorators/Test.ql | 9 +- .../PointsTo/decorators/Values.ql | 5 +- .../PointsTo/extensions/Extend.ql | 26 +- .../library-tests/PointsTo/functions/Calls.ql | 15 +- .../PointsTo/functions/NeverReturns.ql | 1 - .../library-tests/PointsTo/functions/test.ql | 8 +- .../PointsTo/general/GlobalPointsTo.ql | 9 +- .../PointsTo/general/LocalPointsTo.ql | 6 +- .../PointsTo/general/LocalPointsToType.ql | 7 +- .../library-tests/PointsTo/global/Global.ql | 9 +- .../PointsTo/guarded/PointsTo.ql | 9 +- .../PointsTo/guarded/PointsToWithType.ql | 9 +- .../PointsTo/import_star/Values.ql | 4 +- .../library-tests/PointsTo/imports/Runtime.ql | 9 +- .../PointsTo/imports/RuntimeWithType.ql | 12 +- .../library-tests/PointsTo/indexing/Test.ql | 7 +- .../PointsTo/indexing/TestWithType.ql | 10 +- .../PointsTo/inheritance/BaseTypes.ql | 6 +- .../PointsTo/inheritance/Calls.ql | 3 - .../PointsTo/inheritance/Declared.ql | 1 - .../PointsTo/inheritance/Declares.ql | 1 - .../PointsTo/inheritance/Lookup.ql | 1 - .../PointsTo/inheritance/MetaClass.ql | 7 +- .../library-tests/PointsTo/inheritance/Mro.ql | 4 - .../PointsTo/inheritance/Self.ql | 1 - .../PointsTo/inheritance/SuperTypes.ql | 6 +- .../PointsTo/local/LocalPointsTo.ql | 7 +- .../library-tests/PointsTo/lookup/Lookup.ql | 17 +- .../PointsTo/metaclass/Failed.ql | 8 +- .../library-tests/PointsTo/metaclass/Mro.ql | 4 - .../library-tests/PointsTo/metaclass/Style.ql | 16 +- .../library-tests/PointsTo/metaclass/test.ql | 3 - .../test/library-tests/PointsTo/new/Call.ql | 4 +- .../library-tests/PointsTo/new/ClassMethod.ql | 5 +- .../library-tests/PointsTo/new/Dataflow.ql | 5 +- .../library-tests/PointsTo/new/Definitions.ql | 4 +- .../test/library-tests/PointsTo/new/Live.ql | 12 +- .../library-tests/PointsTo/new/NameSpace.ql | 28 +- .../library-tests/PointsTo/new/Parameters.ql | 6 +- .../PointsTo/new/PointsToMissing.ql | 5 +- .../PointsTo/new/PointsToNone.ql | 5 +- .../PointsTo/new/PointsToUnknown.ql | 2 - .../PointsTo/new/PointsToWithContext.ql | 5 +- .../PointsTo/new/PointsToWithType.ql | 5 +- .../library-tests/PointsTo/new/Precedes.ql | 5 +- .../library-tests/PointsTo/new/Reachable.ql | 1 - .../ql/test/library-tests/PointsTo/new/SSA.ql | 11 +- .../test/library-tests/PointsTo/new/Sanity.ql | 81 +++-- .../PointsTo/new/SourceEdgeDefinitions.ql | 2 - .../PointsTo/new/SourceNodeDefinitions.ql | 15 +- .../library-tests/PointsTo/new/SsaAttr.ql | 11 +- .../library-tests/PointsTo/new/SsaUses.ql | 1 - .../PointsTo/new/TestEvaluate.ql | 28 +- .../test/library-tests/PointsTo/new/Values.ql | 8 +- .../library-tests/PointsTo/new/VarUses.ql | 5 +- .../PointsTo/properties/Lookup.ql | 1 - .../PointsTo/properties/Values.ql | 4 +- .../library-tests/PointsTo/returns/Test.ql | 2 +- .../library-tests/PointsTo/subclass/Checks.ql | 3 +- .../PointsTo/subclass/TestEvaluate.ql | 12 +- .../library-tests/PointsTo/subclass/Values.ql | 3 - .../PointsTo/super/SuperMethodCall.ql | 9 +- .../library-tests/attributes/SelfAttribute.ql | 8 +- .../classes/abstract/Abstract.ql | 9 +- .../library-tests/classes/attr/class_attr.ql | 10 +- .../classes/attr/class_defined_attr.ql | 8 +- .../classes/attr/class_defines_attr.ql | 8 +- .../classes/attr/class_has_attr.ql | 8 +- .../test/library-tests/classes/attr/hash.ql | 13 +- .../ql/test/library-tests/classes/mro/C3.ql | 3 - .../ql/test/library-tests/comments/blocks.ql | 2 +- .../comments/blocks_not_example.ql | 3 +- .../ql/test/library-tests/comments/length.ql | 6 +- .../ql/test/library-tests/comments/lines.ql | 3 +- .../comments/lines_not_example.ql | 3 +- .../test/library-tests/comments/type_hint.ql | 2 - .../test/library-tests/comparisons/Compare.ql | 5 +- .../library-tests/comparisons/Compare2.ql | 13 +- .../comparisons/CompareControls.ql | 9 +- .../library-tests/comparisons/Implication.ql | 5 +- .../test/library-tests/comprehensions/Flow.ql | 2 +- .../dependencies/Dependencies.ql | 5 +- .../library-tests/descriptors/Descriptors.ql | 16 +- .../test/library-tests/descriptors/Methods.ql | 14 +- .../library-tests/encoding/CheckEncoding.ql | 6 +- .../test/library-tests/exceptions/Handles.ql | 2 +- .../ql/test/library-tests/exceptions/Legal.ql | 11 +- .../test/library-tests/exprs/ast/AstParent.ql | 6 +- .../ql/test/library-tests/exprs/ast/Child.ql | 1 - .../test/library-tests/exprs/compare/Test.ql | 2 - .../library-tests/exprs/strings/Strings.ql | 1 - .../library-tests/filters/generated/Filter.ql | 1 - .../library-tests/filters/tests/Filter.ql | 1 - .../formatting/FormatArguments.ql | 9 +- .../library-tests/formatting/FormatFields.ql | 1 - python/ql/test/library-tests/imports/Alias.ql | 2 +- .../test/library-tests/jump_to_defn/Remote.ql | 8 +- .../test/library-tests/jump_to_defn/Sanity.ql | 7 +- .../test/library-tests/jump_to_defn/Symbol.ql | 3 - .../test/library-tests/jump_to_defn/test.ql | 5 +- .../test/library-tests/locations/elif/test.ql | 2 +- .../implicit_concatenation/part_locations.ql | 11 +- .../locations/implicit_concatenation/parts.ql | 13 +- .../locations/implicit_concatenation/test.ql | 19 +- .../locations/negative_numbers/negative.ql | 16 +- .../locations/nested_classes/Test.ql | 2 - .../modules/duplicate_name/Modules.ql | 2 - .../modules/overlapping-paths/ModuleNames.ql | 1 - .../modules/spurious_init/ModuleNames.ql | 1 - .../ql/test/library-tests/objects/Literals.ql | 8 +- python/ql/test/library-tests/objects/Name.ql | 34 +-- .../ql/test/library-tests/objects/Strings.ql | 3 - .../library-tests/parameters/Annotations.ql | 2 - .../test/library-tests/parameters/Defaults.ql | 2 - .../test/library-tests/parameters/Special.ql | 13 +- .../test/library-tests/regex/Alternation.ql | 5 +- .../ql/test/library-tests/regex/Characters.ql | 3 - .../ql/test/library-tests/regex/FirstLast.ql | 4 +- .../test/library-tests/regex/GroupContents.ql | 5 +- python/ql/test/library-tests/regex/Mode.ql | 3 - .../ql/test/library-tests/regex/Qualified.ql | 2 - python/ql/test/library-tests/regex/Regex.ql | 4 +- .../ql/test/library-tests/scopes/Previous.ql | 2 +- .../security/sensitive/Sources.ql | 2 - .../test/library-tests/state_tracking/Test.ql | 14 +- .../state_tracking/Violations.ql | 15 +- .../library-tests/stmts/general/AstParent.ql | 7 +- .../stmts/general/SubExpressions.ql | 4 +- .../library-tests/stmts/raise_stmt/AST.ql | 5 +- .../test/library-tests/stmts/try_stmt/AST.ql | 5 +- .../test/library-tests/stmts/with_stmt/AST.ql | 5 +- .../taint/collections/TestTaint.ql | 3 +- .../taint/config/RockPaperScissors.ql | 4 +- .../test/library-tests/taint/config/Simple.ql | 4 +- .../taint/config/TaintedArgument.ql | 14 +- .../library-tests/taint/config/TestNode.ql | 5 +- .../library-tests/taint/config/TestSink.ql | 1 - .../library-tests/taint/config/TestSource.ql | 4 +- .../library-tests/taint/config/TestStep.ql | 9 +- .../library-tests/taint/dataflow/Dataflow.ql | 1 - .../library-tests/taint/dataflow/TestNode.ql | 3 +- .../test/library-tests/taint/example/Edges.ql | 21 +- .../taint/example/ExampleConfig.ql | 6 +- .../test/library-tests/taint/example/Nodes.ql | 5 +- .../taint/exception_traceback/TestNode.ql | 3 +- .../taint/exception_traceback/TestSource.ql | 8 +- .../taint/exception_traceback/TestStep.ql | 8 +- .../taint/extensions/TestNode.ql | 6 +- .../taint/extensions/TestStep.ql | 9 +- .../library-tests/taint/general/Contexts.ql | 7 +- .../taint/general/ModuleAttribute.ql | 2 - .../taint/general/ParamSource.ql | 28 +- .../taint/general/TaintSanity.ql | 39 +-- .../library-tests/taint/general/TestDefn.ql | 5 +- .../taint/general/TestSanitizers.ql | 3 - .../library-tests/taint/general/TestSink.ql | 4 +- .../library-tests/taint/general/TestSource.ql | 1 - .../library-tests/taint/general/TestStep.ql | 8 +- .../library-tests/taint/general/TestTaint.ql | 3 +- .../library-tests/taint/general/TestVar.ql | 5 +- .../taint/namedtuple/TestTaint.ql | 3 +- .../library-tests/taint/strings/TestStep.ql | 14 +- .../library-tests/taint/strings/TestTaint.ql | 3 +- .../taint/unpacking/TestTaint.ql | 3 +- python/ql/test/library-tests/thrift/Child.ql | 1 - python/ql/test/library-tests/thrift/File.ql | 5 +- .../ql/test/library-tests/thrift/Function.ql | 14 +- .../test/library-tests/thrift/References.ql | 1 - .../ql/test/library-tests/thrift/Service.ql | 2 - python/ql/test/library-tests/thrift/Test.ql | 2 - python/ql/test/library-tests/thrift/Value.ql | 3 +- .../library-tests/types/attributes/Test.ql | 4 +- .../types/classattr/ClassAttribute.ql | 17 +- .../types/classattr/ClassMember.ql | 16 +- .../types/classattr/SpecialAttribute.ql | 19 +- .../types/classes/FailedInference.ql | 7 +- .../types/classes/duplicate_base.ql | 2 - .../types/exceptions/ExitRaises.ql | 1 - .../library-tests/types/exceptions/Handles.ql | 2 - .../types/exceptions/Impossible.ql | 33 +- .../types/exceptions/LineRaises.ql | 7 +- .../library-tests/types/exceptions/Raises.ql | 9 +- .../types/exceptions/Reraises.ql | 4 +- .../library-tests/types/exceptions/Viable.ql | 5 +- .../library-tests/types/functions/Zope.ql | 1 - .../types/properties/Deleters.ql | 1 - .../library-tests/types/properties/Getters.ql | 1 - .../types/properties/PythonProperties.ql | 3 +- .../library-tests/types/properties/Setters.ql | 1 - .../variables/definitions/test.ql | 1 - .../library-tests/variables/scopes/free.ql | 7 +- .../library-tests/variables/scopes/globals.ql | 1 - .../library-tests/variables/scopes/locals.ql | 10 +- .../library-tests/variables/scopes/lookup.ql | 24 +- .../library-tests/variables/scopes/scopes.ql | 1 - .../web/client/requests/ClientHttpRequests.ql | 6 +- .../web/client/six/ClientHttpRequests.ql | 6 +- .../web/client/stdlib/ClientHttpRequests.ql | 6 +- .../query-tests/Metrics/ratios/CodeRatio.ql | 5 +- .../ql/test/query-tests/Resources/Dataflow.ql | 20 +- .../query-tests/Security/CWE-327/TestNode.ql | 1 - 491 files changed, 2649 insertions(+), 2747 deletions(-) diff --git a/python/ql/examples/snippets/builtin_object.ql b/python/ql/examples/snippets/builtin_object.ql index fd404aea563..7f552a5aa79 100644 --- a/python/ql/examples/snippets/builtin_object.ql +++ b/python/ql/examples/snippets/builtin_object.ql @@ -6,7 +6,7 @@ * builtin * object */ - + import python from Expr e, string name diff --git a/python/ql/examples/snippets/call.ql b/python/ql/examples/snippets/call.ql index d829802fd82..b326024a33c 100644 --- a/python/ql/examples/snippets/call.ql +++ b/python/ql/examples/snippets/call.ql @@ -5,7 +5,7 @@ * @tags call * function */ - + import python from Value len, CallNode call diff --git a/python/ql/examples/snippets/catch_exception.ql b/python/ql/examples/snippets/catch_exception.ql index e6f66a321c4..c117267d112 100644 --- a/python/ql/examples/snippets/catch_exception.ql +++ b/python/ql/examples/snippets/catch_exception.ql @@ -6,11 +6,11 @@ * try * exception */ - + import python from ExceptStmt ex, ClassValue cls -where +where cls.getName() = "MyExceptionClass" and ex.getType().pointsTo(cls) select ex diff --git a/python/ql/examples/snippets/conditional_expression.ql b/python/ql/examples/snippets/conditional_expression.ql index 3081d14757d..ee519aedb06 100644 --- a/python/ql/examples/snippets/conditional_expression.ql +++ b/python/ql/examples/snippets/conditional_expression.ql @@ -11,7 +11,8 @@ import python from IfExp e, ClassObject cls1, ClassObject cls2 -where - e.getBody().refersTo(_, cls1, _) and e.getOrelse().refersTo(_, cls2, _) and +where + e.getBody().refersTo(_, cls1, _) and + e.getOrelse().refersTo(_, cls2, _) and cls1 != cls2 -select e \ No newline at end of file +select e diff --git a/python/ql/examples/snippets/emptyblock.ql b/python/ql/examples/snippets/emptyblock.ql index 8f05150dc41..b45bb2f02c9 100644 --- a/python/ql/examples/snippets/emptyblock.ql +++ b/python/ql/examples/snippets/emptyblock.ql @@ -6,7 +6,7 @@ * block * statement */ - + import python from StmtList blk diff --git a/python/ql/examples/snippets/emptythen.ql b/python/ql/examples/snippets/emptythen.ql index 4c23c05ee71..bc017d4707a 100644 --- a/python/ql/examples/snippets/emptythen.ql +++ b/python/ql/examples/snippets/emptythen.ql @@ -1,7 +1,7 @@ /** * @id py/examples/emptythen * @name If statements with empty then branch - * @description Finds 'if' statements where the "then" branch + * @description Finds 'if' statements where the "then" branch * consists entirely of Pass statements * @tags if * then @@ -9,13 +9,13 @@ * conditional * branch */ - + import python from If i where not exists(Stmt s | - i.getStmt(_) = s and + i.getStmt(_) = s and not s instanceof Pass ) select i diff --git a/python/ql/examples/snippets/eq_true.ql b/python/ql/examples/snippets/eq_true.ql index 01c49d4d900..46091ea5474 100644 --- a/python/ql/examples/snippets/eq_true.ql +++ b/python/ql/examples/snippets/eq_true.ql @@ -6,7 +6,7 @@ * test * boolean */ - + import python from Compare eq diff --git a/python/ql/examples/snippets/equalitystmt.ql b/python/ql/examples/snippets/equalitystmt.ql index 674037ab2e6..60dd8880515 100644 --- a/python/ql/examples/snippets/equalitystmt.ql +++ b/python/ql/examples/snippets/equalitystmt.ql @@ -6,7 +6,7 @@ * equality * expression statement */ - + import python from ExprStmt e, Compare eq diff --git a/python/ql/examples/snippets/extend_class.ql b/python/ql/examples/snippets/extend_class.ql index 038fc78a9f2..cc4dd62647d 100644 --- a/python/ql/examples/snippets/extend_class.ql +++ b/python/ql/examples/snippets/extend_class.ql @@ -9,11 +9,11 @@ * subtype * supertype */ - + import python from ClassObject sub, ClassObject base -where +where base.getName() = "MyClass" and sub.getABaseType() = base select sub diff --git a/python/ql/examples/snippets/filename.ql b/python/ql/examples/snippets/filename.ql index eb8b9ccb7a2..579cceea47a 100644 --- a/python/ql/examples/snippets/filename.ql +++ b/python/ql/examples/snippets/filename.ql @@ -4,7 +4,7 @@ * @description Finds files called `spam.py` * @tags file */ - + import python from File f diff --git a/python/ql/examples/snippets/generator.ql b/python/ql/examples/snippets/generator.ql index c374895c8e6..573d8a2f757 100644 --- a/python/ql/examples/snippets/generator.ql +++ b/python/ql/examples/snippets/generator.ql @@ -10,4 +10,4 @@ import python from Function f where f.isGenerator() -select f \ No newline at end of file +select f diff --git a/python/ql/examples/snippets/integer_literal.ql b/python/ql/examples/snippets/integer_literal.ql index 1a1b4685ce8..debf88ca384 100644 --- a/python/ql/examples/snippets/integer_literal.ql +++ b/python/ql/examples/snippets/integer_literal.ql @@ -5,7 +5,7 @@ * @tags integer * literal */ - + import python from IntegerLiteral literal diff --git a/python/ql/examples/snippets/method_call.ql b/python/ql/examples/snippets/method_call.ql index c0b119c364c..9f78a4bb22f 100644 --- a/python/ql/examples/snippets/method_call.ql +++ b/python/ql/examples/snippets/method_call.ql @@ -5,11 +5,11 @@ * @tags call * method */ - + import python from AstNode call, PythonFunctionValue method -where +where method.getQualifiedName() = "MyClass.methodName" and method.getACall().getNode() = call select call diff --git a/python/ql/examples/snippets/new_instance.ql b/python/ql/examples/snippets/new_instance.ql index f6ede9fa8f6..c1293d6638c 100644 --- a/python/ql/examples/snippets/new_instance.ql +++ b/python/ql/examples/snippets/new_instance.ql @@ -6,7 +6,7 @@ * constructor * new */ - + import python from Call new, ClassValue cls diff --git a/python/ql/examples/snippets/override_method.ql b/python/ql/examples/snippets/override_method.ql index 81a02004e37..75c276df627 100644 --- a/python/ql/examples/snippets/override_method.ql +++ b/python/ql/examples/snippets/override_method.ql @@ -5,7 +5,7 @@ * @tags method * override */ - + import python from FunctionObject override, FunctionObject base diff --git a/python/ql/examples/snippets/print.ql b/python/ql/examples/snippets/print.ql index b48909fa108..1a560d48e3d 100644 --- a/python/ql/examples/snippets/print.ql +++ b/python/ql/examples/snippets/print.ql @@ -4,11 +4,11 @@ * @description Find print statements or calls to the builtin function 'print' * @tags print */ - + import python from AstNode print -where +where /* Python 2 without `from __future__ import print_function` */ print instanceof Print or diff --git a/python/ql/examples/snippets/private_access.ql b/python/ql/examples/snippets/private_access.ql index 5ea42e965d0..14548864579 100644 --- a/python/ql/examples/snippets/private_access.ql +++ b/python/ql/examples/snippets/private_access.ql @@ -1,19 +1,20 @@ /** * @id py/examples/private-access * @name Private access - * @description Find accesses to "private" attributes (those starting with an underscore) + * @description Find accesses to "private" attributes (those starting with an underscore) * @tags access * private */ - + import python predicate is_private(Attribute a) { - a.getName().matches("\\_%") and + a.getName().matches("\\_%") and not a.getName().matches("\\_\\_%\\_\\_") } from Attribute access -where is_private(access) and -not access.getObject().(Name).getId() = "self" +where + is_private(access) and + not access.getObject().(Name).getId() = "self" select access diff --git a/python/ql/examples/snippets/raise_exception.ql b/python/ql/examples/snippets/raise_exception.ql index 650af97ad6f..ce69c353780 100644 --- a/python/ql/examples/snippets/raise_exception.ql +++ b/python/ql/examples/snippets/raise_exception.ql @@ -6,13 +6,11 @@ * raise * exception */ - + import python from Raise raise, ClassValue ex where ex.getName() = "AnException" and - ( - raise.getException().pointsTo(ex.getASuperType()) - ) + raise.getException().pointsTo(ex.getASuperType()) select raise, "Don't raise instances of 'AnException'" diff --git a/python/ql/examples/snippets/raw_string.ql b/python/ql/examples/snippets/raw_string.ql index 3711d8d5171..78b1bbefb9a 100644 --- a/python/ql/examples/snippets/raw_string.ql +++ b/python/ql/examples/snippets/raw_string.ql @@ -1,11 +1,11 @@ /** * @id py/examples/raw-string * @name Raw string literals - * @description Finds string literals with an 'r' prefix + * @description Finds string literals with an 'r' prefix * @tags string * raw */ - + import python from StrConst s diff --git a/python/ql/examples/snippets/store_none.ql b/python/ql/examples/snippets/store_none.ql index dfcac497908..88aaac47f56 100644 --- a/python/ql/examples/snippets/store_none.ql +++ b/python/ql/examples/snippets/store_none.ql @@ -8,11 +8,11 @@ * collection * add */ - + import python from SubscriptNode store -where +where store.isStore() and store.getIndex().pointsTo(Value::named("None")) select store diff --git a/python/ql/examples/snippets/tryfinally.ql b/python/ql/examples/snippets/tryfinally.ql index f37b86f3fa6..bf5ea3c61a6 100644 --- a/python/ql/examples/snippets/tryfinally.ql +++ b/python/ql/examples/snippets/tryfinally.ql @@ -10,6 +10,7 @@ import python from Try t -where exists(t.getFinalbody()) - and not exists(t.getAHandler()) +where + exists(t.getFinalbody()) and + not exists(t.getAHandler()) select t diff --git a/python/ql/src/Classes/ConflictingAttributesInBaseClasses.ql b/python/ql/src/Classes/ConflictingAttributesInBaseClasses.ql index 44be7ac9157..b4829809135 100644 --- a/python/ql/src/Classes/ConflictingAttributesInBaseClasses.ql +++ b/python/ql/src/Classes/ConflictingAttributesInBaseClasses.ql @@ -15,13 +15,13 @@ import python predicate does_nothing(PyFunctionObject f) { not exists(Stmt s | s.getScope() = f.getFunction() | - not s instanceof Pass and not ((ExprStmt)s).getValue() = f.getFunction().getDocString() + not s instanceof Pass and not s.(ExprStmt).getValue() = f.getFunction().getDocString() ) } /* If a method performs a super() call then it is OK as the 'overridden' method will get called */ predicate calls_super(FunctionObject f) { - exists(Call sup, Call meth, Attribute attr, GlobalVariable v | + exists(Call sup, Call meth, Attribute attr, GlobalVariable v | meth.getScope() = f.getFunction() and meth.getFunc() = attr and attr.getObject() = sup and @@ -33,25 +33,29 @@ predicate calls_super(FunctionObject f) { /** Holds if the given name is white-listed for some reason */ predicate whitelisted(string name) { - /* The standard library specifically recommends this :( - * See https://docs.python.org/3/library/socketserver.html#asynchronous-mixins */ + /* + * The standard library specifically recommends this :( + * See https://docs.python.org/3/library/socketserver.html#asynchronous-mixins + */ + name = "process_request" } -from ClassObject c, ClassObject b1, ClassObject b2, string name, -int i1, int i2, Object o1, Object o2 -where c.getBaseType(i1) = b1 and -c.getBaseType(i2) = b2 and -i1 < i2 and o1 != o2 and -o1 = b1.lookupAttribute(name) and -o2 = b2.lookupAttribute(name) and -not name.matches("\\_\\_%\\_\\_") and -not calls_super(o1) and -not does_nothing(o2) and -not whitelisted(name) and -not o1.overrides(o2) and -not o2.overrides(o1) and -not c.declaresAttribute(name) - -select c, "Base classes have conflicting values for attribute '" + name + "': $@ and $@.", o1, o1.toString(), o2, o2.toString() - +from + ClassObject c, ClassObject b1, ClassObject b2, string name, int i1, int i2, Object o1, Object o2 +where + c.getBaseType(i1) = b1 and + c.getBaseType(i2) = b2 and + i1 < i2 and + o1 != o2 and + o1 = b1.lookupAttribute(name) and + o2 = b2.lookupAttribute(name) and + not name.matches("\\_\\_%\\_\\_") and + not calls_super(o1) and + not does_nothing(o2) and + not whitelisted(name) and + not o1.overrides(o2) and + not o2.overrides(o1) and + not c.declaresAttribute(name) +select c, "Base classes have conflicting values for attribute '" + name + "': $@ and $@.", o1, + o1.toString(), o2, o2.toString() diff --git a/python/ql/src/Classes/DefineEqualsWhenAddingAttributes.ql b/python/ql/src/Classes/DefineEqualsWhenAddingAttributes.ql index 5b80f2fd7bf..8bf7d24b729 100644 --- a/python/ql/src/Classes/DefineEqualsWhenAddingAttributes.ql +++ b/python/ql/src/Classes/DefineEqualsWhenAddingAttributes.ql @@ -15,7 +15,9 @@ import semmle.python.SelfAttribute import Equality predicate class_stores_to_attribute(ClassObject cls, SelfAttributeStore store, string name) { - exists(FunctionObject f | f = cls.declaredAttribute(_) and store.getScope() = f.getFunction() and store.getName() = name) and + exists(FunctionObject f | + f = cls.declaredAttribute(_) and store.getScope() = f.getFunction() and store.getName() = name + ) and /* Exclude classes used as metaclasses */ not cls.getASuperType() = theTypeType() } @@ -30,23 +32,26 @@ predicate should_override_eq(ClassObject cls, Object base_eq) { ) } -/** Does the non-overridden __eq__ method access the attribute, +/** + * Does the non-overridden __eq__ method access the attribute, * which implies that the __eq__ method does not need to be overridden. */ predicate superclassEqExpectsAttribute(ClassObject cls, PyFunctionObject base_eq, string attrname) { not cls.declaresAttribute("__eq__") and exists(ClassObject sup | sup = cls.getABaseType() and sup.declaredAttribute("__eq__") = base_eq | - exists(SelfAttributeRead store | - store.getName() = attrname | + exists(SelfAttributeRead store | store.getName() = attrname | store.getScope() = base_eq.getFunction() ) ) } from ClassObject cls, SelfAttributeStore store, Object base_eq -where class_stores_to_attribute(cls, store, _) and should_override_eq(cls, base_eq) and -/* Don't report overridden unittest.TestCase. -- TestCase overrides __eq__, but subclasses do not really need to. */ -not cls.getASuperType().getName() = "TestCase" and -not superclassEqExpectsAttribute(cls, base_eq, store.getName()) - -select cls, "The class '" + cls.getName() + "' does not override $@, but adds the new attribute $@.", base_eq, "'__eq__'", store, store.getName() +where + class_stores_to_attribute(cls, store, _) and + should_override_eq(cls, base_eq) and + /* Don't report overridden unittest.TestCase. -- TestCase overrides __eq__, but subclasses do not really need to. */ + not cls.getASuperType().getName() = "TestCase" and + not superclassEqExpectsAttribute(cls, base_eq, store.getName()) +select cls, + "The class '" + cls.getName() + "' does not override $@, but adds the new attribute $@.", base_eq, + "'__eq__'", store, store.getName() diff --git a/python/ql/src/Classes/EqualsOrHash.ql b/python/ql/src/Classes/EqualsOrHash.ql index c748675850c..795e7f4c0ff 100644 --- a/python/ql/src/Classes/EqualsOrHash.ql +++ b/python/ql/src/Classes/EqualsOrHash.ql @@ -14,8 +14,11 @@ import python CallableValue defines_equality(ClassValue c, string name) { - (name = "__eq__" or major_version() = 2 and name = "__cmp__") - and + ( + name = "__eq__" + or + major_version() = 2 and name = "__cmp__" + ) and result = c.declaredAttribute(name) } @@ -26,8 +29,12 @@ CallableValue implemented_method(ClassValue c, string name) { } string unimplemented_method(ClassValue c) { - not exists(defines_equality(c, _)) and - (result = "__eq__" and major_version() = 3 or major_version() = 2 and result = "__eq__ or __cmp__") + not exists(defines_equality(c, _)) and + ( + result = "__eq__" and major_version() = 3 + or + major_version() = 2 and result = "__eq__ or __cmp__" + ) or /* Python 3 automatically makes classes unhashable if __eq__ is defined, but __hash__ is not */ not c.declaresAttribute(result) and result = "__hash__" and major_version() = 2 @@ -41,13 +48,15 @@ predicate unhashable(ClassValue cls) { } predicate violates_hash_contract(ClassValue c, string present, string missing, Value method) { - not unhashable(c) and - missing = unimplemented_method(c) and - method = implemented_method(c, present) and - not c.failedInference(_) + not unhashable(c) and + missing = unimplemented_method(c) and + method = implemented_method(c, present) and + not c.failedInference(_) } from ClassValue c, string present, string missing, CallableValue method -where violates_hash_contract(c, present, missing, method) and -exists(c.getScope()) // Suppress results that aren't from source -select method, "Class $@ implements " + present + " but does not define " + missing + ".", c, c.getName() +where + violates_hash_contract(c, present, missing, method) and + exists(c.getScope()) // Suppress results that aren't from source +select method, "Class $@ implements " + present + " but does not define " + missing + ".", c, + c.getName() diff --git a/python/ql/src/Classes/EqualsOrNotEquals.ql b/python/ql/src/Classes/EqualsOrNotEquals.ql index 606718bac6b..7457de441b0 100644 --- a/python/ql/src/Classes/EqualsOrNotEquals.ql +++ b/python/ql/src/Classes/EqualsOrNotEquals.ql @@ -13,16 +13,12 @@ import python import Equality -string equals_or_ne() { - result = "__eq__" or result = "__ne__" -} +string equals_or_ne() { result = "__eq__" or result = "__ne__" } predicate total_ordering(Class cls) { - exists(Attribute a | a = cls.getADecorator() | - a.getName() = "total_ordering") + exists(Attribute a | a = cls.getADecorator() | a.getName() = "total_ordering") or - exists(Name n | n = cls.getADecorator() | - n.getId() = "total_ordering") + exists(Name n | n = cls.getADecorator() | n.getId() = "total_ordering") } CallableValue implemented_method(ClassValue c, string name) { @@ -33,18 +29,20 @@ string unimplemented_method(ClassValue c) { not c.declaresAttribute(result) and result = equals_or_ne() } -predicate violates_equality_contract(ClassValue c, string present, string missing, CallableValue method) { - missing = unimplemented_method(c) and - method = implemented_method(c, present) and - not c.failedInference(_) and - not total_ordering(c.getScope()) and - /* Python 3 automatically implements __ne__ if __eq__ is defined, but not vice-versa */ - not (major_version() = 3 and present = "__eq__" and missing = "__ne__") and - not method.getScope() instanceof DelegatingEqualityMethod and - not c.lookup(missing).(CallableValue).getScope() instanceof DelegatingEqualityMethod +predicate violates_equality_contract( + ClassValue c, string present, string missing, CallableValue method +) { + missing = unimplemented_method(c) and + method = implemented_method(c, present) and + not c.failedInference(_) and + not total_ordering(c.getScope()) and + /* Python 3 automatically implements __ne__ if __eq__ is defined, but not vice-versa */ + not (major_version() = 3 and present = "__eq__" and missing = "__ne__") and + not method.getScope() instanceof DelegatingEqualityMethod and + not c.lookup(missing).(CallableValue).getScope() instanceof DelegatingEqualityMethod } from ClassValue c, string present, string missing, CallableValue method where violates_equality_contract(c, present, missing, method) - -select method, "Class $@ implements " + present + " but does not implement " + missing + ".", c, c.getName() +select method, "Class $@ implements " + present + " but does not implement " + missing + ".", c, + c.getName() diff --git a/python/ql/src/Classes/IncompleteOrdering.ql b/python/ql/src/Classes/IncompleteOrdering.ql index 767e7ce6c37..7755696bd45 100644 --- a/python/ql/src/Classes/IncompleteOrdering.ql +++ b/python/ql/src/Classes/IncompleteOrdering.ql @@ -13,17 +13,18 @@ import python predicate total_ordering(Class cls) { - exists(Attribute a | a = cls.getADecorator() | - a.getName() = "total_ordering") + exists(Attribute a | a = cls.getADecorator() | a.getName() = "total_ordering") or - exists(Name n | n = cls.getADecorator() | - n.getId() = "total_ordering") + exists(Name n | n = cls.getADecorator() | n.getId() = "total_ordering") } string ordering_name(int n) { - result = "__lt__" and n = 1 or - result = "__le__" and n = 2 or - result = "__gt__" and n = 3 or + result = "__lt__" and n = 1 + or + result = "__le__" and n = 2 + or + result = "__gt__" and n = 3 + or result = "__ge__" and n = 4 } @@ -32,8 +33,7 @@ predicate overrides_ordering_method(ClassValue c, string name) { ( c.declaresAttribute(name) or - exists(ClassValue sup | - sup = c.getASuperType() and not sup = Value::named("object") | + exists(ClassValue sup | sup = c.getASuperType() and not sup = Value::named("object") | sup.declaresAttribute(name) ) ) @@ -41,15 +41,14 @@ predicate overrides_ordering_method(ClassValue c, string name) { string unimplemented_ordering(ClassValue c, int n) { not c = Value::named("object") and - not overrides_ordering_method(c, result) and + not overrides_ordering_method(c, result) and result = ordering_name(n) } string unimplemented_ordering_methods(ClassValue c, int n) { n = 0 and result = "" and exists(unimplemented_ordering(c, _)) or - exists(string prefix, int nm1 | - n = nm1 + 1 and prefix = unimplemented_ordering_methods(c, nm1) | + exists(string prefix, int nm1 | n = nm1 + 1 and prefix = unimplemented_ordering_methods(c, nm1) | prefix = "" and result = unimplemented_ordering(c, n) or result = prefix and not exists(unimplemented_ordering(c, n)) and n < 5 @@ -60,16 +59,15 @@ string unimplemented_ordering_methods(ClassValue c, int n) { Value ordering_method(ClassValue c, string name) { /* If class doesn't declare a method then don't blame this class (the superclass will be blamed). */ - name = ordering_name(_) and result = c.declaredAttribute(name) + name = ordering_name(_) and result = c.declaredAttribute(name) } from ClassValue c, Value ordering, string name -where not c.failedInference(_) and -not total_ordering(c.getScope()) -and ordering = ordering_method(c, name) and -exists(unimplemented_ordering(c, _)) - -select c, "Class " + c.getName() + " implements $@, but does not implement " + unimplemented_ordering_methods(c, 4) + ".", -ordering, name - - +where + not c.failedInference(_) and + not total_ordering(c.getScope()) and + ordering = ordering_method(c, name) and + exists(unimplemented_ordering(c, _)) +select c, + "Class " + c.getName() + " implements $@, but does not implement " + + unimplemented_ordering_methods(c, 4) + ".", ordering, name diff --git a/python/ql/src/Classes/InconsistentMRO.ql b/python/ql/src/Classes/InconsistentMRO.ql index 08b1016086c..a9541bc9023 100644 --- a/python/ql/src/Classes/InconsistentMRO.ql +++ b/python/ql/src/Classes/InconsistentMRO.ql @@ -13,15 +13,18 @@ import python ClassObject left_base(ClassObject type, ClassObject base) { - exists(int i | i > 0 and type.getBaseType(i) = base and result = type.getBaseType(i-1)) + exists(int i | i > 0 and type.getBaseType(i) = base and result = type.getBaseType(i - 1)) } predicate invalid_mro(ClassObject t, ClassObject left, ClassObject right) { t.isNewStyle() and - left = left_base(t, right) and left = right.getAnImproperSuperType() + left = left_base(t, right) and + left = right.getAnImproperSuperType() } from ClassObject t, ClassObject left, ClassObject right where invalid_mro(t, left, right) -select t, "Construction of class " + t.getName() + " can fail due to invalid method resolution order(MRO) for bases $@ and $@.", -left, left.getName(), right, right.getName() \ No newline at end of file +select t, + "Construction of class " + t.getName() + + " can fail due to invalid method resolution order(MRO) for bases $@ and $@.", left, + left.getName(), right, right.getName() diff --git a/python/ql/src/Classes/InitCallsSubclassMethod.ql b/python/ql/src/Classes/InitCallsSubclassMethod.ql index 5a191d861bf..b0e1cc0d8f0 100644 --- a/python/ql/src/Classes/InitCallsSubclassMethod.ql +++ b/python/ql/src/Classes/InitCallsSubclassMethod.ql @@ -13,23 +13,18 @@ import python - -from ClassObject supercls, string method, Call call, - FunctionObject overriding, FunctionObject overridden - +from + ClassObject supercls, string method, Call call, FunctionObject overriding, + FunctionObject overridden where -exists(FunctionObject init, SelfAttribute sa | - supercls.declaredAttribute("__init__") = init and - call.getScope() = init.getFunction() and call.getFunc() = sa | - sa.getName() = method and - overridden = supercls.declaredAttribute(method) and - overriding.overrides(overridden) -) - -select call, "Call to self.$@ in __init__ method, which is overridden by $@.", - overridden, method, - overriding, overriding.descriptiveString() - - - - + exists(FunctionObject init, SelfAttribute sa | + supercls.declaredAttribute("__init__") = init and + call.getScope() = init.getFunction() and + call.getFunc() = sa + | + sa.getName() = method and + overridden = supercls.declaredAttribute(method) and + overriding.overrides(overridden) + ) +select call, "Call to self.$@ in __init__ method, which is overridden by $@.", overridden, method, + overriding, overriding.descriptiveString() diff --git a/python/ql/src/Classes/MaybeUndefinedClassAttribute.ql b/python/ql/src/Classes/MaybeUndefinedClassAttribute.ql index ec2e91987dd..ca8a260b863 100644 --- a/python/ql/src/Classes/MaybeUndefinedClassAttribute.ql +++ b/python/ql/src/Classes/MaybeUndefinedClassAttribute.ql @@ -16,26 +16,29 @@ import ClassAttributes predicate guarded_by_other_attribute(SelfAttributeRead a, CheckClass c) { c.sometimesDefines(a.getName()) and - exists(SelfAttributeRead guard, If i | + exists(SelfAttributeRead guard, If i | i.contains(a) and - c.assignedInInit(guard.getName()) | + c.assignedInInit(guard.getName()) + | i.getTest() = guard or i.getTest().contains(guard) ) } - predicate maybe_undefined_class_attribute(SelfAttributeRead a, CheckClass c) { c.sometimesDefines(a.getName()) and not c.alwaysDefines(a.getName()) and - c.interestingUndefined(a) and + c.interestingUndefined(a) and not guarded_by_other_attribute(a, c) } from Attribute a, ClassObject c, SelfAttributeStore sa -where maybe_undefined_class_attribute(a, c) and -sa.getClass() = c.getPyClass() and sa.getName() = a.getName() -select a, "Attribute '" + a.getName() + -"' is not defined in the class body nor in the __init__() method, but it is defined $@", sa, "here" - +where + maybe_undefined_class_attribute(a, c) and + sa.getClass() = c.getPyClass() and + sa.getName() = a.getName() +select a, + "Attribute '" + a.getName() + + "' is not defined in the class body nor in the __init__() method, but it is defined $@", sa, + "here" diff --git a/python/ql/src/Classes/MissingCallToDel.ql b/python/ql/src/Classes/MissingCallToDel.ql index d08c8399669..b54a9b8c782 100644 --- a/python/ql/src/Classes/MissingCallToDel.ql +++ b/python/ql/src/Classes/MissingCallToDel.ql @@ -13,14 +13,12 @@ import python import MethodCallOrder - from ClassObject self, FunctionObject missing - where missing_call_to_superclass_method(self, _, missing, "__del__") and not missing.neverReturns() and not self.failedInference() and not missing.isBuiltin() -select self, "Class " + self.getName() + " may not be cleaned up properly as $@ is not called during deletion.", -missing, missing.descriptiveString() - +select self, + "Class " + self.getName() + " may not be cleaned up properly as $@ is not called during deletion.", + missing, missing.descriptiveString() diff --git a/python/ql/src/Classes/MissingCallToInit.ql b/python/ql/src/Classes/MissingCallToInit.ql index ad137f817f4..bb6121e33b6 100644 --- a/python/ql/src/Classes/MissingCallToInit.ql +++ b/python/ql/src/Classes/MissingCallToInit.ql @@ -14,7 +14,6 @@ import python import MethodCallOrder from ClassObject self, FunctionObject initializer, FunctionObject missing - where self.lookupAttribute("__init__") = initializer and missing_call_to_superclass_method(self, initializer, missing, "__init__") and @@ -24,5 +23,6 @@ where not self.failedInference() and not missing.isBuiltin() and not self.isAbstract() -select self, "Class " + self.getName() + " may not be initialized properly as $@ is not called from its $@.", -missing, missing.descriptiveString(), initializer, "__init__ method" \ No newline at end of file +select self, + "Class " + self.getName() + " may not be initialized properly as $@ is not called from its $@.", + missing, missing.descriptiveString(), initializer, "__init__ method" diff --git a/python/ql/src/Classes/MutatingDescriptor.ql b/python/ql/src/Classes/MutatingDescriptor.ql index 65659526f57..1f1188c2830 100644 --- a/python/ql/src/Classes/MutatingDescriptor.ql +++ b/python/ql/src/Classes/MutatingDescriptor.ql @@ -15,8 +15,7 @@ import python predicate mutates_descriptor(ClassObject cls, SelfAttributeStore s) { cls.isDescriptorType() and exists(PyFunctionObject f, PyFunctionObject get_set | - exists(string name | - cls.lookupAttribute(name) = get_set | + exists(string name | cls.lookupAttribute(name) = get_set | name = "__get__" or name = "__set__" or name = "__delete__" ) and cls.lookupAttribute(_) = f and @@ -27,7 +26,7 @@ predicate mutates_descriptor(ClassObject cls, SelfAttributeStore s) { } from ClassObject cls, SelfAttributeStore s -where -mutates_descriptor(cls, s) - -select s, "Mutation of descriptor $@ object may lead to action-at-a-distance effects or race conditions for properties.", cls, cls.getName() \ No newline at end of file +where mutates_descriptor(cls, s) +select s, + "Mutation of descriptor $@ object may lead to action-at-a-distance effects or race conditions for properties.", + cls, cls.getName() diff --git a/python/ql/src/Classes/OverwritingAttributeInSuperClass.ql b/python/ql/src/Classes/OverwritingAttributeInSuperClass.ql index bd2be2ed379..168348e7b1c 100644 --- a/python/ql/src/Classes/OverwritingAttributeInSuperClass.ql +++ b/python/ql/src/Classes/OverwritingAttributeInSuperClass.ql @@ -13,59 +13,80 @@ import python - class InitCallStmt extends ExprStmt { - InitCallStmt() { exists(Call call, Attribute attr | call = this.getValue() and attr = call.getFunc() | - attr.getName() = "__init__") + attr.getName() = "__init__" + ) } - } predicate overwrites_which(Function subinit, AssignStmt write_attr, string which) { - write_attr.getScope() = subinit and self_write_stmt(write_attr, _) and + write_attr.getScope() = subinit and + self_write_stmt(write_attr, _) and exists(Stmt top | top.contains(write_attr) or top = write_attr | - (exists(int i, int j, InitCallStmt call | call.getScope() = subinit | i > j and top = subinit.getStmt(i) and call = subinit.getStmt(j) and which = "superclass") - or - exists(int i, int j, InitCallStmt call | call.getScope() = subinit | i < j and top = subinit.getStmt(i) and call = subinit.getStmt(j) and which = "subclass") - ) - ) + ( + exists(int i, int j, InitCallStmt call | call.getScope() = subinit | + i > j and top = subinit.getStmt(i) and call = subinit.getStmt(j) and which = "superclass" + ) + or + exists(int i, int j, InitCallStmt call | call.getScope() = subinit | + i < j and top = subinit.getStmt(i) and call = subinit.getStmt(j) and which = "subclass" + ) + ) + ) } predicate self_write_stmt(Stmt s, string attr) { - exists(Attribute a, Name self | self = a.getObject() and s.contains(a) and self.getId() = "self" and a.getCtx() instanceof Store and a.getName() = attr) + exists(Attribute a, Name self | + self = a.getObject() and + s.contains(a) and + self.getId() = "self" and + a.getCtx() instanceof Store and + a.getName() = attr + ) } predicate both_assign_attribute(Stmt s1, Stmt s2, Function f1, Function f2) { - exists(string name | s1.getScope() = f1 and s2.getScope() = f2 and self_write_stmt(s1, name) and self_write_stmt(s2, name)) + exists(string name | + s1.getScope() = f1 and + s2.getScope() = f2 and + self_write_stmt(s1, name) and + self_write_stmt(s2, name) + ) } -predicate attribute_overwritten(AssignStmt overwrites, AssignStmt overwritten, string name, string classtype, string classname) -{ - exists(FunctionObject superinit, FunctionObject subinit, ClassObject superclass, ClassObject subclass, AssignStmt subattr, AssignStmt superattr | - (classtype = "superclass" and classname = superclass.getName() and overwrites = subattr and overwritten = superattr or - classtype = "subclass" and classname = subclass.getName() and overwrites = superattr and overwritten = subattr) - and - /* OK if overwritten in subclass and is a class attribute */ - (not exists(superclass.declaredAttribute(name)) or classtype = "subclass") - and - superclass.declaredAttribute("__init__") = superinit - and - subclass.declaredAttribute("__init__") = subinit - and - superclass = subclass.getASuperType() - and - overwrites_which(subinit.getFunction(), subattr, classtype) - and - both_assign_attribute(subattr, superattr, subinit.getFunction(), superinit.getFunction()) - and - self_write_stmt(superattr, name) - ) +predicate attribute_overwritten( + AssignStmt overwrites, AssignStmt overwritten, string name, string classtype, string classname +) { + exists( + FunctionObject superinit, FunctionObject subinit, ClassObject superclass, ClassObject subclass, + AssignStmt subattr, AssignStmt superattr + | + ( + classtype = "superclass" and + classname = superclass.getName() and + overwrites = subattr and + overwritten = superattr + or + classtype = "subclass" and + classname = subclass.getName() and + overwrites = superattr and + overwritten = subattr + ) and + /* OK if overwritten in subclass and is a class attribute */ + (not exists(superclass.declaredAttribute(name)) or classtype = "subclass") and + superclass.declaredAttribute("__init__") = superinit and + subclass.declaredAttribute("__init__") = subinit and + superclass = subclass.getASuperType() and + overwrites_which(subinit.getFunction(), subattr, classtype) and + both_assign_attribute(subattr, superattr, subinit.getFunction(), superinit.getFunction()) and + self_write_stmt(superattr, name) + ) } - from string classtype, AssignStmt overwrites, AssignStmt overwritten, string name, string classname where attribute_overwritten(overwrites, overwritten, name, classtype, classname) - -select overwrites, "Assignment overwrites attribute " + name + ", which was previously defined in " + classtype + " $@.", overwritten, classname +select overwrites, + "Assignment overwrites attribute " + name + ", which was previously defined in " + classtype + + " $@.", overwritten, classname diff --git a/python/ql/src/Classes/PropertyInOldStyleClass.ql b/python/ql/src/Classes/PropertyInOldStyleClass.ql index fb2c822a573..ff2bf13a9f8 100644 --- a/python/ql/src/Classes/PropertyInOldStyleClass.ql +++ b/python/ql/src/Classes/PropertyInOldStyleClass.ql @@ -14,4 +14,6 @@ import python from PropertyObject prop, ClassObject cls where cls.declaredAttribute(_) = prop and not cls.failedInference() and not cls.isNewStyle() -select prop, "Property " + prop.getName() + " will not work properly, as class " + cls.getName() + " is an old-style class." +select prop, + "Property " + prop.getName() + " will not work properly, as class " + cls.getName() + + " is an old-style class." diff --git a/python/ql/src/Classes/ShouldBeContextManager.ql b/python/ql/src/Classes/ShouldBeContextManager.ql index d7394728935..e6bf946b65a 100644 --- a/python/ql/src/Classes/ShouldBeContextManager.ql +++ b/python/ql/src/Classes/ShouldBeContextManager.ql @@ -16,4 +16,6 @@ import python from ClassObject c where not c.isC() and not c.isContextManager() and exists(c.declaredAttribute("__del__")) -select c, "Class " + c.getName() + " implements __del__ (presumably to release some resource). Consider making it a context manager." +select c, + "Class " + c.getName() + + " implements __del__ (presumably to release some resource). Consider making it a context manager." diff --git a/python/ql/src/Classes/SubclassShadowing.ql b/python/ql/src/Classes/SubclassShadowing.ql index 6cdd9edf01d..ed1a79869b0 100644 --- a/python/ql/src/Classes/SubclassShadowing.ql +++ b/python/ql/src/Classes/SubclassShadowing.ql @@ -11,30 +11,36 @@ * @id py/attribute-shadows-method */ -/* Determine if a class defines a method that is shadowed by an attribute - defined in a super-class -*/ +/* + * Determine if a class defines a method that is shadowed by an attribute + * defined in a super-class + */ /* Need to find attributes defined in superclass (only in __init__?) */ - import python -predicate shadowed_by_super_class(ClassObject c, ClassObject supercls, Assign assign, FunctionObject f) -{ - c.getASuperType() = supercls and c.declaredAttribute(_) = f and +predicate shadowed_by_super_class( + ClassObject c, ClassObject supercls, Assign assign, FunctionObject f +) { + c.getASuperType() = supercls and + c.declaredAttribute(_) = f and exists(FunctionObject init, Attribute attr | supercls.declaredAttribute("__init__") = init and attr = assign.getATarget() and - ((Name)attr.getObject()).getId() = "self" and + attr.getObject().(Name).getId() = "self" and attr.getName() = f.getName() and - assign.getScope() = ((FunctionExpr)init.getOrigin()).getInnerScope() + assign.getScope() = init.getOrigin().(FunctionExpr).getInnerScope() ) and - /* It's OK if the super class defines the method as well. - * We assume that the original method must have been defined for a reason. */ + /* + * It's OK if the super class defines the method as well. + * We assume that the original method must have been defined for a reason. + */ + not supercls.hasAttribute(f.getName()) } from ClassObject c, ClassObject supercls, Assign assign, FunctionObject shadowed where shadowed_by_super_class(c, supercls, assign, shadowed) -select shadowed.getOrigin(), "Method " + shadowed.getName() + " is shadowed by $@ in super class '"+ supercls.getName() + "'.", assign, "an attribute" - +select shadowed.getOrigin(), + "Method " + shadowed.getName() + " is shadowed by $@ in super class '" + supercls.getName() + "'.", + assign, "an attribute" diff --git a/python/ql/src/Classes/SuperInOldStyleClass.ql b/python/ql/src/Classes/SuperInOldStyleClass.ql index b6c7649a1ca..aa4c62c6f08 100644 --- a/python/ql/src/Classes/SuperInOldStyleClass.ql +++ b/python/ql/src/Classes/SuperInOldStyleClass.ql @@ -13,10 +13,15 @@ import python predicate uses_of_super_in_old_style_class(Call s) { - exists(Function f, ClassObject c | s.getScope() = f and f.getScope() = c.getPyClass() and not c.failedInference() and - not c.isNewStyle() and ((Name)s.getFunc()).getId() = "super") + exists(Function f, ClassObject c | + s.getScope() = f and + f.getScope() = c.getPyClass() and + not c.failedInference() and + not c.isNewStyle() and + s.getFunc().(Name).getId() = "super" + ) } from Call c where uses_of_super_in_old_style_class(c) -select c, "super() will not work in old-style classes" \ No newline at end of file +select c, "super() will not work in old-style classes" diff --git a/python/ql/src/Classes/SuperclassDelCalledMultipleTimes.ql b/python/ql/src/Classes/SuperclassDelCalledMultipleTimes.ql index b0e4a13469d..cd4c74a5e86 100644 --- a/python/ql/src/Classes/SuperclassDelCalledMultipleTimes.ql +++ b/python/ql/src/Classes/SuperclassDelCalledMultipleTimes.ql @@ -13,15 +13,16 @@ import python import MethodCallOrder - from ClassObject self, FunctionObject multi -where -multiple_calls_to_superclass_method(self, multi, "__del__") and -not multiple_calls_to_superclass_method(self.getABaseType(), multi, "__del__") and -not exists(FunctionObject better | - multiple_calls_to_superclass_method(self, better, "__del__") and - better.overrides(multi) -) and -not self.failedInference() -select self, "Class " + self.getName() + " may not be cleaned up properly as $@ may be called multiple times during destruction.", -multi, multi.descriptiveString() +where + multiple_calls_to_superclass_method(self, multi, "__del__") and + not multiple_calls_to_superclass_method(self.getABaseType(), multi, "__del__") and + not exists(FunctionObject better | + multiple_calls_to_superclass_method(self, better, "__del__") and + better.overrides(multi) + ) and + not self.failedInference() +select self, + "Class " + self.getName() + + " may not be cleaned up properly as $@ may be called multiple times during destruction.", multi, + multi.descriptiveString() diff --git a/python/ql/src/Classes/SuperclassInitCalledMultipleTimes.ql b/python/ql/src/Classes/SuperclassInitCalledMultipleTimes.ql index 723527e1de8..71d05533fde 100644 --- a/python/ql/src/Classes/SuperclassInitCalledMultipleTimes.ql +++ b/python/ql/src/Classes/SuperclassInitCalledMultipleTimes.ql @@ -14,13 +14,16 @@ import python import MethodCallOrder from ClassObject self, FunctionObject multi -where multi != theObjectType().lookupAttribute("__init__") and -multiple_calls_to_superclass_method(self, multi, "__init__") and -not multiple_calls_to_superclass_method(self.getABaseType(), multi, "__init__") and -not exists(FunctionObject better | - multiple_calls_to_superclass_method(self, better, "__init__") and - better.overrides(multi) -) and -not self.failedInference() -select self, "Class " + self.getName() + " may not be initialized properly as $@ may be called multiple times during initialization.", -multi, multi.descriptiveString() +where + multi != theObjectType().lookupAttribute("__init__") and + multiple_calls_to_superclass_method(self, multi, "__init__") and + not multiple_calls_to_superclass_method(self.getABaseType(), multi, "__init__") and + not exists(FunctionObject better | + multiple_calls_to_superclass_method(self, better, "__init__") and + better.overrides(multi) + ) and + not self.failedInference() +select self, + "Class " + self.getName() + + " may not be initialized properly as $@ may be called multiple times during initialization.", + multi, multi.descriptiveString() diff --git a/python/ql/src/Classes/UndefinedClassAttribute.ql b/python/ql/src/Classes/UndefinedClassAttribute.ql index 6619fd031eb..bdbbcbf2496 100644 --- a/python/ql/src/Classes/UndefinedClassAttribute.ql +++ b/python/ql/src/Classes/UndefinedClassAttribute.ql @@ -32,4 +32,3 @@ predicate report_undefined_class_attribute(Attribute a, ClassObject c, string na from Attribute a, ClassObject c, string name where report_undefined_class_attribute(a, c, name) select a, "Attribute '" + name + "' is not defined in either the class body or in any method" - diff --git a/python/ql/src/Classes/UselessClass.ql b/python/ql/src/Classes/UselessClass.ql index e04ea103ad6..2c872420049 100644 --- a/python/ql/src/Classes/UselessClass.ql +++ b/python/ql/src/Classes/UselessClass.ql @@ -21,63 +21,68 @@ predicate does_not_define_special_method(Class cls) { not exists(Function f | f = cls.getAMethod() and f.isSpecialMethod()) } - predicate no_inheritance(Class c) { not exists(ClassObject cls, ClassObject other | - cls.getPyClass() = c and - other != theObjectType() | + cls.getPyClass() = c and + other != theObjectType() + | other.getABaseType() = cls or cls.getABaseType() = other - ) - and + ) and not exists(Expr base | base = c.getABase() | - not base instanceof Name or ((Name)base).getId() != "object" + not base instanceof Name or base.(Name).getId() != "object" ) } -predicate is_decorated(Class c) { - exists(c.getADecorator()) -} +predicate is_decorated(Class c) { exists(c.getADecorator()) } predicate is_stateful(Class c) { - exists(Function method, ExprContext ctx | - method.getScope() = c and (ctx instanceof Store or ctx instanceof AugStore) | + exists(Function method, ExprContext ctx | + method.getScope() = c and + (ctx instanceof Store or ctx instanceof AugStore) + | exists(Subscript s | s.getScope() = method and s.getCtx() = ctx) or exists(Attribute a | a.getScope() = method and a.getCtx() = ctx) ) or - exists(Function method, Call call, Attribute a, string name | - method.getScope() = c and call.getScope() = method and - call.getFunc() = a and a.getName() = name | - name = "pop" or name = "remove" or name = "discard" or - name = "extend" or name = "append" + exists(Function method, Call call, Attribute a, string name | + method.getScope() = c and + call.getScope() = method and + call.getFunc() = a and + a.getName() = name + | + name = "pop" or + name = "remove" or + name = "discard" or + name = "extend" or + name = "append" ) - } predicate useless_class(Class c, int methods) { - c.isTopLevel() - and - c.isPublic() - and - no_inheritance(c) - and - fewer_than_two_public_methods(c, methods) - and - does_not_define_special_method(c) - and - not c.isProbableMixin() - and - not is_decorated(c) - and + c.isTopLevel() and + c.isPublic() and + no_inheritance(c) and + fewer_than_two_public_methods(c, methods) and + does_not_define_special_method(c) and + not c.isProbableMixin() and + not is_decorated(c) and not is_stateful(c) } from Class c, int methods, string msg -where useless_class(c, methods) and -(methods = 1 and msg = "Class " + c.getName() + " defines only one public method, which should be replaced by a function." - or - methods = 0 and msg = "Class " + c.getName() + " defines no public methods and could be replaced with a namedtuple or dictionary." -) +where + useless_class(c, methods) and + ( + methods = 1 and + msg = + "Class " + c.getName() + + " defines only one public method, which should be replaced by a function." + or + methods = 0 and + msg = + "Class " + c.getName() + + " defines no public methods and could be replaced with a namedtuple or dictionary." + ) select c, msg diff --git a/python/ql/src/Classes/WrongNameForArgumentInClassInstantiation.ql b/python/ql/src/Classes/WrongNameForArgumentInClassInstantiation.ql index 022d6a515e6..3ac4454a019 100644 --- a/python/ql/src/Classes/WrongNameForArgumentInClassInstantiation.ql +++ b/python/ql/src/Classes/WrongNameForArgumentInClassInstantiation.ql @@ -14,14 +14,11 @@ */ import python - import Expressions.CallArgs - from Call call, ClassObject cls, string name, FunctionObject init where - illegally_named_parameter_objectapi(call, cls, name) - and init = get_function_or_initializer_objectapi(cls) -select - call, "Keyword argument '" + name + "' is not a supported parameter name of $@.", init, init.getQualifiedName() - + illegally_named_parameter_objectapi(call, cls, name) and + init = get_function_or_initializer_objectapi(cls) +select call, "Keyword argument '" + name + "' is not a supported parameter name of $@.", init, + init.getQualifiedName() diff --git a/python/ql/src/Classes/WrongNumberArgumentsInClassInstantiation.ql b/python/ql/src/Classes/WrongNumberArgumentsInClassInstantiation.ql index f94b5ac5b3e..f04d2350855 100644 --- a/python/ql/src/Classes/WrongNumberArgumentsInClassInstantiation.ql +++ b/python/ql/src/Classes/WrongNumberArgumentsInClassInstantiation.ql @@ -17,9 +17,15 @@ import Expressions.CallArgs from Call call, ClassObject cls, string too, string should, int limit, FunctionObject init where -( - too_many_args_objectapi(call, cls, limit) and too = "too many arguments" and should = "no more than " - or - too_few_args_objectapi(call, cls, limit) and too = "too few arguments" and should = "no fewer than " -) and init = get_function_or_initializer_objectapi(cls) -select call, "Call to $@ with " + too + "; should be " + should + limit.toString() + ".", init, init.getQualifiedName() + ( + too_many_args_objectapi(call, cls, limit) and + too = "too many arguments" and + should = "no more than " + or + too_few_args_objectapi(call, cls, limit) and + too = "too few arguments" and + should = "no fewer than " + ) and + init = get_function_or_initializer_objectapi(cls) +select call, "Call to $@ with " + too + "; should be " + should + limit.toString() + ".", init, + init.getQualifiedName() diff --git a/python/ql/src/Exceptions/CatchingBaseException.ql b/python/ql/src/Exceptions/CatchingBaseException.ql index d175297f1c9..04a95a8e827 100644 --- a/python/ql/src/Exceptions/CatchingBaseException.ql +++ b/python/ql/src/Exceptions/CatchingBaseException.ql @@ -14,17 +14,16 @@ import python -predicate doesnt_reraise(ExceptStmt ex) { - ex.getAFlowNode().getBasicBlock().reachesExit() -} +predicate doesnt_reraise(ExceptStmt ex) { ex.getAFlowNode().getBasicBlock().reachesExit() } predicate catches_base_exception(ExceptStmt ex) { - ex.getType().pointsTo(ClassValue::baseException()) - or - not exists(ex.getType()) + ex.getType().pointsTo(ClassValue::baseException()) + or + not exists(ex.getType()) } from ExceptStmt ex -where catches_base_exception(ex) and -doesnt_reraise(ex) +where + catches_base_exception(ex) and + doesnt_reraise(ex) select ex, "Except block directly handles BaseException." diff --git a/python/ql/src/Exceptions/EmptyExcept.ql b/python/ql/src/Exceptions/EmptyExcept.ql index a753181af71..fd656755c1c 100755 --- a/python/ql/src/Exceptions/EmptyExcept.ql +++ b/python/ql/src/Exceptions/EmptyExcept.ql @@ -13,21 +13,18 @@ import python -predicate -empty_except(ExceptStmt ex) { +predicate empty_except(ExceptStmt ex) { not exists(Stmt s | s = ex.getAStmt() and not s instanceof Pass) } -predicate no_else(ExceptStmt ex) { - not exists(ex.getTry().getOrelse()) -} +predicate no_else(ExceptStmt ex) { not exists(ex.getTry().getOrelse()) } predicate no_comment(ExceptStmt ex) { - not exists(Comment c | - c.getLocation().getFile() = ex.getLocation().getFile() and - c.getLocation().getStartLine() >= ex.getLocation().getStartLine() and - c.getLocation().getEndLine() <= ex.getBody().getLastItem().getLocation().getEndLine() - ) + not exists(Comment c | + c.getLocation().getFile() = ex.getLocation().getFile() and + c.getLocation().getStartLine() >= ex.getLocation().getStartLine() and + c.getLocation().getEndLine() <= ex.getBody().getLastItem().getLocation().getEndLine() + ) } predicate non_local_control_flow(ExceptStmt ex) { @@ -38,7 +35,8 @@ predicate try_has_normal_exit(Try try) { exists(ControlFlowNode pred, ControlFlowNode succ | /* Exists a non-exception predecessor, successor pair */ pred.getASuccessor() = succ and - not pred.getAnExceptionalSuccessor() = succ | + not pred.getAnExceptionalSuccessor() = succ + | /* Successor is either a normal flow node or a fall-through exit */ not exists(Scope s | s.getReturnNode() = succ) and /* Predecessor is in try body and successor is not */ @@ -50,8 +48,7 @@ predicate try_has_normal_exit(Try try) { predicate attribute_access(Stmt s) { s.(ExprStmt).getValue() instanceof Attribute or - exists(string name | - s.(ExprStmt).getValue().(Call).getFunc().(Name).getId() = name | + exists(string name | s.(ExprStmt).getValue().(Call).getFunc().(Name).getId() = name | name = "getattr" or name = "setattr" or name = "delattr" ) or @@ -65,8 +62,7 @@ predicate subscript(Stmt s) { } predicate encode_decode(Call ex, ClassValue type) { - exists(string name | - ex.getFunc().(Attribute).getName() = name | + exists(string name | ex.getFunc().(Attribute).getName() = name | name = "encode" and type = ClassValue::unicodeEncodeError() or name = "decode" and type = ClassValue::unicodeDecodeError() @@ -80,8 +76,7 @@ predicate small_handler(ExceptStmt ex, Stmt s, ClassValue type) { } predicate focussed_handler(ExceptStmt ex) { - exists(Stmt s, ClassValue type | - small_handler(ex, s, type) | + exists(Stmt s, ClassValue type | small_handler(ex, s, type) | subscript(s) and type.getASuperType() = ClassValue::lookupError() or attribute_access(s) and type = ClassValue::attributeError() @@ -92,12 +87,15 @@ predicate focussed_handler(ExceptStmt ex) { ) } -Try try_return() { - not exists(result.getStmt(1)) and result.getStmt(0) instanceof Return -} +Try try_return() { not exists(result.getStmt(1)) and result.getStmt(0) instanceof Return } from ExceptStmt ex -where empty_except(ex) and no_else(ex) and no_comment(ex) and not non_local_control_flow(ex) - and not ex.getTry() = try_return() and try_has_normal_exit(ex.getTry()) and - not focussed_handler(ex) +where + empty_except(ex) and + no_else(ex) and + no_comment(ex) and + not non_local_control_flow(ex) and + not ex.getTry() = try_return() and + try_has_normal_exit(ex.getTry()) and + not focussed_handler(ex) select ex, "'except' clause does nothing but pass and there is no explanatory comment." diff --git a/python/ql/src/Exceptions/IllegalRaise.ql b/python/ql/src/Exceptions/IllegalRaise.ql index da1bc56ae33..f05f5437db2 100644 --- a/python/ql/src/Exceptions/IllegalRaise.ql +++ b/python/ql/src/Exceptions/IllegalRaise.ql @@ -16,6 +16,10 @@ import Raising import Exceptions.NotImplemented from Raise r, ClassValue t -where type_or_typeof(r, t, _) and not t.isLegalExceptionType() and not t.failedInference(_) and not use_of_not_implemented_in_raise(r, _) -select r, "Illegal class '" + t.getName() + "' raised; will result in a TypeError being raised instead." - +where + type_or_typeof(r, t, _) and + not t.isLegalExceptionType() and + not t.failedInference(_) and + not use_of_not_implemented_in_raise(r, _) +select r, + "Illegal class '" + t.getName() + "' raised; will result in a TypeError being raised instead." diff --git a/python/ql/src/Exceptions/NotImplementedIsNotAnException.ql b/python/ql/src/Exceptions/NotImplementedIsNotAnException.ql index 89f1bb04568..933d15ddf60 100644 --- a/python/ql/src/Exceptions/NotImplementedIsNotAnException.ql +++ b/python/ql/src/Exceptions/NotImplementedIsNotAnException.ql @@ -15,5 +15,4 @@ import Exceptions.NotImplemented from Expr notimpl where use_of_not_implemented_in_raise(_, notimpl) - select notimpl, "NotImplemented is not an Exception. Did you mean NotImplementedError?" diff --git a/python/ql/src/Exceptions/RaisingTuple.ql b/python/ql/src/Exceptions/RaisingTuple.ql index ab197fe1665..dc4b295a90d 100644 --- a/python/ql/src/Exceptions/RaisingTuple.ql +++ b/python/ql/src/Exceptions/RaisingTuple.ql @@ -12,8 +12,11 @@ import python from Raise r, Value v, AstNode origin -where r.getException().pointsTo(v, origin) and -v.getClass() = ClassValue::tuple() and -major_version() = 2 /* Raising a tuple is a type error in Python 3, so is handled by the IllegalRaise query. */ - -select r, "Raising $@ will result in the first element (recursively) being raised and all other elements being discarded.", origin, "a tuple" \ No newline at end of file +where + r.getException().pointsTo(v, origin) and + v.getClass() = ClassValue::tuple() and + major_version() = 2 +/* Raising a tuple is a type error in Python 3, so is handled by the IllegalRaise query. */ +select r, + "Raising $@ will result in the first element (recursively) being raised and all other elements being discarded.", + origin, "a tuple" diff --git a/python/ql/src/Exceptions/UnguardedNextInGenerator.ql b/python/ql/src/Exceptions/UnguardedNextInGenerator.ql index ff0f53dea4d..c2435d41b3e 100755 --- a/python/ql/src/Exceptions/UnguardedNextInGenerator.ql +++ b/python/ql/src/Exceptions/UnguardedNextInGenerator.ql @@ -12,13 +12,9 @@ import python -FunctionValue iter() { - result = Value::named("iter") -} +FunctionValue iter() { result = Value::named("iter") } -BuiltinFunctionValue next() { - result = Value::named("next") -} +BuiltinFunctionValue next() { result = Value::named("next") } predicate call_to_iter(CallNode call, EssaVariable sequence) { sequence.getAUse() = iter().getArgumentForCall(call, 0) @@ -52,14 +48,14 @@ predicate stop_iteration_handled(CallNode call) { } from CallNode call -where call_to_next(call, _) and -not call_to_next_has_default(call) and -not exists(EssaVariable iterator | - call_to_next(call, iterator.getAUse()) and - iter_not_exhausted(iterator) -) and -call.getNode().getScope().(Function).isGenerator() and -not exists(Comp comp | comp.contains(call.getNode())) and -not stop_iteration_handled(call) - +where + call_to_next(call, _) and + not call_to_next_has_default(call) and + not exists(EssaVariable iterator | + call_to_next(call, iterator.getAUse()) and + iter_not_exhausted(iterator) + ) and + call.getNode().getScope().(Function).isGenerator() and + not exists(Comp comp | comp.contains(call.getNode())) and + not stop_iteration_handled(call) select call, "Call to next() in a generator" diff --git a/python/ql/src/Expressions/CallToSuperWrongClass.ql b/python/ql/src/Expressions/CallToSuperWrongClass.ql index 57ae36fa30e..4f218ab5a2c 100644 --- a/python/ql/src/Expressions/CallToSuperWrongClass.ql +++ b/python/ql/src/Expressions/CallToSuperWrongClass.ql @@ -16,14 +16,14 @@ import python from CallNode call_to_super, string name where -exists(GlobalVariable gv, ControlFlowNode cn | - call_to_super = ClassValue::super_().getACall() and - gv.getId() = "super" and - cn = call_to_super.getArg(0) and - name = call_to_super.getScope().getScope().(Class).getName() and - exists(ClassValue other | - cn.pointsTo(other) and - not other.getScope().getName() = name + exists(GlobalVariable gv, ControlFlowNode cn | + call_to_super = ClassValue::super_().getACall() and + gv.getId() = "super" and + cn = call_to_super.getArg(0) and + name = call_to_super.getScope().getScope().(Class).getName() and + exists(ClassValue other | + cn.pointsTo(other) and + not other.getScope().getName() = name + ) ) -) select call_to_super.getNode(), "First argument to super() should be " + name + "." diff --git a/python/ql/src/Expressions/CompareConstants.ql b/python/ql/src/Expressions/CompareConstants.ql index 2a66a952c5e..5b04302db31 100644 --- a/python/ql/src/Expressions/CompareConstants.ql +++ b/python/ql/src/Expressions/CompareConstants.ql @@ -16,6 +16,8 @@ import python from Compare comparison, Expr left, Expr right where - comparison.compares(left, _, right) and left.isConstant() and right.isConstant() and + comparison.compares(left, _, right) and + left.isConstant() and + right.isConstant() and not exists(Assert a | a.getTest() = comparison) select comparison, "Comparison of constants; use 'True' or 'False' instead." diff --git a/python/ql/src/Expressions/CompareIdenticalValuesMissingSelf.ql b/python/ql/src/Expressions/CompareIdenticalValuesMissingSelf.ql index 9d618c2dbb1..554d7a087b6 100644 --- a/python/ql/src/Expressions/CompareIdenticalValuesMissingSelf.ql +++ b/python/ql/src/Expressions/CompareIdenticalValuesMissingSelf.ql @@ -16,6 +16,5 @@ import python import Expressions.RedundantComparison from RedundantComparison comparison -where - comparison.maybeMissingSelf() +where comparison.maybeMissingSelf() select comparison, "Comparison of identical values; may be missing 'self'." diff --git a/python/ql/src/Expressions/Comparisons/UselessComparisonTest.ql b/python/ql/src/Expressions/Comparisons/UselessComparisonTest.ql index 1a1083884ea..29f21e7beb2 100644 --- a/python/ql/src/Expressions/Comparisons/UselessComparisonTest.ql +++ b/python/ql/src/Expressions/Comparisons/UselessComparisonTest.ql @@ -15,16 +15,19 @@ import python import semmle.python.Comparisons -/* Holds if the comparison `comp` is of the complex form `a op b op c` and not of +/* + * Holds if the comparison `comp` is of the complex form `a op b op c` and not of * the simple form `a op b`. */ + private predicate is_complex(Expr comp) { exists(comp.(Compare).getOp(1)) or is_complex(comp.(UnaryExpr).getOperand()) } -/** A test is useless if for every block that it controls there is another test that is at least as +/** + * A test is useless if for every block that it controls there is another test that is at least as * strict and also controls that block. */ private predicate useless_test(Comparison comp, ComparisonControlBlock controls, boolean isTrue) { @@ -34,17 +37,15 @@ private predicate useless_test(Comparison comp, ComparisonControlBlock controls, } private predicate useless_test_ast(AstNode comp, AstNode previous, boolean isTrue) { - forex(Comparison compnode, ConditionBlock block| + forex(Comparison compnode, ConditionBlock block | compnode.getNode() = comp and block.getLastNode().getNode() = previous - | + | useless_test(compnode, block, isTrue) ) } from Expr test, Expr other, boolean isTrue -where -useless_test_ast(test, other, isTrue) and not useless_test_ast(test.getAChildNode+(), other, _) - - +where + useless_test_ast(test, other, isTrue) and not useless_test_ast(test.getAChildNode+(), other, _) select test, "Test is always " + isTrue + ", because of $@", other, "this condition" diff --git a/python/ql/src/Expressions/DuplicateKeyInDictionaryLiteral.ql b/python/ql/src/Expressions/DuplicateKeyInDictionaryLiteral.ql index 20678da8dc0..99a1a0e44e1 100644 --- a/python/ql/src/Expressions/DuplicateKeyInDictionaryLiteral.ql +++ b/python/ql/src/Expressions/DuplicateKeyInDictionaryLiteral.ql @@ -17,13 +17,12 @@ import semmle.python.strings predicate dict_key(Dict d, Expr k, string s) { k = d.getAKey() and ( - s = ((Num)k).getN() + s = k.(Num).getN() or // We use � to mark unrepresentable characters // so two instances of � may represent different strings in the source code not "�" = s.charAt(_) and - exists(StrConst c | - c = k | + exists(StrConst c | c = k | s = "u\"" + c.getText() + "\"" and c.isUnicode() or s = "b\"" + c.getText() + "\"" and not c.isUnicode() @@ -32,13 +31,15 @@ predicate dict_key(Dict d, Expr k, string s) { } from Dict d, Expr k1, Expr k2 -where exists(string s | dict_key(d, k1, s) and dict_key(d, k2, s) and k1 != k2) and -( - exists(BasicBlock b, int i1, int i2 | - k1.getAFlowNode() = b.getNode(i1) and - k2.getAFlowNode() = b.getNode(i2) and - i1 < i2 - ) or - k1.getAFlowNode().getBasicBlock().strictlyDominates(k2.getAFlowNode().getBasicBlock()) -) +where + exists(string s | dict_key(d, k1, s) and dict_key(d, k2, s) and k1 != k2) and + ( + exists(BasicBlock b, int i1, int i2 | + k1.getAFlowNode() = b.getNode(i1) and + k2.getAFlowNode() = b.getNode(i2) and + i1 < i2 + ) + or + k1.getAFlowNode().getBasicBlock().strictlyDominates(k2.getAFlowNode().getBasicBlock()) + ) select k1, "Dictionary key " + repr(k1) + " is subsequently $@.", k2, "overwritten" diff --git a/python/ql/src/Expressions/ExplicitCallToDel.ql b/python/ql/src/Expressions/ExplicitCallToDel.ql index 1cb2782c885..81e8fc97b43 100644 --- a/python/ql/src/Expressions/ExplicitCallToDel.ql +++ b/python/ql/src/Expressions/ExplicitCallToDel.ql @@ -13,23 +13,22 @@ import python class DelCall extends Call { - DelCall() { - ((Attribute)this.getFunc()).getName() = "__del__" - } - - predicate isSuperCall() { - exists(Function f | f = this.getScope() and f.getName() = "__del__" | - // We pass in `self` as the first argument... - f.getArg(0).asName().getVariable() = ((Name)this.getArg(0)).getVariable() or - // ... or the call is of the form `super(Type, self).__del__()`, or the equivalent - // Python 3: `super().__del__()`. - exists(Call superCall | superCall = ((Attribute)this.getFunc()).getObject() | - ((Name)superCall.getFunc()).getId() = "super" - ) - ) - } + DelCall() { this.getFunc().(Attribute).getName() = "__del__" } + + predicate isSuperCall() { + exists(Function f | f = this.getScope() and f.getName() = "__del__" | + // We pass in `self` as the first argument... + f.getArg(0).asName().getVariable() = this.getArg(0).(Name).getVariable() + or + // ... or the call is of the form `super(Type, self).__del__()`, or the equivalent + // Python 3: `super().__del__()`. + exists(Call superCall | superCall = this.getFunc().(Attribute).getObject() | + superCall.getFunc().(Name).getId() = "super" + ) + ) + } } from DelCall del where not del.isSuperCall() -select del, "The __del__ special method is called explicitly." \ No newline at end of file +select del, "The __del__ special method is called explicitly." diff --git a/python/ql/src/Expressions/Formatting/MixedExplicitImplicitIn3101Format.ql b/python/ql/src/Expressions/Formatting/MixedExplicitImplicitIn3101Format.ql index 3f488aa9507..a52fada69b0 100644 --- a/python/ql/src/Expressions/Formatting/MixedExplicitImplicitIn3101Format.ql +++ b/python/ql/src/Expressions/Formatting/MixedExplicitImplicitIn3101Format.ql @@ -15,4 +15,4 @@ import AdvancedFormatting from AdvancedFormattingCall call, AdvancedFormatString fmt where call.getAFormat() = fmt and fmt.isImplicitlyNumbered() and fmt.isExplicitlyNumbered() -select fmt, "Formatting string mixes implicitly and explicitly numbered fields." \ No newline at end of file +select fmt, "Formatting string mixes implicitly and explicitly numbered fields." diff --git a/python/ql/src/Expressions/Formatting/UnusedArgumentIn3101Format.ql b/python/ql/src/Expressions/Formatting/UnusedArgumentIn3101Format.ql index 67c95277375..89af180099d 100644 --- a/python/ql/src/Expressions/Formatting/UnusedArgumentIn3101Format.ql +++ b/python/ql/src/Expressions/Formatting/UnusedArgumentIn3101Format.ql @@ -11,16 +11,18 @@ */ import python - - import python import AdvancedFormatting int field_count(AdvancedFormatString fmt) { result = max(fmt.getFieldNumber(_, _)) + 1 } from AdvancedFormattingCall call, AdvancedFormatString fmt, int arg_count, int max_field -where arg_count = call.providedArgCount() and max_field = field_count(fmt) and -call.getAFormat() = fmt and not exists(call.getStarargs()) and -forall(AdvancedFormatString other | other = call.getAFormat() | field_count(other) < arg_count) -select call, "Too many arguments for string format. Format $@ requires only " + max_field + ", but " + -arg_count.toString() + " are provided.", fmt, "\"" + fmt.getText() + "\"" +where + arg_count = call.providedArgCount() and + max_field = field_count(fmt) and + call.getAFormat() = fmt and + not exists(call.getStarargs()) and + forall(AdvancedFormatString other | other = call.getAFormat() | field_count(other) < arg_count) +select call, + "Too many arguments for string format. Format $@ requires only " + max_field + ", but " + + arg_count.toString() + " are provided.", fmt, "\"" + fmt.getText() + "\"" diff --git a/python/ql/src/Expressions/Formatting/UnusedNamedArgumentIn3101Format.ql b/python/ql/src/Expressions/Formatting/UnusedNamedArgumentIn3101Format.ql index c902b992b1c..62c598a397e 100644 --- a/python/ql/src/Expressions/Formatting/UnusedNamedArgumentIn3101Format.ql +++ b/python/ql/src/Expressions/Formatting/UnusedNamedArgumentIn3101Format.ql @@ -14,14 +14,18 @@ import python import AdvancedFormatting from AdvancedFormattingCall call, AdvancedFormatString fmt, string name, string fmt_repr -where call.getAFormat() = fmt and -name = call.getAKeyword().getArg() and -forall(AdvancedFormatString format | format = call.getAFormat() | not format.getFieldName(_, _) = name) -and not exists(call.getKwargs()) and -(strictcount(call.getAFormat()) = 1 and fmt_repr = "format \"" + fmt.getText() + "\"" - or - strictcount(call.getAFormat()) != 1 and fmt_repr = "any format used." -) - -select call, "Surplus named argument for string format. An argument named '" + name + - "' is provided, but it is not required by $@.", fmt, fmt_repr +where + call.getAFormat() = fmt and + name = call.getAKeyword().getArg() and + forall(AdvancedFormatString format | format = call.getAFormat() | + not format.getFieldName(_, _) = name + ) and + not exists(call.getKwargs()) and + ( + strictcount(call.getAFormat()) = 1 and fmt_repr = "format \"" + fmt.getText() + "\"" + or + strictcount(call.getAFormat()) != 1 and fmt_repr = "any format used." + ) +select call, + "Surplus named argument for string format. An argument named '" + name + + "' is provided, but it is not required by $@.", fmt, fmt_repr diff --git a/python/ql/src/Expressions/Formatting/WrongNameInArgumentsFor3101Format.ql b/python/ql/src/Expressions/Formatting/WrongNameInArgumentsFor3101Format.ql index 412d8d55830..384d9b9d58e 100644 --- a/python/ql/src/Expressions/Formatting/WrongNameInArgumentsFor3101Format.ql +++ b/python/ql/src/Expressions/Formatting/WrongNameInArgumentsFor3101Format.ql @@ -15,9 +15,11 @@ import python import AdvancedFormatting from AdvancedFormattingCall call, AdvancedFormatString fmt, string name -where call.getAFormat() = fmt and -not name = call.getAKeyword().getArg() and -fmt.getFieldName(_, _) = name -and not exists(call.getKwargs()) -select call, "Missing named argument for string format. Format $@ requires '" + name + "', but it is omitted.", -fmt, "\"" + fmt.getText() + "\"" \ No newline at end of file +where + call.getAFormat() = fmt and + not name = call.getAKeyword().getArg() and + fmt.getFieldName(_, _) = name and + not exists(call.getKwargs()) +select call, + "Missing named argument for string format. Format $@ requires '" + name + "', but it is omitted.", + fmt, "\"" + fmt.getText() + "\"" diff --git a/python/ql/src/Expressions/Formatting/WrongNumberArgumentsFor3101Format.ql b/python/ql/src/Expressions/Formatting/WrongNumberArgumentsFor3101Format.ql index fe766ae2d8b..8f3479c5be5 100644 --- a/python/ql/src/Expressions/Formatting/WrongNumberArgumentsFor3101Format.ql +++ b/python/ql/src/Expressions/Formatting/WrongNumberArgumentsFor3101Format.ql @@ -14,10 +14,16 @@ import python import AdvancedFormatting -from AdvancedFormattingCall call, AdvancedFormatString fmt, -int arg_count, int max_field, string provided -where arg_count = call.providedArgCount() and max_field = max(fmt.getFieldNumber(_, _)) and -call.getAFormat() = fmt and not exists(call.getStarargs()) and arg_count <= max_field and -(if arg_count = 1 then provided = " is provided." else provided = " are provided.") -select call, "Too few arguments for string format. Format $@ requires at least " + (max_field+1) + ", but " + -arg_count.toString() + provided, fmt, "\"" + fmt.getText() + "\"" \ No newline at end of file +from + AdvancedFormattingCall call, AdvancedFormatString fmt, int arg_count, int max_field, + string provided +where + arg_count = call.providedArgCount() and + max_field = max(fmt.getFieldNumber(_, _)) and + call.getAFormat() = fmt and + not exists(call.getStarargs()) and + arg_count <= max_field and + (if arg_count = 1 then provided = " is provided." else provided = " are provided.") +select call, + "Too few arguments for string format. Format $@ requires at least " + (max_field + 1) + ", but " + + arg_count.toString() + provided, fmt, "\"" + fmt.getText() + "\"" diff --git a/python/ql/src/Expressions/HashedButNoHash.ql b/python/ql/src/Expressions/HashedButNoHash.ql index 37da9407b7f..7fbb723fc54 100644 --- a/python/ql/src/Expressions/HashedButNoHash.ql +++ b/python/ql/src/Expressions/HashedButNoHash.ql @@ -12,7 +12,8 @@ import python -/* This assumes that any indexing operation where the value is not a sequence or numpy array involves hashing. +/* + * This assumes that any indexing operation where the value is not a sequence or numpy array involves hashing. * For sequences, the index must be an int, which are hashable, so we don't need to treat them specially. * For numpy arrays, the index may be a list, which are not hashable and needs to be treated specially. */ @@ -30,7 +31,9 @@ predicate has_custom_getitem(Value v) { } predicate explicitly_hashed(ControlFlowNode f) { - exists(CallNode c, GlobalVariable hash | c.getArg(0) = f and c.getFunction().(NameNode).uses(hash) and hash.getId() = "hash") + exists(CallNode c, GlobalVariable hash | + c.getArg(0) = f and c.getFunction().(NameNode).uses(hash) and hash.getId() = "hash" + ) } predicate unhashable_subscript(ControlFlowNode f, ClassValue c, ControlFlowNode origin) { @@ -44,9 +47,7 @@ predicate unhashable_subscript(ControlFlowNode f, ClassValue c, ControlFlowNode } predicate is_unhashable(ControlFlowNode f, ClassValue cls, ControlFlowNode origin) { - exists(Value v | - f.pointsTo(v, origin) and v.getClass() = cls - | + exists(Value v | f.pointsTo(v, origin) and v.getClass() = cls | not cls.hasAttribute("__hash__") and not cls.failedInference(_) and cls.isNewStyle() or cls.lookup("__hash__") = Value::named("None") @@ -67,16 +68,18 @@ predicate is_unhashable(ControlFlowNode f, ClassValue cls, ControlFlowNode origi * it. */ predicate typeerror_is_caught(ControlFlowNode f) { - exists (Try try | + exists(Try try | try.getBody().contains(f.getNode()) and - try.getAHandler().getType().pointsTo(ClassValue::typeError())) + try.getAHandler().getType().pointsTo(ClassValue::typeError()) + ) } from ControlFlowNode f, ClassValue c, ControlFlowNode origin where -not typeerror_is_caught(f) -and -(explicitly_hashed(f) and is_unhashable(f, c, origin) - or - unhashable_subscript(f, c, origin)) + not typeerror_is_caught(f) and + ( + explicitly_hashed(f) and is_unhashable(f, c, origin) + or + unhashable_subscript(f, c, origin) + ) select f.getNode(), "This $@ of $@ is unhashable.", origin, "instance", c, c.getQualifiedName() diff --git a/python/ql/src/Expressions/IncorrectComparisonUsingIs.ql b/python/ql/src/Expressions/IncorrectComparisonUsingIs.ql index 2a2025ec51e..5dda5b857f9 100644 --- a/python/ql/src/Expressions/IncorrectComparisonUsingIs.ql +++ b/python/ql/src/Expressions/IncorrectComparisonUsingIs.ql @@ -14,7 +14,14 @@ import python import IsComparisons from Compare comp, Cmpop op, ClassValue c, string alt -where invalid_portable_is_comparison(comp, op, c) and -not cpython_interned_constant(comp.getASubExpression()) and -(op instanceof Is and alt = "==" or op instanceof IsNot and alt = "!=") -select comp, "Values compared using '" + op.getSymbol() + "' when equivalence is not the same as identity. Use '" + alt + "' instead." +where + invalid_portable_is_comparison(comp, op, c) and + not cpython_interned_constant(comp.getASubExpression()) and + ( + op instanceof Is and alt = "==" + or + op instanceof IsNot and alt = "!=" + ) +select comp, + "Values compared using '" + op.getSymbol() + + "' when equivalence is not the same as identity. Use '" + alt + "' instead." diff --git a/python/ql/src/Expressions/NonCallableCalled.ql b/python/ql/src/Expressions/NonCallableCalled.ql index 2f9a0f8f5cc..fdd0bbd13c3 100644 --- a/python/ql/src/Expressions/NonCallableCalled.ql +++ b/python/ql/src/Expressions/NonCallableCalled.ql @@ -15,10 +15,13 @@ import python import Exceptions.NotImplemented from Call c, Value v, ClassValue t, Expr f, AstNode origin -where f = c.getFunc() and f.pointsTo(v, origin) and t = v.getClass() and - not t.isCallable() and not t.failedInference(_) - and not t.hasAttribute("__get__") - and not v = Value::named("None") - and not use_of_not_implemented_in_raise(_, f) - +where + f = c.getFunc() and + f.pointsTo(v, origin) and + t = v.getClass() and + not t.isCallable() and + not t.failedInference(_) and + not t.hasAttribute("__get__") and + not v = Value::named("None") and + not use_of_not_implemented_in_raise(_, f) select c, "Call to a $@ of $@.", origin, "non-callable", t, t.toString() diff --git a/python/ql/src/Expressions/NonPortableComparisonUsingIs.ql b/python/ql/src/Expressions/NonPortableComparisonUsingIs.ql index d5aefebd3ce..3e01ccdacf7 100644 --- a/python/ql/src/Expressions/NonPortableComparisonUsingIs.ql +++ b/python/ql/src/Expressions/NonPortableComparisonUsingIs.ql @@ -14,10 +14,12 @@ import python import IsComparisons from Compare comp, Cmpop op, ClassValue c -where invalid_portable_is_comparison(comp, op, c) and -exists(Expr sub | - sub = comp.getASubExpression() | - cpython_interned_constant(sub) and - not universally_interned_constant(sub) -) -select comp, "The result of this comparison with '" + op.getSymbol() + "' may differ between implementations of Python." \ No newline at end of file +where + invalid_portable_is_comparison(comp, op, c) and + exists(Expr sub | sub = comp.getASubExpression() | + cpython_interned_constant(sub) and + not universally_interned_constant(sub) + ) +select comp, + "The result of this comparison with '" + op.getSymbol() + + "' may differ between implementations of Python." diff --git a/python/ql/src/Expressions/Regex/BackspaceEscape.ql b/python/ql/src/Expressions/Regex/BackspaceEscape.ql index b80893b04f0..b18d581257a 100644 --- a/python/ql/src/Expressions/Regex/BackspaceEscape.ql +++ b/python/ql/src/Expressions/Regex/BackspaceEscape.ql @@ -14,9 +14,8 @@ import python import semmle.python.regex from Regex r, int offset -where r.escapingChar(offset) and r.getChar(offset+1) = "b" and -exists(int start, int end | - start < offset and end > offset | - r.charSet(start, end) -) -select r, "Backspace escape in regular expression at offset " + offset + "." \ No newline at end of file +where + r.escapingChar(offset) and + r.getChar(offset + 1) = "b" and + exists(int start, int end | start < offset and end > offset | r.charSet(start, end)) +select r, "Backspace escape in regular expression at offset " + offset + "." diff --git a/python/ql/src/Expressions/Regex/DuplicateCharacterInSet.ql b/python/ql/src/Expressions/Regex/DuplicateCharacterInSet.ql index 88c265fb370..42a745affb8 100644 --- a/python/ql/src/Expressions/Regex/DuplicateCharacterInSet.ql +++ b/python/ql/src/Expressions/Regex/DuplicateCharacterInSet.ql @@ -15,20 +15,28 @@ import semmle.python.regex predicate duplicate_char_in_class(Regex r, string char) { exists(int i, int j, int x, int y, int start, int end | - i != x and j != y and - start < i and j < end and - start < x and y < end and - r.character(i, j) and char = r.getText().substring(i, j) and - r.character(x, y) and char = r.getText().substring(x, y) and + i != x and + j != y and + start < i and + j < end and + start < x and + y < end and + r.character(i, j) and + char = r.getText().substring(i, j) and + r.character(x, y) and + char = r.getText().substring(x, y) and r.charSet(start, end) ) and /* Exclude � as we use it for any unencodable character */ char != "�" and //Ignore whitespace in verbose mode - not (r.getAMode() = "VERBOSE" and (char = " " or char = "\t" or char = "\r" or char = "\n")) + not ( + r.getAMode() = "VERBOSE" and + (char = " " or char = "\t" or char = "\r" or char = "\n") + ) } from Regex r, string char where duplicate_char_in_class(r, char) -select r, "This regular expression includes duplicate character '" + char + "' in a set of characters." - +select r, + "This regular expression includes duplicate character '" + char + "' in a set of characters." diff --git a/python/ql/src/Expressions/Regex/MissingPartSpecialGroup.ql b/python/ql/src/Expressions/Regex/MissingPartSpecialGroup.ql index 7a1974fc514..ea5deffa7de 100644 --- a/python/ql/src/Expressions/Regex/MissingPartSpecialGroup.ql +++ b/python/ql/src/Expressions/Regex/MissingPartSpecialGroup.ql @@ -16,5 +16,3 @@ import semmle.python.regex from Regex r, string missing, string part where r.getText().regexpMatch(".*\\(P<\\w+>.*") and missing = "?" and part = "named group" select r, "Regular expression is missing '" + missing + "' in " + part + "." - - diff --git a/python/ql/src/Expressions/Regex/UnmatchableCaret.ql b/python/ql/src/Expressions/Regex/UnmatchableCaret.ql index 7fc0c6f219e..7a5c087ec02 100644 --- a/python/ql/src/Expressions/Regex/UnmatchableCaret.ql +++ b/python/ql/src/Expressions/Regex/UnmatchableCaret.ql @@ -16,10 +16,11 @@ import semmle.python.regex predicate unmatchable_caret(Regex r, int start) { not r.getAMode() = "MULTILINE" and not r.getAMode() = "VERBOSE" and - r.specialCharacter(start, start+1, "^") and - not r.firstItem(start, start+1) + r.specialCharacter(start, start + 1, "^") and + not r.firstItem(start, start + 1) } from Regex r, int offset where unmatchable_caret(r, offset) -select r, "This regular expression includes an unmatchable caret at offset " + offset.toString() + "." +select r, + "This regular expression includes an unmatchable caret at offset " + offset.toString() + "." diff --git a/python/ql/src/Expressions/Regex/UnmatchableDollar.ql b/python/ql/src/Expressions/Regex/UnmatchableDollar.ql index 49cef2bded1..dfd2bfcf893 100644 --- a/python/ql/src/Expressions/Regex/UnmatchableDollar.ql +++ b/python/ql/src/Expressions/Regex/UnmatchableDollar.ql @@ -16,11 +16,11 @@ import semmle.python.regex predicate unmatchable_dollar(Regex r, int start) { not r.getAMode() = "MULTILINE" and not r.getAMode() = "VERBOSE" and - r.specialCharacter(start, start+1, "$") - and - not r.lastItem(start, start+1) + r.specialCharacter(start, start + 1, "$") and + not r.lastItem(start, start + 1) } from Regex r, int offset where unmatchable_dollar(r, offset) -select r, "This regular expression includes an unmatchable dollar at offset " + offset.toString() + "." +select r, + "This regular expression includes an unmatchable dollar at offset " + offset.toString() + "." diff --git a/python/ql/src/Expressions/TruncatedDivision.ql b/python/ql/src/Expressions/TruncatedDivision.ql index 471b5244de0..399435dbabf 100644 --- a/python/ql/src/Expressions/TruncatedDivision.ql +++ b/python/ql/src/Expressions/TruncatedDivision.ql @@ -1,38 +1,37 @@ - /** - * @name Result of integer division may be truncated - * @description The arguments to a division statement may be integers, which - * may cause the result to be truncated in Python 2. - * @kind problem - * @tags maintainability - * correctness - * @problem.severity warning - * @sub-severity high - * @precision very-high - * @id py/truncated-division - */ +/** + * @name Result of integer division may be truncated + * @description The arguments to a division statement may be integers, which + * may cause the result to be truncated in Python 2. + * @kind problem + * @tags maintainability + * correctness + * @problem.severity warning + * @sub-severity high + * @precision very-high + * @id py/truncated-division + */ import python from BinaryExpr div, ControlFlowNode left, ControlFlowNode right where // Only relevant for Python 2, as all later versions implement true division - major_version() = 2 - and + major_version() = 2 and exists(BinaryExprNode bin, Value lval, Value rval | - bin = div.getAFlowNode() - and bin.getNode().getOp() instanceof Div - and bin.getLeft().pointsTo(lval, left) - and lval.getClass() = ClassValue::int_() - and bin.getRight().pointsTo(rval, right) - and rval.getClass() = ClassValue::int_() + bin = div.getAFlowNode() and + bin.getNode().getOp() instanceof Div and + bin.getLeft().pointsTo(lval, left) and + lval.getClass() = ClassValue::int_() and + bin.getRight().pointsTo(rval, right) and + rval.getClass() = ClassValue::int_() and // Ignore instances where integer division leaves no remainder - and not lval.(NumericValue).getIntValue() % rval.(NumericValue).getIntValue() = 0 - and not bin.getNode().getEnclosingModule().hasFromFuture("division") + not lval.(NumericValue).getIntValue() % rval.(NumericValue).getIntValue() = 0 and + not bin.getNode().getEnclosingModule().hasFromFuture("division") and // Filter out results wrapped in `int(...)` - and not exists(CallNode c | - c = ClassValue::int_().getACall() - and c.getAnArg() = bin + not exists(CallNode c | + c = ClassValue::int_().getACall() and + c.getAnArg() = bin ) ) select div, "Result of division may be truncated as its $@ and $@ arguments may both be integers.", - left.getLocation(), "left", right.getLocation(), "right" + left.getLocation(), "left", right.getLocation(), "right" diff --git a/python/ql/src/Expressions/UnintentionalImplicitStringConcatenation.ql b/python/ql/src/Expressions/UnintentionalImplicitStringConcatenation.ql index 70128406915..8199be8a051 100644 --- a/python/ql/src/Expressions/UnintentionalImplicitStringConcatenation.ql +++ b/python/ql/src/Expressions/UnintentionalImplicitStringConcatenation.ql @@ -22,14 +22,13 @@ predicate string_const(Expr s) { from StrConst s where -// Implicitly concatenated string is in a list and that list contains at least one other string. -exists(List l, Expr other | - not s = other and - l.getAnElt() = s and - l.getAnElt() = other and - string_const(other) -) and -exists(s.getAnImplicitlyConcatenatedPart()) and -not s.isParenthesized() - + // Implicitly concatenated string is in a list and that list contains at least one other string. + exists(List l, Expr other | + not s = other and + l.getAnElt() = s and + l.getAnElt() = other and + string_const(other) + ) and + exists(s.getAnImplicitlyConcatenatedPart()) and + not s.isParenthesized() select s, "Implicit string concatenation. Maybe missing a comma?" diff --git a/python/ql/src/Expressions/UnnecessaryLambda.ql b/python/ql/src/Expressions/UnnecessaryLambda.ql index 2d7bbf72682..2b927973015 100644 --- a/python/ql/src/Expressions/UnnecessaryLambda.ql +++ b/python/ql/src/Expressions/UnnecessaryLambda.ql @@ -15,43 +15,47 @@ import python /* f consists of a single return statement, whose value is a call. The arguments of the call are exactly the parameters of f */ predicate simple_wrapper(Lambda l, Expr wrapped) { exists(Function f, Call c | f = l.getInnerScope() and c = l.getExpression() | - wrapped = c.getFunc() and - count(f.getAnArg()) = count(c.getAnArg()) and - forall(int arg | exists(f.getArg(arg)) | - f.getArgName(arg) = ((Name)c.getArg(arg)).getId()) and - /* Either no **kwargs or they must match */ - (not exists(f.getKwarg()) and not exists(c.getKwargs()) or - ((Name)f.getKwarg()).getId() = ((Name)c.getKwargs()).getId()) and - /* Either no *args or they must match */ - (not exists(f.getVararg()) and not exists(c.getStarargs()) or - ((Name)f.getVararg()).getId() = ((Name)c.getStarargs()).getId()) and - /* No named parameters in call */ - not exists(c.getAKeyword()) - ) - and + wrapped = c.getFunc() and + count(f.getAnArg()) = count(c.getAnArg()) and + forall(int arg | exists(f.getArg(arg)) | f.getArgName(arg) = c.getArg(arg).(Name).getId()) and + /* Either no **kwargs or they must match */ + ( + not exists(f.getKwarg()) and not exists(c.getKwargs()) + or + f.getKwarg().(Name).getId() = c.getKwargs().(Name).getId() + ) and + /* Either no *args or they must match */ + ( + not exists(f.getVararg()) and not exists(c.getStarargs()) + or + f.getVararg().(Name).getId() = c.getStarargs().(Name).getId() + ) and + /* No named parameters in call */ + not exists(c.getAKeyword()) + ) and // f is not necessarily a drop-in replacement for the lambda if there are default argument values not exists(l.getArgs().getADefault()) } /* The expression called will refer to the same object if evaluated when the lambda is created or when the lambda is executed. */ predicate unnecessary_lambda(Lambda l, Expr e) { - simple_wrapper(l, e) and + simple_wrapper(l, e) and ( - /* plain class */ - exists(ClassValue c | e.pointsTo(c)) - or - /* plain function */ - exists(FunctionValue f | e.pointsTo(f)) - or - /* bound-method of enclosing instance */ - exists(ClassValue cls, Attribute a | - cls.getScope() = l.getScope().getScope() and a = e | - ((Name)a.getObject()).getId() = "self" and - cls.hasAttribute(a.getName()) - ) + /* plain class */ + exists(ClassValue c | e.pointsTo(c)) + or + /* plain function */ + exists(FunctionValue f | e.pointsTo(f)) + or + /* bound-method of enclosing instance */ + exists(ClassValue cls, Attribute a | cls.getScope() = l.getScope().getScope() and a = e | + a.getObject().(Name).getId() = "self" and + cls.hasAttribute(a.getName()) + ) ) } from Lambda l, Expr e where unnecessary_lambda(l, e) -select l, "This 'lambda' is just a simple wrapper around a callable object. Use that object directly." \ No newline at end of file +select l, + "This 'lambda' is just a simple wrapper around a callable object. Use that object directly." diff --git a/python/ql/src/Expressions/WrongNameForArgumentInCall.ql b/python/ql/src/Expressions/WrongNameForArgumentInCall.ql index 6abab859f5f..4800f898c54 100644 --- a/python/ql/src/Expressions/WrongNameForArgumentInCall.ql +++ b/python/ql/src/Expressions/WrongNameForArgumentInCall.ql @@ -16,11 +16,12 @@ import python import Expressions.CallArgs - from Call call, FunctionObject func, string name where -illegally_named_parameter_objectapi(call, func, name) and -not func.isAbstract() and -not exists(FunctionObject overridden | func.overrides(overridden) and overridden.getFunction().getAnArg().(Name).getId() = name) -select -call, "Keyword argument '" + name + "' is not a supported parameter name of $@.", func, func.descriptiveString() + illegally_named_parameter_objectapi(call, func, name) and + not func.isAbstract() and + not exists(FunctionObject overridden | + func.overrides(overridden) and overridden.getFunction().getAnArg().(Name).getId() = name + ) +select call, "Keyword argument '" + name + "' is not a supported parameter name of $@.", func, + func.descriptiveString() diff --git a/python/ql/src/Expressions/WrongNumberArgumentsForFormat.ql b/python/ql/src/Expressions/WrongNumberArgumentsForFormat.ql index 71d5bec2fca..39d265fe290 100644 --- a/python/ql/src/Expressions/WrongNumberArgumentsForFormat.ql +++ b/python/ql/src/Expressions/WrongNumberArgumentsForFormat.ql @@ -18,29 +18,30 @@ import semmle.python.strings predicate string_format(BinaryExpr operation, StrConst str, Value args, AstNode origin) { operation.getOp() instanceof Mod and exists(Value fmt, Context ctx | - operation.getLeft().pointsTo(ctx, fmt, str) and - operation.getRight().pointsTo(ctx, args, origin) + operation.getLeft().pointsTo(ctx, fmt, str) and + operation.getRight().pointsTo(ctx, args, origin) ) } int sequence_length(Value args) { /* Guess length of sequence */ - exists(Tuple seq, AstNode origin | - seq.pointsTo(args,origin) | + exists(Tuple seq, AstNode origin | seq.pointsTo(args, origin) | result = strictcount(seq.getAnElt()) and not seq.getAnElt() instanceof Starred ) or - exists(ImmutableLiteral i | - i.getLiteralValue() = args | - result = 1 - ) + exists(ImmutableLiteral i | i.getLiteralValue() = args | result = 1) } - -from BinaryExpr operation, StrConst fmt, Value args, int slen, int alen, AstNode origin, string provided -where string_format(operation, fmt, args, origin) and slen = sequence_length(args) and alen = format_items(fmt) and slen != alen and -(if slen = 1 then provided = " is provided." else provided = " are provided.") -select operation, "Wrong number of $@ for string format. Format $@ takes " + alen.toString() + ", but " + slen.toString() + provided, - origin, "arguments", - fmt, fmt.getText() +from + BinaryExpr operation, StrConst fmt, Value args, int slen, int alen, AstNode origin, + string provided +where + string_format(operation, fmt, args, origin) and + slen = sequence_length(args) and + alen = format_items(fmt) and + slen != alen and + (if slen = 1 then provided = " is provided." else provided = " are provided.") +select operation, + "Wrong number of $@ for string format. Format $@ takes " + alen.toString() + ", but " + + slen.toString() + provided, origin, "arguments", fmt, fmt.getText() diff --git a/python/ql/src/Expressions/WrongNumberArgumentsInCall.ql b/python/ql/src/Expressions/WrongNumberArgumentsInCall.ql index 9f636213a34..732cb7a8b7e 100644 --- a/python/ql/src/Expressions/WrongNumberArgumentsInCall.ql +++ b/python/ql/src/Expressions/WrongNumberArgumentsInCall.ql @@ -16,15 +16,20 @@ import CallArgs from Call call, FunctionObject func, string too, string should, int limit where -( - too_many_args_objectapi(call, func, limit) and too = "too many arguments" and should = "no more than " - or - too_few_args_objectapi(call, func, limit) and too = "too few arguments" and should = "no fewer than " -) and -not func.isAbstract() and -not exists(FunctionObject overridden | func.overrides(overridden) and correct_args_if_called_as_method_objectapi(call, overridden)) -/* The semantics of `__new__` can be a bit subtle, so we simply exclude `__new__` methods */ -and not func.getName() = "__new__" - -select call, "Call to $@ with " + too + "; should be " + should + limit.toString() + ".", func, func.descriptiveString() - + ( + too_many_args_objectapi(call, func, limit) and + too = "too many arguments" and + should = "no more than " + or + too_few_args_objectapi(call, func, limit) and + too = "too few arguments" and + should = "no fewer than " + ) and + not func.isAbstract() and + not exists(FunctionObject overridden | + func.overrides(overridden) and correct_args_if_called_as_method_objectapi(call, overridden) + ) and + /* The semantics of `__new__` can be a bit subtle, so we simply exclude `__new__` methods */ + not func.getName() = "__new__" +select call, "Call to $@ with " + too + "; should be " + should + limit.toString() + ".", func, + func.descriptiveString() diff --git a/python/ql/src/Filters/ClassifyFiles.ql b/python/ql/src/Filters/ClassifyFiles.ql index 4448d993903..20062f0451f 100644 --- a/python/ql/src/Filters/ClassifyFiles.ql +++ b/python/ql/src/Filters/ClassifyFiles.ql @@ -11,8 +11,9 @@ import semmle.python.filters.GeneratedCode import semmle.python.filters.Tests predicate classify(File f, string tag) { - f instanceof GeneratedFile and tag = "generated" or - exists (TestScope t | t.getLocation().getFile() = f) and tag = "test" + f instanceof GeneratedFile and tag = "generated" + or + exists(TestScope t | t.getLocation().getFile() = f) and tag = "test" } from File f, string tag diff --git a/python/ql/src/Filters/NotGenerated.ql b/python/ql/src/Filters/NotGenerated.ql index c59368eb9d8..e1efbfd42e3 100644 --- a/python/ql/src/Filters/NotGenerated.ql +++ b/python/ql/src/Filters/NotGenerated.ql @@ -4,6 +4,7 @@ * @kind problem * @id py/not-generated-file-filter */ + import python import external.DefectFilter import semmle.python.filters.GeneratedCode diff --git a/python/ql/src/Filters/NotTest.ql b/python/ql/src/Filters/NotTest.ql index ddea7fd212b..56650e4ff15 100644 --- a/python/ql/src/Filters/NotTest.ql +++ b/python/ql/src/Filters/NotTest.ql @@ -4,6 +4,7 @@ * @kind problem * @id py/not-test-file-filter */ + import python import external.DefectFilter import semmle.python.filters.Tests diff --git a/python/ql/src/Functions/ConsistentReturns.ql b/python/ql/src/Functions/ConsistentReturns.ql index f3344bd8f74..9e28dee36a3 100644 --- a/python/ql/src/Functions/ConsistentReturns.ql +++ b/python/ql/src/Functions/ConsistentReturns.ql @@ -13,20 +13,21 @@ import python predicate explicitly_returns_non_none(Function func) { - exists(Return return | return.getScope() = func and - exists(Expr val | - val= return.getValue() | - not val instanceof None - ) + exists(Return return | + return.getScope() = func and + exists(Expr val | val = return.getValue() | not val instanceof None) ) } predicate has_implicit_return(Function func) { - exists(ControlFlowNode fallthru | fallthru = func.getFallthroughNode() and not fallthru.unlikelyReachable()) or + exists(ControlFlowNode fallthru | + fallthru = func.getFallthroughNode() and not fallthru.unlikelyReachable() + ) + or exists(Return return | return.getScope() = func and not exists(return.getValue())) } - from Function func where explicitly_returns_non_none(func) and has_implicit_return(func) -select func, "Mixing implicit and explicit returns may indicate an error as implicit returns always return None." +select func, + "Mixing implicit and explicit returns may indicate an error as implicit returns always return None." diff --git a/python/ql/src/Functions/DeprecatedSliceMethod.ql b/python/ql/src/Functions/DeprecatedSliceMethod.ql index ff2df9919a6..c37f2195b54 100644 --- a/python/ql/src/Functions/DeprecatedSliceMethod.ql +++ b/python/ql/src/Functions/DeprecatedSliceMethod.ql @@ -12,13 +12,13 @@ import python predicate slice_method_name(string name) { - name = "__getslice__" or name = "__setslice__" or name = "__delslice__" + name = "__getslice__" or name = "__setslice__" or name = "__delslice__" } from PythonFunctionValue f, string meth - -where f.getScope().isMethod() and not f.isOverridingMethod() and - slice_method_name(meth) and f.getName() = meth - - -select f, meth + " method has been deprecated since Python 2.0" \ No newline at end of file +where + f.getScope().isMethod() and + not f.isOverridingMethod() and + slice_method_name(meth) and + f.getName() = meth +select f, meth + " method has been deprecated since Python 2.0" diff --git a/python/ql/src/Functions/IncorrectRaiseInSpecialMethod.ql b/python/ql/src/Functions/IncorrectRaiseInSpecialMethod.ql index c1e497ac470..c9368173a76 100644 --- a/python/ql/src/Functions/IncorrectRaiseInSpecialMethod.ql +++ b/python/ql/src/Functions/IncorrectRaiseInSpecialMethod.ql @@ -22,44 +22,87 @@ private predicate indexing_method(string name) { } private predicate arithmetic_method(string name) { - name = "__add__" or name = "__sub__" or name = "__div__" or - name = "__pos__" or name = "__abs__" or name = "__floordiv__" or - name = "__div__" or name = "__divmod__" or name = "__lshift__" or - name = "__and__" or name = "__or__"or name = "__xor__" or name = "__rshift__" or - name = "__pow__" or name = "__mul__" or name = "__neg__" or - name = "__radd__" or name = "__rsub__" or name = "__rdiv__" or - name = "__rfloordiv__" or name = "__rdiv__" or name = "__rlshift__" or - name = "__rand__" or name = "__ror__"or name = "__rxor__" or name = "__rrshift__" or - name = "__rpow__" or name = "__rmul__" or name = "__truediv__" or name = "__rtruediv__" or - name = "__iadd__" or name = "__isub__" or name = "__idiv__" or - name = "__ifloordiv__" or name = "__idiv__" or name = "__ilshift__" or - name = "__iand__" or name = "__ior__"or name = "__ixor__" or name = "__irshift__" or - name = "__ipow__" or name = "__imul__" or name = "__itruediv__" + name = "__add__" or + name = "__sub__" or + name = "__div__" or + name = "__pos__" or + name = "__abs__" or + name = "__floordiv__" or + name = "__div__" or + name = "__divmod__" or + name = "__lshift__" or + name = "__and__" or + name = "__or__" or + name = "__xor__" or + name = "__rshift__" or + name = "__pow__" or + name = "__mul__" or + name = "__neg__" or + name = "__radd__" or + name = "__rsub__" or + name = "__rdiv__" or + name = "__rfloordiv__" or + name = "__rdiv__" or + name = "__rlshift__" or + name = "__rand__" or + name = "__ror__" or + name = "__rxor__" or + name = "__rrshift__" or + name = "__rpow__" or + name = "__rmul__" or + name = "__truediv__" or + name = "__rtruediv__" or + name = "__iadd__" or + name = "__isub__" or + name = "__idiv__" or + name = "__ifloordiv__" or + name = "__idiv__" or + name = "__ilshift__" or + name = "__iand__" or + name = "__ior__" or + name = "__ixor__" or + name = "__irshift__" or + name = "__ipow__" or + name = "__imul__" or + name = "__itruediv__" } private predicate ordering_method(string name) { - name = "__lt__" or name = "__le__" or name = "__gt__" or name = "__ge__" or + name = "__lt__" + or + name = "__le__" + or + name = "__gt__" + or + name = "__ge__" + or name = "__cmp__" and major_version() = 2 } private predicate cast_method(string name) { - name = "__nonzero__" and major_version() = 2 or - name = "__bool__" or - name = "__int__" or name = "__float__" or - name = "__long__" or - name = "__trunc__" or + name = "__nonzero__" and major_version() = 2 + or + name = "__bool__" + or + name = "__int__" + or + name = "__float__" + or + name = "__long__" + or + name = "__trunc__" + or name = "__complex__" } predicate correct_raise(string name, ClassObject ex) { - ex.getAnImproperSuperType() = theTypeErrorType() - and + ex.getAnImproperSuperType() = theTypeErrorType() and ( - name = "__copy__" or - name = "__deepcopy__" or - name = "__call__" or - indexing_method(name) or - attribute_method(name) + name = "__copy__" or + name = "__deepcopy__" or + name = "__call__" or + indexing_method(name) or + attribute_method(name) ) or preferred_raise(name, ex) @@ -84,11 +127,11 @@ predicate no_need_to_raise(string name, string message) { } predicate is_abstract(FunctionObject func) { - ((Name)func.getFunction().getADecorator()).getId().matches("%abstract%") + func.getFunction().getADecorator().(Name).getId().matches("%abstract%") } predicate always_raises(FunctionObject f, ClassObject ex) { - ex = f.getARaisedType() and + ex = f.getARaisedType() and strictcount(f.getARaisedType()) = 1 and not exists(f.getFunction().getANormalExit()) and /* raising StopIteration is equivalent to a return in a generator */ @@ -96,17 +139,17 @@ predicate always_raises(FunctionObject f, ClassObject ex) { } from FunctionObject f, ClassObject cls, string message -where f.getFunction().isSpecialMethod() and -not is_abstract(f) and -always_raises(f, cls) and -( - no_need_to_raise(f.getName(), message) and not cls.getName() = "NotImplementedError" - or - not correct_raise(f.getName(), cls) and not cls.getName() = "NotImplementedError" - and - exists(ClassObject preferred | - preferred_raise(f.getName(), preferred) | - message = "raise " + preferred.getName() + " instead" +where + f.getFunction().isSpecialMethod() and + not is_abstract(f) and + always_raises(f, cls) and + ( + no_need_to_raise(f.getName(), message) and not cls.getName() = "NotImplementedError" + or + not correct_raise(f.getName(), cls) and + not cls.getName() = "NotImplementedError" and + exists(ClassObject preferred | preferred_raise(f.getName(), preferred) | + message = "raise " + preferred.getName() + " instead" + ) ) -) select f, "Function always raises $@; " + message, cls, cls.toString() diff --git a/python/ql/src/Functions/IncorrectlyOverriddenMethod.ql b/python/ql/src/Functions/IncorrectlyOverriddenMethod.ql index a425079cce0..53d70815ddd 100644 --- a/python/ql/src/Functions/IncorrectlyOverriddenMethod.ql +++ b/python/ql/src/Functions/IncorrectlyOverriddenMethod.ql @@ -14,14 +14,18 @@ import Expressions.CallArgs from Call call, FunctionObject func, FunctionObject overridden, string problem where -func.overrides(overridden) and ( - wrong_args_objectapi(call, func, _, problem) and correct_args_if_called_as_method_objectapi(call, overridden) - or - exists(string name | - illegally_named_parameter_objectapi(call, func, name) and problem = "an argument named '" + name + "'" and - overridden.getFunction().getAnArg().(Name).getId() = name + func.overrides(overridden) and + ( + wrong_args_objectapi(call, func, _, problem) and + correct_args_if_called_as_method_objectapi(call, overridden) + or + exists(string name | + illegally_named_parameter_objectapi(call, func, name) and + problem = "an argument named '" + name + "'" and + overridden.getFunction().getAnArg().(Name).getId() = name + ) ) -) - -select func, "Overriding method signature does not match $@, where it is passed " + problem + ". Overridden method $@ is correctly specified.", -call, "here", overridden, overridden.descriptiveString() +select func, + "Overriding method signature does not match $@, where it is passed " + problem + + ". Overridden method $@ is correctly specified.", call, "here", overridden, + overridden.descriptiveString() diff --git a/python/ql/src/Functions/IncorrectlySpecifiedOverriddenMethod.ql b/python/ql/src/Functions/IncorrectlySpecifiedOverriddenMethod.ql index 9636c7c22db..0dd0fd5856b 100644 --- a/python/ql/src/Functions/IncorrectlySpecifiedOverriddenMethod.ql +++ b/python/ql/src/Functions/IncorrectlySpecifiedOverriddenMethod.ql @@ -15,21 +15,23 @@ import Expressions.CallArgs from Call call, FunctionObject func, FunctionObject overriding, string problem where -not func.getName() = "__init__" and -overriding.overrides(func) and -call = overriding.getAMethodCall().getNode() and -correct_args_if_called_as_method_objectapi(call, overriding) and -( - arg_count_objectapi(call)+1 < func.minParameters() and problem = "too few arguments" - or - arg_count_objectapi(call) >= func.maxParameters() and problem = "too many arguments" - or - exists(string name | call.getAKeyword().getArg() = name and - overriding.getFunction().getAnArg().(Name).getId() = name and - not func.getFunction().getAnArg().(Name).getId() = name and - problem = "an argument named '" + name + "'" + not func.getName() = "__init__" and + overriding.overrides(func) and + call = overriding.getAMethodCall().getNode() and + correct_args_if_called_as_method_objectapi(call, overriding) and + ( + arg_count_objectapi(call) + 1 < func.minParameters() and problem = "too few arguments" + or + arg_count_objectapi(call) >= func.maxParameters() and problem = "too many arguments" + or + exists(string name | + call.getAKeyword().getArg() = name and + overriding.getFunction().getAnArg().(Name).getId() = name and + not func.getFunction().getAnArg().(Name).getId() = name and + problem = "an argument named '" + name + "'" + ) ) -) - -select func, "Overridden method signature does not match $@, where it is passed " + problem + ". Overriding method $@ matches the call.", -call, "call", overriding, overriding.descriptiveString() +select func, + "Overridden method signature does not match $@, where it is passed " + problem + + ". Overriding method $@ matches the call.", call, "call", overriding, + overriding.descriptiveString() diff --git a/python/ql/src/Functions/InitIsGenerator.ql b/python/ql/src/Functions/InitIsGenerator.ql index 5ad61ae8255..bb02f103ea3 100644 --- a/python/ql/src/Functions/InitIsGenerator.ql +++ b/python/ql/src/Functions/InitIsGenerator.ql @@ -13,6 +13,7 @@ import python from Function f -where f.isInitMethod() and -(exists(Yield y | y.getScope() = f) or exists(YieldFrom y| y.getScope() = f)) +where + f.isInitMethod() and + (exists(Yield y | y.getScope() = f) or exists(YieldFrom y | y.getScope() = f)) select f, "__init__ method is a generator." diff --git a/python/ql/src/Functions/IterReturnsNonSelf.ql b/python/ql/src/Functions/IterReturnsNonSelf.ql index 0899cf798a1..7ca63493015 100644 --- a/python/ql/src/Functions/IterReturnsNonSelf.ql +++ b/python/ql/src/Functions/IterReturnsNonSelf.ql @@ -13,21 +13,20 @@ import python Function iter_method(ClassObject t) { - result = ((FunctionObject)t.lookupAttribute("__iter__")).getFunction() + result = t.lookupAttribute("__iter__").(FunctionObject).getFunction() } -predicate is_self(Name value, Function f) { - value.getVariable() = ((Name)f.getArg(0)).getVariable() -} +predicate is_self(Name value, Function f) { value.getVariable() = f.getArg(0).(Name).getVariable() } predicate returns_non_self(Function f) { - exists(f.getFallthroughNode()) - or - exists(Return r | r.getScope() = f and not is_self(r.getValue(), f)) - or - exists(Return r | r.getScope() = f and not exists(r.getValue())) + exists(f.getFallthroughNode()) + or + exists(Return r | r.getScope() = f and not is_self(r.getValue(), f)) + or + exists(Return r | r.getScope() = f and not exists(r.getValue())) } from ClassObject t, Function iter where t.isIterator() and iter = iter_method(t) and returns_non_self(iter) -select t, "Class " + t.getName() + " is an iterator but its $@ method does not return 'self'.", iter, iter.getName() \ No newline at end of file +select t, "Class " + t.getName() + " is an iterator but its $@ method does not return 'self'.", + iter, iter.getName() diff --git a/python/ql/src/Functions/NonCls.ql b/python/ql/src/Functions/NonCls.ql index 983a5c75b30..10ca06af12c 100644 --- a/python/ql/src/Functions/NonCls.ql +++ b/python/ql/src/Functions/NonCls.ql @@ -40,9 +40,11 @@ where ( if exists(f.getArgName(0)) then - message = "Class methods or methods of a type deriving from type should have 'cls', rather than '" - + f.getArgName(0) + "', as their first parameter." + message = + "Class methods or methods of a type deriving from type should have 'cls', rather than '" + + f.getArgName(0) + "', as their first parameter." else - message = "Class methods or methods of a type deriving from type should have 'cls' as their first parameter." + message = + "Class methods or methods of a type deriving from type should have 'cls' as their first parameter." ) select f, message diff --git a/python/ql/src/Functions/NonSelf.ql b/python/ql/src/Functions/NonSelf.ql index 2f0cf44ca2a..a3102eee2aa 100644 --- a/python/ql/src/Functions/NonSelf.ql +++ b/python/ql/src/Functions/NonSelf.ql @@ -45,10 +45,12 @@ where ( if exists(f.getArgName(0)) then - message = "Normal methods should have 'self', rather than '" + f.getArgName(0) + + message = + "Normal methods should have 'self', rather than '" + f.getArgName(0) + "', as their first parameter." else - message = "Normal methods should have at least one parameter (the first of which should be 'self')." + message = + "Normal methods should have at least one parameter (the first of which should be 'self')." ) and not f.hasVarArg() ) and diff --git a/python/ql/src/Functions/OverlyComplexDelMethod.ql b/python/ql/src/Functions/OverlyComplexDelMethod.ql index fff4b3fad0b..2503f7ac6a7 100644 --- a/python/ql/src/Functions/OverlyComplexDelMethod.ql +++ b/python/ql/src/Functions/OverlyComplexDelMethod.ql @@ -16,6 +16,9 @@ import python from FunctionObject method -where exists(ClassObject c | c.declaredAttribute("__del__") = method and -method.getFunction().getMetrics().getCyclomaticComplexity() > 3) +where + exists(ClassObject c | + c.declaredAttribute("__del__") = method and + method.getFunction().getMetrics().getCyclomaticComplexity() > 3 + ) select method, "Overly complex '__del__' method." diff --git a/python/ql/src/Functions/ReturnConsistentTupleSizes.ql b/python/ql/src/Functions/ReturnConsistentTupleSizes.ql index 9a39e363872..02965c2a3a5 100644 --- a/python/ql/src/Functions/ReturnConsistentTupleSizes.ql +++ b/python/ql/src/Functions/ReturnConsistentTupleSizes.ql @@ -15,15 +15,16 @@ import python predicate returns_tuple_of_size(Function func, int size, AstNode origin) { exists(Return return, TupleValue val | return.getScope() = func and - return.getValue().pointsTo(val, origin) | + return.getValue().pointsTo(val, origin) + | size = val.length() ) } - from Function func, int s1, int s2, AstNode t1, AstNode t2 where returns_tuple_of_size(func, s1, t1) and returns_tuple_of_size(func, s2, t2) and s1 < s2 -select func, func.getQualifiedName() + " returns $@ and $@.", t1, "tuple of size " + s1, t2, "tuple of size " + s2 +select func, func.getQualifiedName() + " returns $@ and $@.", t1, "tuple of size " + s1, t2, + "tuple of size " + s2 diff --git a/python/ql/src/Functions/ReturnValueIgnored.ql b/python/ql/src/Functions/ReturnValueIgnored.ql index 19896533a7c..4235ef9a5d0 100644 --- a/python/ql/src/Functions/ReturnValueIgnored.ql +++ b/python/ql/src/Functions/ReturnValueIgnored.ql @@ -21,28 +21,34 @@ predicate meaningful_return_value(Expr val) { or val instanceof BooleanLiteral or - exists(FunctionObject callee | val = callee.getACall().getNode() and returns_meaningful_value(callee)) + exists(FunctionObject callee | + val = callee.getACall().getNode() and returns_meaningful_value(callee) + ) or not exists(FunctionObject callee | val = callee.getACall().getNode()) and not val instanceof Name } /* Value is used before returning, and thus its value is not lost if ignored */ predicate used_value(Expr val) { - exists(LocalVariable var, Expr other | var.getAnAccess() = val and other = var.getAnAccess() and not other = val) + exists(LocalVariable var, Expr other | + var.getAnAccess() = val and other = var.getAnAccess() and not other = val + ) } -predicate returns_meaningful_value(FunctionObject f) { - not exists(f.getFunction().getFallthroughNode()) - and +predicate returns_meaningful_value(FunctionObject f) { + not exists(f.getFunction().getFallthroughNode()) and ( - exists(Return ret, Expr val | ret.getScope() = f.getFunction() and val = ret.getValue() | - meaningful_return_value(val) and - not used_value(val) - ) - or - /* Is f a builtin function that returns something other than None? - * Ignore __import__ as it is often called purely for side effects */ - f.isC() and f.getAnInferredReturnType() != theNoneType() and not f.getName() = "__import__" + exists(Return ret, Expr val | ret.getScope() = f.getFunction() and val = ret.getValue() | + meaningful_return_value(val) and + not used_value(val) + ) + or + /* + * Is f a builtin function that returns something other than None? + * Ignore __import__ as it is often called purely for side effects + */ + + f.isC() and f.getAnInferredReturnType() != theNoneType() and not f.getName() = "__import__" ) } @@ -56,17 +62,19 @@ predicate wrapped_in_try_except(ExprStmt call) { } from ExprStmt call, FunctionObject callee, float percentage_used, int total -where call.getValue() = callee.getACall().getNode() and returns_meaningful_value(callee) and -not wrapped_in_try_except(call) and -exists(int unused | - unused = count(ExprStmt e | e.getValue().getAFlowNode() = callee.getACall()) and - total = count(callee.getACall()) | - percentage_used = (100.0*(total-unused)/total).floor() -) and -/* Report an alert if we see at least 5 calls and the return value is used in at least 3/4 of those calls. */ -percentage_used >= 75 and -total >= 5 - -select call, "Call discards return value of function $@. The result is used in " + percentage_used.toString() + "% of calls.", -callee, callee.getName() - +where + call.getValue() = callee.getACall().getNode() and + returns_meaningful_value(callee) and + not wrapped_in_try_except(call) and + exists(int unused | + unused = count(ExprStmt e | e.getValue().getAFlowNode() = callee.getACall()) and + total = count(callee.getACall()) + | + percentage_used = (100.0 * (total - unused) / total).floor() + ) and + /* Report an alert if we see at least 5 calls and the return value is used in at least 3/4 of those calls. */ + percentage_used >= 75 and + total >= 5 +select call, + "Call discards return value of function $@. The result is used in " + percentage_used.toString() + + "% of calls.", callee, callee.getName() diff --git a/python/ql/src/Functions/SignatureOverriddenMethod.ql b/python/ql/src/Functions/SignatureOverriddenMethod.ql index 47182d8d87d..f79b4e9722c 100644 --- a/python/ql/src/Functions/SignatureOverriddenMethod.ql +++ b/python/ql/src/Functions/SignatureOverriddenMethod.ql @@ -6,7 +6,6 @@ * @problem.severity warning * @tags reliability * correctness - * @problem.severity warning * @sub-severity high * @precision very-high * @id py/inheritance/signature-mismatch @@ -17,19 +16,20 @@ import Expressions.CallArgs from FunctionObject base, PyFunctionObject derived where - not exists(base.getACall()) and - not exists(FunctionObject a_derived | - a_derived.overrides(base) and - exists(a_derived.getACall()) - ) and - not derived.getFunction().isSpecialMethod() and - derived.getName() != "__init__" and - derived.isNormalMethod() and - not derived.getFunction().isSpecialMethod() and - // call to overrides distributed for efficiency - ( - (derived.overrides(base) and derived.minParameters() > base.maxParameters()) - or - (derived.overrides(base) and derived.maxParameters() < base.minParameters()) - ) -select derived, "Overriding method '" + derived.getName() + "' has signature mismatch with $@.", base, "overridden method" + not exists(base.getACall()) and + not exists(FunctionObject a_derived | + a_derived.overrides(base) and + exists(a_derived.getACall()) + ) and + not derived.getFunction().isSpecialMethod() and + derived.getName() != "__init__" and + derived.isNormalMethod() and + not derived.getFunction().isSpecialMethod() and + // call to overrides distributed for efficiency + ( + derived.overrides(base) and derived.minParameters() > base.maxParameters() + or + derived.overrides(base) and derived.maxParameters() < base.minParameters() + ) +select derived, "Overriding method '" + derived.getName() + "' has signature mismatch with $@.", + base, "overridden method" diff --git a/python/ql/src/Functions/SignatureSpecialMethods.ql b/python/ql/src/Functions/SignatureSpecialMethods.ql index 3e718ce2a3b..bd5587ec903 100644 --- a/python/ql/src/Functions/SignatureSpecialMethods.ql +++ b/python/ql/src/Functions/SignatureSpecialMethods.ql @@ -12,105 +12,102 @@ import python - predicate is_unary_op(string name) { - name = "__del__" or - name = "__repr__" or - name = "__str__" or - name = "__hash__" or - name = "__bool__" or - name = "__nonzero__" or - name = "__unicode__" or - name = "__len__" or - name = "__iter__" or - name = "__reversed__" or - name = "__neg__" or - name = "__pos__" or - name = "__abs__" or - name = "__invert__" or - name = "__complex__" or - name = "__int__" or - name = "__float__" or - name = "__long__" or - name = "__oct__" or - name = "__hex__" or - name = "__index__" or - name = "__enter__" + name = "__del__" or + name = "__repr__" or + name = "__str__" or + name = "__hash__" or + name = "__bool__" or + name = "__nonzero__" or + name = "__unicode__" or + name = "__len__" or + name = "__iter__" or + name = "__reversed__" or + name = "__neg__" or + name = "__pos__" or + name = "__abs__" or + name = "__invert__" or + name = "__complex__" or + name = "__int__" or + name = "__float__" or + name = "__long__" or + name = "__oct__" or + name = "__hex__" or + name = "__index__" or + name = "__enter__" } predicate is_binary_op(string name) { - name = "__lt__" or - name = "__le__" or - name = "__eq__" or - name = "__ne__" or - name = "__gt__" or - name = "__ge__" or - name = "__cmp__" or - name = "__rcmp__" or - name = "__getattr___" or - name = "__getattribute___" or - name = "__delattr__" or - name = "__delete__" or - name = "__instancecheck__" or - name = "__subclasscheck__" or - name = "__getitem__" or - name = "__delitem__" or - name = "__contains__" or - name = "__add__" or - name = "__sub__" or - name = "__mul__" or - name = "__floordiv__" or - name = "__div__" or - name = "__truediv__" or - name = "__mod__" or - name = "__divmod__" or - name = "__lshift__" or - name = "__rshift__" or - name = "__and__" or - name = "__xor__" or - name = "__or__" or - name = "__radd__" or - name = "__rsub__" or - name = "__rmul__" or - name = "__rfloordiv__" or - name = "__rdiv__" or - name = "__rtruediv__" or - name = "__rmod__" or - name = "__rdivmod__" or - name = "__rpow__" or - name = "__rlshift__" or - name = "__rrshift__" or - name = "__rand__" or - name = "__rxor__" or - name = "__ror__" or - name = "__iadd__" or - name = "__isub__" or - name = "__imul__" or - name = "__ifloordiv__" or - name = "__idiv__" or - name = "__itruediv__" or - name = "__imod__" or - name = "__idivmod__" or - name = "__ipow__" or - name = "__ilshift__" or - name = "__irshift__" or - name = "__iand__" or - name = "__ixor__" or - name = "__ior__" or - name = "__coerce__" + name = "__lt__" or + name = "__le__" or + name = "__eq__" or + name = "__ne__" or + name = "__gt__" or + name = "__ge__" or + name = "__cmp__" or + name = "__rcmp__" or + name = "__getattr___" or + name = "__getattribute___" or + name = "__delattr__" or + name = "__delete__" or + name = "__instancecheck__" or + name = "__subclasscheck__" or + name = "__getitem__" or + name = "__delitem__" or + name = "__contains__" or + name = "__add__" or + name = "__sub__" or + name = "__mul__" or + name = "__floordiv__" or + name = "__div__" or + name = "__truediv__" or + name = "__mod__" or + name = "__divmod__" or + name = "__lshift__" or + name = "__rshift__" or + name = "__and__" or + name = "__xor__" or + name = "__or__" or + name = "__radd__" or + name = "__rsub__" or + name = "__rmul__" or + name = "__rfloordiv__" or + name = "__rdiv__" or + name = "__rtruediv__" or + name = "__rmod__" or + name = "__rdivmod__" or + name = "__rpow__" or + name = "__rlshift__" or + name = "__rrshift__" or + name = "__rand__" or + name = "__rxor__" or + name = "__ror__" or + name = "__iadd__" or + name = "__isub__" or + name = "__imul__" or + name = "__ifloordiv__" or + name = "__idiv__" or + name = "__itruediv__" or + name = "__imod__" or + name = "__idivmod__" or + name = "__ipow__" or + name = "__ilshift__" or + name = "__irshift__" or + name = "__iand__" or + name = "__ixor__" or + name = "__ior__" or + name = "__coerce__" } predicate is_ternary_op(string name) { - name = "__setattr__" or - name = "__set__" or - name = "__setitem__" or - name = "__getslice__" or - name = "__delslice__" + name = "__setattr__" or + name = "__set__" or + name = "__setitem__" or + name = "__getslice__" or + name = "__delslice__" } -predicate is_quad_op(string name) { - name = "__setslice__" or name = "__exit__" -} +predicate is_quad_op(string name) { name = "__setslice__" or name = "__exit__" } int argument_count(PythonFunctionValue f, string name, ClassValue cls) { cls.declaredAttribute(name) = f and @@ -125,52 +122,62 @@ int argument_count(PythonFunctionValue f, string name, ClassValue cls) { ) } -predicate incorrect_special_method_defn(PythonFunctionValue func, string message, boolean show_counts, string name, ClassValue owner) { - exists(int required | - required = argument_count(func, name, owner) | - /* actual_non_default <= actual */ - if required > func.maxParameters() then - (message = "Too few parameters" and show_counts = true) - else if required < func.minParameters() then - (message = "Too many parameters" and show_counts = true) - else if (func.minParameters() < required and not func.getScope().hasVarArg()) then - (message = (required -func.minParameters()) + " default values(s) will never be used" and show_counts = false) - else - none() - ) +predicate incorrect_special_method_defn( + PythonFunctionValue func, string message, boolean show_counts, string name, ClassValue owner +) { + exists(int required | required = argument_count(func, name, owner) | + /* actual_non_default <= actual */ + if required > func.maxParameters() + then message = "Too few parameters" and show_counts = true + else + if required < func.minParameters() + then message = "Too many parameters" and show_counts = true + else + if func.minParameters() < required and not func.getScope().hasVarArg() + then + message = (required - func.minParameters()) + " default values(s) will never be used" and + show_counts = false + else none() + ) } predicate incorrect_pow(FunctionValue func, string message, boolean show_counts, ClassValue owner) { owner.declaredAttribute("__pow__") = func and ( - func.maxParameters() < 2 and message = "Too few parameters" and show_counts = true - or - func.minParameters() > 3 and message = "Too many parameters" and show_counts = true - or - func.minParameters() < 2 and message = (2 - func.minParameters()) + " default value(s) will never be used" and show_counts = false - or - func.minParameters() = 3 and message = "Third parameter to __pow__ should have a default value" and show_counts = false - ) + func.maxParameters() < 2 and message = "Too few parameters" and show_counts = true + or + func.minParameters() > 3 and message = "Too many parameters" and show_counts = true + or + func.minParameters() < 2 and + message = (2 - func.minParameters()) + " default value(s) will never be used" and + show_counts = false + or + func.minParameters() = 3 and + message = "Third parameter to __pow__ should have a default value" and + show_counts = false + ) } predicate incorrect_get(FunctionValue func, string message, boolean show_counts, ClassValue owner) { owner.declaredAttribute("__get__") = func and ( - func.maxParameters() < 3 and message = "Too few parameters" and show_counts = true - or - func.minParameters() > 3 and message = "Too many parameters" and show_counts = true - or - func.minParameters() < 2 and not func.getScope().hasVarArg() and - message = (2 - func.minParameters()) + " default value(s) will never be used" and show_counts = false - ) + func.maxParameters() < 3 and message = "Too few parameters" and show_counts = true + or + func.minParameters() > 3 and message = "Too many parameters" and show_counts = true + or + func.minParameters() < 2 and + not func.getScope().hasVarArg() and + message = (2 - func.minParameters()) + " default value(s) will never be used" and + show_counts = false + ) } string should_have_parameters(PythonFunctionValue f, string name, ClassValue owner) { - exists(int i | i = argument_count(f, name, owner) | - result = i.toString() - ) - or - owner.declaredAttribute(name) = f and (name = "__get__" or name = "__pow__") and result = "2 or 3" + exists(int i | i = argument_count(f, name, owner) | result = i.toString()) + or + owner.declaredAttribute(name) = f and + (name = "__get__" or name = "__pow__") and + result = "2 or 3" } string has_parameters(PythonFunctionValue f) { @@ -183,18 +190,23 @@ string has_parameters(PythonFunctionValue f) { ) } -from PythonFunctionValue f, string message, string sizes, boolean show_counts, string name, ClassValue owner -where - ( - incorrect_special_method_defn(f, message, show_counts, name, owner) - or - incorrect_pow(f, message, show_counts, owner) and name = "__pow__" - or - incorrect_get(f, message, show_counts, owner) and name = "__get__" - ) - and - ( - show_counts = false and sizes = "" or - show_counts = true and sizes = ", which has " + has_parameters(f) + ", but should have " + should_have_parameters(f, name, owner) - ) +from + PythonFunctionValue f, string message, string sizes, boolean show_counts, string name, + ClassValue owner +where + ( + incorrect_special_method_defn(f, message, show_counts, name, owner) + or + incorrect_pow(f, message, show_counts, owner) and name = "__pow__" + or + incorrect_get(f, message, show_counts, owner) and name = "__get__" + ) and + ( + show_counts = false and sizes = "" + or + show_counts = true and + sizes = + ", which has " + has_parameters(f) + ", but should have " + + should_have_parameters(f, name, owner) + ) select f, message + " for special method " + name + sizes + ", in class $@.", owner, owner.getName() diff --git a/python/ql/src/Functions/UseImplicitNoneReturnValue.ql b/python/ql/src/Functions/UseImplicitNoneReturnValue.ql index ab797844533..38632358c08 100644 --- a/python/ql/src/Functions/UseImplicitNoneReturnValue.ql +++ b/python/ql/src/Functions/UseImplicitNoneReturnValue.ql @@ -13,9 +13,11 @@ import python import Testing.Mox predicate is_used(Call c) { - exists(Expr outer | outer != c and outer.containsInScope(c) | outer instanceof Call or outer instanceof Attribute or outer instanceof Subscript) + exists(Expr outer | outer != c and outer.containsInScope(c) | + outer instanceof Call or outer instanceof Attribute or outer instanceof Subscript + ) or - exists(Stmt s | + exists(Stmt s | c = s.getASubExpression() and not s instanceof ExprStmt and /* Ignore if a single return, as def f(): return g() is quite common. Covers implicit return in a lambda. */ @@ -24,11 +26,13 @@ predicate is_used(Call c) { } from Call c, FunctionValue func -where -/* Call result is used, but callee is a procedure */ -is_used(c) and c.getFunc().pointsTo(func) and func.getScope().isProcedure() and -/* All callees are procedures */ -forall(FunctionValue callee | c.getFunc().pointsTo(callee) | callee.getScope().isProcedure()) and -/* Mox return objects have an `AndReturn` method */ -not useOfMoxInModule(c.getEnclosingModule()) +where + /* Call result is used, but callee is a procedure */ + is_used(c) and + c.getFunc().pointsTo(func) and + func.getScope().isProcedure() and + /* All callees are procedures */ + forall(FunctionValue callee | c.getFunc().pointsTo(callee) | callee.getScope().isProcedure()) and + /* Mox return objects have an `AndReturn` method */ + not useOfMoxInModule(c.getEnclosingModule()) select c, "The result of '$@' is used even though it is always None.", func, func.getQualifiedName() diff --git a/python/ql/src/Imports/DeprecatedModule.ql b/python/ql/src/Imports/DeprecatedModule.ql index 5ecd7f45cfe..359f3dad10d 100644 --- a/python/ql/src/Imports/DeprecatedModule.ql +++ b/python/ql/src/Imports/DeprecatedModule.ql @@ -60,7 +60,8 @@ predicate deprecated_module(string name, string instead, int major, int minor) { string deprecation_message(string mod) { exists(int major, int minor | deprecated_module(mod, _, major, minor) | - result = "The " + mod + " module was deprecated in version " + major.toString() + "." + + result = + "The " + mod + " module was deprecated in version " + major.toString() + "." + minor.toString() + "." ) } @@ -77,8 +78,7 @@ from ImportExpr imp, string name, string instead where name = imp.getName() and deprecated_module(name, instead, _, _) and - not exists(Try try, ExceptStmt except | except = try.getAHandler() - | + not exists(Try try, ExceptStmt except | except = try.getAHandler() | except.getType().pointsTo(ClassValue::importError()) and except.containsInScope(imp) ) diff --git a/python/ql/src/Imports/EncodingError.ql b/python/ql/src/Imports/EncodingError.ql index f26bf8dad33..962ae4426df 100644 --- a/python/ql/src/Imports/EncodingError.ql +++ b/python/ql/src/Imports/EncodingError.ql @@ -13,4 +13,4 @@ import python from EncodingError error -select error, error.getMessage() \ No newline at end of file +select error, error.getMessage() diff --git a/python/ql/src/Imports/ImportShadowedByLoopVar.ql b/python/ql/src/Imports/ImportShadowedByLoopVar.ql index 29f6536cce7..f3817a1bcde 100644 --- a/python/ql/src/Imports/ImportShadowedByLoopVar.ql +++ b/python/ql/src/Imports/ImportShadowedByLoopVar.ql @@ -13,10 +13,13 @@ import python predicate shadowsImport(Variable l) { - exists(Import i, Name shadow | shadow = i.getAName().getAsname() and shadow.getId() = l.getId() and i.getScope() = l.getScope().getScope*()) + exists(Import i, Name shadow | + shadow = i.getAName().getAsname() and + shadow.getId() = l.getId() and + i.getScope() = l.getScope().getScope*() + ) } - from Variable l, Name defn where shadowsImport(l) and defn.defines(l) and exists(For for | defn = for.getTarget()) select defn, "Loop variable '" + l.getId() + "' shadows an import" diff --git a/python/ql/src/Imports/ImportStarUsed.ql b/python/ql/src/Imports/ImportStarUsed.ql index bc125c05a3b..ad25748e771 100644 --- a/python/ql/src/Imports/ImportStarUsed.ql +++ b/python/ql/src/Imports/ImportStarUsed.ql @@ -14,4 +14,3 @@ import python from ImportStar i select i, "Using 'from ... import *' pollutes the namespace" - diff --git a/python/ql/src/Imports/ImportandImportFrom.ql b/python/ql/src/Imports/ImportandImportFrom.ql index 6a12e6b938d..f04e6d896ba 100644 --- a/python/ql/src/Imports/ImportandImportFrom.ql +++ b/python/ql/src/Imports/ImportandImportFrom.ql @@ -12,9 +12,10 @@ import python predicate import_and_import_from(Import i1, Import i2, Module m) { - i1.getEnclosingModule() = i2.getEnclosingModule() and - exists (ImportExpr e1, ImportExpr e2, ImportMember im | - e1 = i1.getAName().getValue() and im = i2.getAName().getValue() and e2 = im.getModule() | + i1.getEnclosingModule() = i2.getEnclosingModule() and + exists(ImportExpr e1, ImportExpr e2, ImportMember im | + e1 = i1.getAName().getValue() and im = i2.getAName().getValue() and e2 = im.getModule() + | e1.getName() = m.getName() and e2.getName() = m.getName() ) } diff --git a/python/ql/src/Imports/Imports.ql b/python/ql/src/Imports/Imports.ql index 7adba83cfe4..233aa7b68be 100644 --- a/python/ql/src/Imports/Imports.ql +++ b/python/ql/src/Imports/Imports.ql @@ -11,16 +11,15 @@ * @id py/multiple-imports-on-line */ -/* Look for imports of the form: -import modA, modB -(Imports should be one per line according PEP 8) -*/ +/* + * Look for imports of the form: + * import modA, modB + * (Imports should be one per line according PEP 8) + */ import python -predicate multiple_import(Import imp) { - count(imp.getAName()) > 1 and not imp.isFromImport() -} +predicate multiple_import(Import imp) { count(imp.getAName()) > 1 and not imp.isFromImport() } from Import i where multiple_import(i) diff --git a/python/ql/src/Imports/ModuleImportsItself.ql b/python/ql/src/Imports/ModuleImportsItself.ql index 1000842550a..3a4ad487687 100644 --- a/python/ql/src/Imports/ModuleImportsItself.ql +++ b/python/ql/src/Imports/ModuleImportsItself.ql @@ -14,7 +14,8 @@ import python predicate modules_imports_itself(ImportingStmt i, ModuleValue m) { i.getEnclosingModule() = m.getScope() and - m = max(string s, ModuleValue m_ | + m = + max(string s, ModuleValue m_ | s = i.getAnImportedModuleName() and m_.importedAs(s) | diff --git a/python/ql/src/Imports/MultipleImports.ql b/python/ql/src/Imports/MultipleImports.ql index 4e5f16779c0..09638457423 100644 --- a/python/ql/src/Imports/MultipleImports.ql +++ b/python/ql/src/Imports/MultipleImports.ql @@ -12,33 +12,35 @@ import python -predicate is_simple_import(Import imp) { - not exists(Attribute a | imp.contains(a)) -} +predicate is_simple_import(Import imp) { not exists(Attribute a | imp.contains(a)) } predicate double_import(Import original, Import duplicate, Module m) { original != duplicate and - is_simple_import(original) and is_simple_import(duplicate) and + is_simple_import(original) and + is_simple_import(duplicate) and /* Imports import the same thing */ - exists (ImportExpr e1, ImportExpr e2 | e1.getName() = m.getName() and e2.getName() = m.getName() and - e1 = original.getAName().getValue() and e2 = duplicate.getAName().getValue() + exists(ImportExpr e1, ImportExpr e2 | + e1.getName() = m.getName() and + e2.getName() = m.getName() and + e1 = original.getAName().getValue() and + e2 = duplicate.getAName().getValue() ) and - original.getAName().getAsname().(Name).getId() = duplicate.getAName().getAsname().(Name).getId() - and + original.getAName().getAsname().(Name).getId() = duplicate.getAName().getAsname().(Name).getId() and exists(Module enclosing | original.getScope() = enclosing and duplicate.getEnclosingModule() = enclosing and ( - /* Duplicate is not at top level scope */ - duplicate.getScope() != enclosing - or - /* Original dominates duplicate */ - original.getAnEntryNode().dominates(duplicate.getAnEntryNode()) + /* Duplicate is not at top level scope */ + duplicate.getScope() != enclosing + or + /* Original dominates duplicate */ + original.getAnEntryNode().dominates(duplicate.getAnEntryNode()) ) - ) + ) } from Import original, Import duplicate, Module m where double_import(original, duplicate, m) -select duplicate, "This import of module " + m.getName() + " is redundant, as it was previously imported $@.", - original, "on line " + original.getLocation().getStartLine().toString() +select duplicate, + "This import of module " + m.getName() + " is redundant, as it was previously imported $@.", + original, "on line " + original.getLocation().getStartLine().toString() diff --git a/python/ql/src/Imports/SyntaxError.ql b/python/ql/src/Imports/SyntaxError.ql index 8a2e0567a04..fd92211d241 100644 --- a/python/ql/src/Imports/SyntaxError.ql +++ b/python/ql/src/Imports/SyntaxError.ql @@ -14,4 +14,4 @@ import python from SyntaxError error where not error instanceof EncodingError -select error, error.getMessage() + " (in Python " + major_version() + ")." \ No newline at end of file +select error, error.getMessage() + " (in Python " + major_version() + ")." diff --git a/python/ql/src/Imports/UnintentionalImport.ql b/python/ql/src/Imports/UnintentionalImport.ql index 8e396896e95..47ae2c999a5 100644 --- a/python/ql/src/Imports/UnintentionalImport.ql +++ b/python/ql/src/Imports/UnintentionalImport.ql @@ -25,8 +25,8 @@ predicate all_defined(ModuleValue exporter) { exporter.getScope().getInitModule().(ImportTimeScope).definesName("__all__") } - from ImportStar imp, ModuleValue exporter where import_star(imp, exporter) and not all_defined(exporter) -select imp, "Import pollutes the enclosing namespace, as the imported module $@ does not define '__all__'.", - exporter, exporter.getName() +select imp, + "Import pollutes the enclosing namespace, as the imported module $@ does not define '__all__'.", + exporter, exporter.getName() diff --git a/python/ql/src/Lexical/CommentedOutCode.ql b/python/ql/src/Lexical/CommentedOutCode.ql index 5b71bd2fe0a..d40ce95598a 100644 --- a/python/ql/src/Lexical/CommentedOutCode.ql +++ b/python/ql/src/Lexical/CommentedOutCode.ql @@ -12,7 +12,6 @@ */ import python - import Lexical.CommentedOutCode from CommentedOutCodeBlock c diff --git a/python/ql/src/Lexical/FCommentedOutCode.ql b/python/ql/src/Lexical/FCommentedOutCode.ql index 2f6ee0741c6..e988f4074c7 100644 --- a/python/ql/src/Lexical/FCommentedOutCode.ql +++ b/python/ql/src/Lexical/FCommentedOutCode.ql @@ -11,10 +11,8 @@ import python import Lexical.CommentedOutCode - import python from File f, int n where n = count(CommentedOutCodeLine c | not c.maybeExampleCode() and c.getLocation().getFile() = f) -select f, n -order by n desc +select f, n order by n desc diff --git a/python/ql/src/Lexical/OldOctalLiteral.ql b/python/ql/src/Lexical/OldOctalLiteral.ql index af0ee723c10..28791d8903d 100644 --- a/python/ql/src/Lexical/OldOctalLiteral.ql +++ b/python/ql/src/Lexical/OldOctalLiteral.ql @@ -12,8 +12,7 @@ import python predicate is_old_octal(IntegerLiteral i) { - exists(string text | - text = i.getText() | + exists(string text | text = i.getText() | text.charAt(0) = "0" and not text = "00" and exists(text.charAt(1).toInt()) and diff --git a/python/ql/src/Metrics/CLinesOfCode.ql b/python/ql/src/Metrics/CLinesOfCode.ql index 5c5453fb76a..c7b29615593 100644 --- a/python/ql/src/Metrics/CLinesOfCode.ql +++ b/python/ql/src/Metrics/CLinesOfCode.ql @@ -8,8 +8,8 @@ * @metricAggregate avg sum max * @tags maintainability */ + import python from Function f -select f, f.getMetrics().getNumberOfLinesOfCode() as n -order by n desc \ No newline at end of file +select f, f.getMetrics().getNumberOfLinesOfCode() as n order by n desc diff --git a/python/ql/src/Metrics/ClassAfferentCoupling.ql b/python/ql/src/Metrics/ClassAfferentCoupling.ql index 5fd2ec4c16f..295e8c61a6c 100644 --- a/python/ql/src/Metrics/ClassAfferentCoupling.ql +++ b/python/ql/src/Metrics/ClassAfferentCoupling.ql @@ -13,6 +13,4 @@ import python from ClassMetrics cls -select cls, cls.getAfferentCoupling() as n -order by n desc - +select cls, cls.getAfferentCoupling() as n order by n desc diff --git a/python/ql/src/Metrics/ClassEfferentCoupling.ql b/python/ql/src/Metrics/ClassEfferentCoupling.ql index d8d9dabd5dd..d960c0142e3 100644 --- a/python/ql/src/Metrics/ClassEfferentCoupling.ql +++ b/python/ql/src/Metrics/ClassEfferentCoupling.ql @@ -13,6 +13,4 @@ import python from ClassMetrics cls -select cls, cls.getEfferentCoupling() as n -order by n desc - +select cls, cls.getEfferentCoupling() as n order by n desc diff --git a/python/ql/src/Metrics/CommentRatio.ql b/python/ql/src/Metrics/CommentRatio.ql index 3f04da28283..76a185321ac 100644 --- a/python/ql/src/Metrics/CommentRatio.ql +++ b/python/ql/src/Metrics/CommentRatio.ql @@ -10,9 +10,10 @@ * @tags maintainability * documentation */ + import python from Module m, ModuleMetrics mm where mm = m.getMetrics() and mm.getNumberOfLines() > 0 -select m, 100.0 * ((float)mm.getNumberOfLinesOfComments() / (float)mm.getNumberOfLines()) as ratio -order by ratio desc +select m, 100.0 * (mm.getNumberOfLinesOfComments().(float) / mm.getNumberOfLines().(float)) as ratio + order by ratio desc diff --git a/python/ql/src/Metrics/CyclomaticComplexity.ql b/python/ql/src/Metrics/CyclomaticComplexity.ql index c5ab9858202..1e332f4ec9f 100644 --- a/python/ql/src/Metrics/CyclomaticComplexity.ql +++ b/python/ql/src/Metrics/CyclomaticComplexity.ql @@ -11,9 +11,9 @@ * complexity * maintainability */ + import python from Function func, int complexity where complexity = func.getMetrics().getCyclomaticComplexity() -select func, complexity -order by complexity desc \ No newline at end of file +select func, complexity order by complexity desc diff --git a/python/ql/src/Metrics/Dependencies/ExternalDependencies.ql b/python/ql/src/Metrics/Dependencies/ExternalDependencies.ql index 49506b0a0f9..b2c319070ea 100644 --- a/python/ql/src/Metrics/Dependencies/ExternalDependencies.ql +++ b/python/ql/src/Metrics/Dependencies/ExternalDependencies.ql @@ -2,7 +2,7 @@ * @name External dependencies * @description Count the number of dependencies that a Python source file has on external packages. * @kind treemap - * @treemap.warnOn highValues + * @treemap.warnOn highValues * @metricType externalDependency * @precision medium * @id py/external-dependencies @@ -11,18 +11,18 @@ import python import semmle.python.dependencies.TechInventory -/* +/* * These two columns encode four logical columns: - * + * * 1. Python source file where the dependency originates * 2. Package Object, ideally referring to a PyPI or similar externally provided package * 3. Version of that package Object, if known * 4. Number of dependencies from the source file to the package - * + * * Ideally this query would therefore return three columns, * but this would require changing the dashboard database schema * and dashboard extractor. - * + * * The first column (the Python source file) is prepended with a '/' * so that the file path matches the path used for the file in the * dashboard database, which is implicitly relative to the source @@ -30,15 +30,15 @@ import semmle.python.dependencies.TechInventory */ predicate src_package_count(File sourceFile, ExternalPackage package, int total) { - total = strictcount(AstNode src | - dependency(src, package) and - src.getLocation().getFile() = sourceFile - ) + total = + strictcount(AstNode src | + dependency(src, package) and + src.getLocation().getFile() = sourceFile + ) } from File sourceFile, int total, string entity, ExternalPackage package -where -src_package_count(sourceFile, package, total) and -entity = munge(sourceFile, package) -select entity, total -order by total desc +where + src_package_count(sourceFile, package, total) and + entity = munge(sourceFile, package) +select entity, total order by total desc diff --git a/python/ql/src/Metrics/Dependencies/ExternalDependenciesSourceLinks.ql b/python/ql/src/Metrics/Dependencies/ExternalDependenciesSourceLinks.ql index 3129edd6328..2424d82abeb 100644 --- a/python/ql/src/Metrics/Dependencies/ExternalDependenciesSourceLinks.ql +++ b/python/ql/src/Metrics/Dependencies/ExternalDependenciesSourceLinks.ql @@ -16,11 +16,12 @@ import semmle.python.dependencies.TechInventory * recover that information once we are in the dashboard database, using the * ExternalEntity.getASourceLink() method. */ + from File sourceFile, string entity where - exists(PackageObject package, AstNode src | - dependency(src, package) and - src.getLocation().getFile() = sourceFile and - entity = munge(sourceFile, package) - ) + exists(PackageObject package, AstNode src | + dependency(src, package) and + src.getLocation().getFile() = sourceFile and + entity = munge(sourceFile, package) + ) select entity, sourceFile diff --git a/python/ql/src/Metrics/DirectImports.ql b/python/ql/src/Metrics/DirectImports.ql index ec9114cddd9..240cd65e687 100644 --- a/python/ql/src/Metrics/DirectImports.ql +++ b/python/ql/src/Metrics/DirectImports.ql @@ -9,6 +9,7 @@ * @tags modularity * maintainability */ + import python from ModuleValue m, int n diff --git a/python/ql/src/Metrics/DocStringRatio.ql b/python/ql/src/Metrics/DocStringRatio.ql index 43d8d7af248..46859560c16 100644 --- a/python/ql/src/Metrics/DocStringRatio.ql +++ b/python/ql/src/Metrics/DocStringRatio.ql @@ -9,9 +9,11 @@ * @tags maintainability * documentation */ + import python from Module m, ModuleMetrics mm -where mm = m.getMetrics() and mm.getNumberOfLines() > 0 -select m, 100.0 * ((float)mm.getNumberOfLinesOfDocStrings() / (float)mm.getNumberOfLines()) as ratio -order by ratio desc +where mm = m.getMetrics() and mm.getNumberOfLines() > 0 +select m, + 100.0 * (mm.getNumberOfLinesOfDocStrings().(float) / mm.getNumberOfLines().(float)) as ratio + order by ratio desc diff --git a/python/ql/src/Metrics/External/CommitDisplayStrings.ql b/python/ql/src/Metrics/External/CommitDisplayStrings.ql index dd5104996d0..a682f4d1de6 100644 --- a/python/ql/src/Metrics/External/CommitDisplayStrings.ql +++ b/python/ql/src/Metrics/External/CommitDisplayStrings.ql @@ -4,7 +4,9 @@ * @id py/commit-display-strings * @metricType commit */ + import python import external.VCS + from Commit c select c.getRevisionName(), c.getMessage() + "(" + c.getDate().toString() + ")" diff --git a/python/ql/src/Metrics/External/CommitSourceLinks.ql b/python/ql/src/Metrics/External/CommitSourceLinks.ql index a31b73e2a7c..607829288c6 100644 --- a/python/ql/src/Metrics/External/CommitSourceLinks.ql +++ b/python/ql/src/Metrics/External/CommitSourceLinks.ql @@ -4,8 +4,10 @@ * @id py/commit-source-links * @metricType commit */ + import python import external.VCS + from Commit c, File f where f.fromSource() and f = c.getAnAffectedFile() select c.getRevisionName(), f diff --git a/python/ql/src/Metrics/FClasses.ql b/python/ql/src/Metrics/FClasses.ql index da667bd1df5..4736021caf2 100644 --- a/python/ql/src/Metrics/FClasses.ql +++ b/python/ql/src/Metrics/FClasses.ql @@ -13,5 +13,4 @@ import python from Module m, int n where n = count(Class c | c.getEnclosingModule() = m) -select m, n -order by n desc +select m, n order by n desc diff --git a/python/ql/src/Metrics/FFunctionsAndMethods.ql b/python/ql/src/Metrics/FFunctionsAndMethods.ql index b8d3a43b1dd..5b9fdf799cf 100644 --- a/python/ql/src/Metrics/FFunctionsAndMethods.ql +++ b/python/ql/src/Metrics/FFunctionsAndMethods.ql @@ -13,5 +13,4 @@ import python from Module m, int n where n = count(Function f | f.getEnclosingModule() = m and f.getName() != "lambda") -select m, n -order by n desc +select m, n order by n desc diff --git a/python/ql/src/Metrics/FLines.ql b/python/ql/src/Metrics/FLines.ql index 04d9abad7e4..340fb6f58ea 100644 --- a/python/ql/src/Metrics/FLines.ql +++ b/python/ql/src/Metrics/FLines.ql @@ -7,9 +7,9 @@ * @metricType file * @metricAggregate avg sum max */ + import python from Module m, int n where n = m.getMetrics().getNumberOfLines() -select m, n -order by n desc +select m, n order by n desc diff --git a/python/ql/src/Metrics/FLinesOfCode.ql b/python/ql/src/Metrics/FLinesOfCode.ql index 778897c6ae0..a46698c7087 100644 --- a/python/ql/src/Metrics/FLinesOfCode.ql +++ b/python/ql/src/Metrics/FLinesOfCode.ql @@ -10,9 +10,9 @@ * @tags maintainability * @id py/lines-of-code-in-files */ + import python from Module m, int n where n = m.getMetrics().getNumberOfLinesOfCode() -select m, n -order by n desc +select m, n order by n desc diff --git a/python/ql/src/Metrics/FLinesOfComments.ql b/python/ql/src/Metrics/FLinesOfComments.ql index 38b19c2dc46..bd52f8d5caa 100644 --- a/python/ql/src/Metrics/FLinesOfComments.ql +++ b/python/ql/src/Metrics/FLinesOfComments.ql @@ -9,9 +9,10 @@ * @precision very-high * @id py/lines-of-comments-in-files */ + import python from Module m, int n -where n = m.getMetrics().getNumberOfLinesOfComments() + m.getMetrics().getNumberOfLinesOfDocStrings() -select m, n -order by n desc +where + n = m.getMetrics().getNumberOfLinesOfComments() + m.getMetrics().getNumberOfLinesOfDocStrings() +select m, n order by n desc diff --git a/python/ql/src/Metrics/FLinesOfDuplicatedCode.ql b/python/ql/src/Metrics/FLinesOfDuplicatedCode.ql index ac8e0a3a25c..03bee534ee3 100644 --- a/python/ql/src/Metrics/FLinesOfDuplicatedCode.ql +++ b/python/ql/src/Metrics/FLinesOfDuplicatedCode.ql @@ -10,17 +10,17 @@ * @tags testability * @id py/duplicated-lines-in-files */ + import python import external.CodeDuplication - + from File f, int n - -where n = count(int line | - exists(DuplicateBlock d | d.sourceFile() = f | - line in [d.sourceStartLine()..d.sourceEndLine()] and - not whitelistedLineForDuplication(f, line) - ) -) - -select f, n -order by n desc +where + n = + count(int line | + exists(DuplicateBlock d | d.sourceFile() = f | + line in [d.sourceStartLine() .. d.sourceEndLine()] and + not whitelistedLineForDuplication(f, line) + ) + ) +select f, n order by n desc diff --git a/python/ql/src/Metrics/FLinesOfSimilarCode.ql b/python/ql/src/Metrics/FLinesOfSimilarCode.ql index e78fe52959b..d407a38d63d 100644 --- a/python/ql/src/Metrics/FLinesOfSimilarCode.ql +++ b/python/ql/src/Metrics/FLinesOfSimilarCode.ql @@ -10,17 +10,17 @@ * @tags testability * @id py/similar-lines-in-files */ + import python import external.CodeDuplication - + from File f, int n - -where n = count(int line | - exists(SimilarBlock d | d.sourceFile() = f | - line in [d.sourceStartLine()..d.sourceEndLine()] and - not whitelistedLineForDuplication(f, line) - ) -) - -select f, n -order by n desc +where + n = + count(int line | + exists(SimilarBlock d | d.sourceFile() = f | + line in [d.sourceStartLine() .. d.sourceEndLine()] and + not whitelistedLineForDuplication(f, line) + ) + ) +select f, n order by n desc diff --git a/python/ql/src/Metrics/FNumberOfTests.ql b/python/ql/src/Metrics/FNumberOfTests.ql index 1cc914a0d55..34a76c70d33 100644 --- a/python/ql/src/Metrics/FNumberOfTests.ql +++ b/python/ql/src/Metrics/FNumberOfTests.ql @@ -6,13 +6,12 @@ * @metricType file * @metricAggregate avg sum max * @precision medium - * @precision very-high * @id py/tests-in-files */ + import python import semmle.python.filters.Tests from Module m, int n where n = strictcount(Test test | test.getEnclosingModule() = m) -select m.getFile(), n -order by n desc +select m.getFile(), n order by n desc diff --git a/python/ql/src/Metrics/FunctionNumberOfCalls.ql b/python/ql/src/Metrics/FunctionNumberOfCalls.ql index 0dd5050214a..fb4dfe5a9d2 100644 --- a/python/ql/src/Metrics/FunctionNumberOfCalls.ql +++ b/python/ql/src/Metrics/FunctionNumberOfCalls.ql @@ -3,14 +3,12 @@ * @description The total number of calls in a function. * @kind treemap * @id py/number-of-calls-per-function - * @treemap.warnOn highValues + * @treemap.warnOn highValues * @metricType callable * @metricAggregate avg max */ import python - from FunctionMetrics func -select func, func.getNumberOfCalls() as n -order by n desc +select func, func.getNumberOfCalls() as n order by n desc diff --git a/python/ql/src/Metrics/FunctionStatementNestingDepth.ql b/python/ql/src/Metrics/FunctionStatementNestingDepth.ql index 64a72fbd34d..ab40cc6068d 100644 --- a/python/ql/src/Metrics/FunctionStatementNestingDepth.ql +++ b/python/ql/src/Metrics/FunctionStatementNestingDepth.ql @@ -12,7 +12,5 @@ import python - from FunctionMetrics func -select func, func.getStatementNestingDepth() as n -order by n desc +select func, func.getStatementNestingDepth() as n order by n desc diff --git a/python/ql/src/Metrics/History/HChurn.ql b/python/ql/src/Metrics/History/HChurn.ql index 437fae7460c..e18b8dd528a 100644 --- a/python/ql/src/Metrics/History/HChurn.ql +++ b/python/ql/src/Metrics/History/HChurn.ql @@ -7,11 +7,17 @@ * @metricType file * @metricAggregate avg sum max */ + import python import external.VCS from Module m, int n -where n = sum(Commit entry, int churn | churn = entry.getRecentChurnForFile(m.getFile()) and not artificialChange(entry) | churn) - and exists(m.getMetrics().getNumberOfLinesOfCode()) -select m, n -order by n desc +where + n = + sum(Commit entry, int churn | + churn = entry.getRecentChurnForFile(m.getFile()) and not artificialChange(entry) + | + churn + ) and + exists(m.getMetrics().getNumberOfLinesOfCode()) +select m, n order by n desc diff --git a/python/ql/src/Metrics/History/HLinesAdded.ql b/python/ql/src/Metrics/History/HLinesAdded.ql index 9eea8687118..239d227f365 100644 --- a/python/ql/src/Metrics/History/HLinesAdded.ql +++ b/python/ql/src/Metrics/History/HLinesAdded.ql @@ -7,11 +7,17 @@ * @metricType file * @metricAggregate avg sum max */ + import python import external.VCS from Module m, int n -where n = sum(Commit entry, int churn | churn = entry.getRecentAdditionsForFile(m.getFile()) and not artificialChange(entry) | churn) - and exists(m.getMetrics().getNumberOfLinesOfCode()) -select m, n -order by n desc +where + n = + sum(Commit entry, int churn | + churn = entry.getRecentAdditionsForFile(m.getFile()) and not artificialChange(entry) + | + churn + ) and + exists(m.getMetrics().getNumberOfLinesOfCode()) +select m, n order by n desc diff --git a/python/ql/src/Metrics/History/HLinesDeleted.ql b/python/ql/src/Metrics/History/HLinesDeleted.ql index 905d15b524c..7f02c17cc2c 100644 --- a/python/ql/src/Metrics/History/HLinesDeleted.ql +++ b/python/ql/src/Metrics/History/HLinesDeleted.ql @@ -7,11 +7,17 @@ * @metricType file * @metricAggregate avg sum max */ + import python import external.VCS from Module m, int n -where n = sum(Commit entry, int churn | churn = entry.getRecentDeletionsForFile(m.getFile()) and not artificialChange(entry) | churn) - and exists(m.getMetrics().getNumberOfLinesOfCode()) -select m, n -order by n desc +where + n = + sum(Commit entry, int churn | + churn = entry.getRecentDeletionsForFile(m.getFile()) and not artificialChange(entry) + | + churn + ) and + exists(m.getMetrics().getNumberOfLinesOfCode()) +select m, n order by n desc diff --git a/python/ql/src/Metrics/History/HNumberOfAuthors.ql b/python/ql/src/Metrics/History/HNumberOfAuthors.ql index fef769fc705..15e679e58c5 100644 --- a/python/ql/src/Metrics/History/HNumberOfAuthors.ql +++ b/python/ql/src/Metrics/History/HNumberOfAuthors.ql @@ -7,10 +7,10 @@ * @metricType file * @metricAggregate avg min max */ + import python import external.VCS from Module m where exists(m.getMetrics().getNumberOfLinesOfCode()) select m, count(Author author | author.getAnEditedFile() = m.getFile()) - diff --git a/python/ql/src/Metrics/History/HNumberOfCoCommits.ql b/python/ql/src/Metrics/History/HNumberOfCoCommits.ql index 81dbe8ba2da..4f48641e394 100644 --- a/python/ql/src/Metrics/History/HNumberOfCoCommits.ql +++ b/python/ql/src/Metrics/History/HNumberOfCoCommits.ql @@ -7,14 +7,17 @@ * @metricType file * @metricAggregate avg min max */ + import python import external.VCS -int committedFiles(Commit commit) { - result = count(commit.getAnAffectedFile()) -} +int committedFiles(Commit commit) { result = count(commit.getAnAffectedFile()) } from Module m where exists(m.getMetrics().getNumberOfLinesOfCode()) -select m, avg(Commit commit, int toAvg | (commit.getAnAffectedFile() = m.getFile()) and (toAvg = committedFiles(commit)-1) | toAvg) - +select m, + avg(Commit commit, int toAvg | + commit.getAnAffectedFile() = m.getFile() and toAvg = committedFiles(commit) - 1 + | + toAvg + ) diff --git a/python/ql/src/Metrics/History/HNumberOfCommits.ql b/python/ql/src/Metrics/History/HNumberOfCommits.ql index deca31e1444..d7f99646fe3 100644 --- a/python/ql/src/Metrics/History/HNumberOfCommits.ql +++ b/python/ql/src/Metrics/History/HNumberOfCommits.ql @@ -7,6 +7,7 @@ * @metricType commit * @metricAggregate sum */ + import python import external.VCS diff --git a/python/ql/src/Metrics/History/HNumberOfReCommits.ql b/python/ql/src/Metrics/History/HNumberOfReCommits.ql index f5831944aed..c1863e934c9 100644 --- a/python/ql/src/Metrics/History/HNumberOfReCommits.ql +++ b/python/ql/src/Metrics/History/HNumberOfReCommits.ql @@ -5,25 +5,30 @@ * @id py/historical-number-of-re-commits * @treemap.warnOn highValues * @metricType file - * @metricAggregate avg min max + * @metricAggregate avg min max */ + import python import external.VCS predicate inRange(Commit first, Commit second) { - first.getAnAffectedFile() = second.getAnAffectedFile() and - first != second and - exists(int n | n = first.getDate().daysTo(second.getDate()) and - n >= 0 and n < 5) + first.getAnAffectedFile() = second.getAnAffectedFile() and + first != second and + exists(int n | + n = first.getDate().daysTo(second.getDate()) and + n >= 0 and + n < 5 + ) } int recommitsForFile(File f) { - result = count(Commit recommit | - f = recommit.getAnAffectedFile() and - exists(Commit prev | inRange(prev, recommit))) + result = + count(Commit recommit | + f = recommit.getAnAffectedFile() and + exists(Commit prev | inRange(prev, recommit)) + ) } from Module m where exists(m.getMetrics().getNumberOfLinesOfCode()) select m, recommitsForFile(m.getFile()) - diff --git a/python/ql/src/Metrics/History/HNumberOfRecentAuthors.ql b/python/ql/src/Metrics/History/HNumberOfRecentAuthors.ql index 6ea84550f76..75832cc82bd 100644 --- a/python/ql/src/Metrics/History/HNumberOfRecentAuthors.ql +++ b/python/ql/src/Metrics/History/HNumberOfRecentAuthors.ql @@ -7,10 +7,18 @@ * @metricType file * @metricAggregate avg min max */ + import python import external.VCS from Module m where exists(m.getMetrics().getNumberOfLinesOfCode()) -select m, count(Author author | exists(Commit e | e = author.getACommit() and m.getFile() = e.getAnAffectedFile() and e.daysToNow() <= 180 and not artificialChange(e))) - +select m, + count(Author author | + exists(Commit e | + e = author.getACommit() and + m.getFile() = e.getAnAffectedFile() and + e.daysToNow() <= 180 and + not artificialChange(e) + ) + ) diff --git a/python/ql/src/Metrics/History/HNumberOfRecentChangedFiles.ql b/python/ql/src/Metrics/History/HNumberOfRecentChangedFiles.ql index 3f35a9cba77..9b90a73294f 100644 --- a/python/ql/src/Metrics/History/HNumberOfRecentChangedFiles.ql +++ b/python/ql/src/Metrics/History/HNumberOfRecentChangedFiles.ql @@ -5,13 +5,16 @@ * @id py/historical-number-of-recent-changed-files * @treemap.warnOn highValues * @metricType file - * @metricAggregate avg min max + * @metricAggregate avg min max */ + import python import external.VCS from Module m -where exists(Commit e | e.getAnAffectedFile() = m.getFile() and e.daysToNow() <= 180 and not artificialChange(e)) - and exists(m.getMetrics().getNumberOfLinesOfCode()) +where + exists(Commit e | + e.getAnAffectedFile() = m.getFile() and e.daysToNow() <= 180 and not artificialChange(e) + ) and + exists(m.getMetrics().getNumberOfLinesOfCode()) select m, 1 - diff --git a/python/ql/src/Metrics/History/HNumberOfRecentCommits.ql b/python/ql/src/Metrics/History/HNumberOfRecentCommits.ql index e9e3b14538f..7ebec9bb7a4 100644 --- a/python/ql/src/Metrics/History/HNumberOfRecentCommits.ql +++ b/python/ql/src/Metrics/History/HNumberOfRecentCommits.ql @@ -7,10 +7,10 @@ * @metricType commit * @metricAggregate sum */ + import python import external.VCS from Commit c where c.daysToNow() <= 180 and not artificialChange(c) select c.getRevisionName(), 1 - diff --git a/python/ql/src/Metrics/Internal/CallableDisplayStrings.ql b/python/ql/src/Metrics/Internal/CallableDisplayStrings.ql index 47a6f20db3e..3f4790272d2 100644 --- a/python/ql/src/Metrics/Internal/CallableDisplayStrings.ql +++ b/python/ql/src/Metrics/Internal/CallableDisplayStrings.ql @@ -4,6 +4,7 @@ * @id py/function-display-strings * @metricType callable */ + import python from Function f diff --git a/python/ql/src/Metrics/Internal/CallableExtents.ql b/python/ql/src/Metrics/Internal/CallableExtents.ql index 7e2d0baedfa..be617bf2e44 100644 --- a/python/ql/src/Metrics/Internal/CallableExtents.ql +++ b/python/ql/src/Metrics/Internal/CallableExtents.ql @@ -4,6 +4,7 @@ * @id py/function-extents * @metricType callable */ + import python import Extents diff --git a/python/ql/src/Metrics/Internal/CallableSourceLinks.ql b/python/ql/src/Metrics/Internal/CallableSourceLinks.ql index 41278a18684..0e37d683222 100644 --- a/python/ql/src/Metrics/Internal/CallableSourceLinks.ql +++ b/python/ql/src/Metrics/Internal/CallableSourceLinks.ql @@ -4,6 +4,7 @@ * @id py/function-source-links * @metricType callable */ + import python from Function f diff --git a/python/ql/src/Metrics/Internal/ClassDisplayStrings.ql b/python/ql/src/Metrics/Internal/ClassDisplayStrings.ql index 612abfebec7..cf240b42af1 100644 --- a/python/ql/src/Metrics/Internal/ClassDisplayStrings.ql +++ b/python/ql/src/Metrics/Internal/ClassDisplayStrings.ql @@ -4,6 +4,7 @@ * @id py/lgtm/class-display-strings * @metricType reftype */ + import python from Class c diff --git a/python/ql/src/Metrics/Internal/ClassExtents.ql b/python/ql/src/Metrics/Internal/ClassExtents.ql index cc5fd7e9390..b3b3985a8a8 100644 --- a/python/ql/src/Metrics/Internal/ClassExtents.ql +++ b/python/ql/src/Metrics/Internal/ClassExtents.ql @@ -4,6 +4,7 @@ * @id py/class-extents * @metricType reftype */ + import python import Extents diff --git a/python/ql/src/Metrics/Internal/ClassSourceLinks.ql b/python/ql/src/Metrics/Internal/ClassSourceLinks.ql index 089596a0d40..198328f2e8d 100644 --- a/python/ql/src/Metrics/Internal/ClassSourceLinks.ql +++ b/python/ql/src/Metrics/Internal/ClassSourceLinks.ql @@ -4,6 +4,7 @@ * @id py/class-source-links * @metricType reftype */ + import python from Class c diff --git a/python/ql/src/Metrics/LackofCohesionInMethodsCK.ql b/python/ql/src/Metrics/LackofCohesionInMethodsCK.ql index c950cd4bac4..c0ef582c32b 100644 --- a/python/ql/src/Metrics/LackofCohesionInMethodsCK.ql +++ b/python/ql/src/Metrics/LackofCohesionInMethodsCK.ql @@ -3,14 +3,12 @@ * @description Lack of cohesion in the methods of a class, as defined by Chidamber and Kemerer. * @kind treemap * @id py/lack-of-cohesion-chidamber-kemerer - * @treemap.warnOn highValues + * @treemap.warnOn highValues * @metricType reftype * @metricAggregate avg max */ import python - from ClassMetrics cls -select cls, cls.getLackOfCohesionCK() as n -order by n desc +select cls, cls.getLackOfCohesionCK() as n order by n desc diff --git a/python/ql/src/Metrics/LackofCohesionInMethodsHM.ql b/python/ql/src/Metrics/LackofCohesionInMethodsHM.ql index 0a315c44ea7..5cc77ecfb4f 100644 --- a/python/ql/src/Metrics/LackofCohesionInMethodsHM.ql +++ b/python/ql/src/Metrics/LackofCohesionInMethodsHM.ql @@ -3,14 +3,12 @@ * @description Lack of cohesion of a class, as defined by Hitz and Montazeri. * @kind treemap * @id py/lack-of-cohesion-hitz-montazeri - * @treemap.warnOn highValues + * @treemap.warnOn highValues * @metricType reftype * @metricAggregate avg max */ import python - from ClassMetrics cls -select cls, cls.getLackOfCohesionHM() as n -order by n desc +select cls, cls.getLackOfCohesionHM() as n order by n desc diff --git a/python/ql/src/Metrics/ModuleAfferentCoupling.ql b/python/ql/src/Metrics/ModuleAfferentCoupling.ql index f8f5e0c4208..7bf51433785 100644 --- a/python/ql/src/Metrics/ModuleAfferentCoupling.ql +++ b/python/ql/src/Metrics/ModuleAfferentCoupling.ql @@ -13,6 +13,4 @@ import python from ModuleMetrics m -select m, m.getAfferentCoupling() as n -order by n desc - +select m, m.getAfferentCoupling() as n order by n desc diff --git a/python/ql/src/Metrics/ModuleEfferentCoupling.ql b/python/ql/src/Metrics/ModuleEfferentCoupling.ql index be32b8bc561..51fdcf5423b 100644 --- a/python/ql/src/Metrics/ModuleEfferentCoupling.ql +++ b/python/ql/src/Metrics/ModuleEfferentCoupling.ql @@ -13,6 +13,4 @@ import python from ModuleMetrics m -select m, m.getEfferentCoupling() as n -order by n desc - +select m, m.getEfferentCoupling() as n order by n desc diff --git a/python/ql/src/Metrics/NumberOfParametersWithoutDefault.ql b/python/ql/src/Metrics/NumberOfParametersWithoutDefault.ql index 4ddd2ba1f0e..00a4c1bf0db 100644 --- a/python/ql/src/Metrics/NumberOfParametersWithoutDefault.ql +++ b/python/ql/src/Metrics/NumberOfParametersWithoutDefault.ql @@ -12,7 +12,5 @@ import python - from FunctionMetrics func -select func, func.getNumberOfParametersWithoutDefault() as n -order by n desc +select func, func.getNumberOfParametersWithoutDefault() as n order by n desc diff --git a/python/ql/src/Metrics/NumberOfStatements.ql b/python/ql/src/Metrics/NumberOfStatements.ql index 66263f68a84..a5025d8b95d 100644 --- a/python/ql/src/Metrics/NumberOfStatements.ql +++ b/python/ql/src/Metrics/NumberOfStatements.ql @@ -7,9 +7,9 @@ * @metricType file * @metricAggregate avg sum max */ + import python from Module m, int n where n = count(Stmt s | s.getEnclosingModule() = m) -select m, n -order by n desc +select m, n order by n desc diff --git a/python/ql/src/Metrics/TransitiveImports.ql b/python/ql/src/Metrics/TransitiveImports.ql index cea731388f9..a46a7a16302 100644 --- a/python/ql/src/Metrics/TransitiveImports.ql +++ b/python/ql/src/Metrics/TransitiveImports.ql @@ -9,6 +9,7 @@ * @metricAggregate avg max * @tags modularity */ + import python from ModuleValue m, int n diff --git a/python/ql/src/Numerics/Pythagorean.ql b/python/ql/src/Numerics/Pythagorean.ql index 920ec3f326b..6522da8a2b2 100644 --- a/python/ql/src/Numerics/Pythagorean.ql +++ b/python/ql/src/Numerics/Pythagorean.ql @@ -12,37 +12,34 @@ import python predicate squareOp(BinaryExpr e) { - e.getOp() instanceof Pow and e.getRight().(IntegerLiteral).getN() = "2" + e.getOp() instanceof Pow and e.getRight().(IntegerLiteral).getN() = "2" } predicate squareMul(BinaryExpr e) { - e.getOp() instanceof Mult and e.getRight().(Name).getId() = e.getLeft().(Name).getId() + e.getOp() instanceof Mult and e.getRight().(Name).getId() = e.getLeft().(Name).getId() } predicate squareRef(Name e) { - e.isUse() and - exists(SsaVariable v, Expr s | - v.getVariable() = e.getVariable() | - s = v.getDefinition().getNode().getParentNode().(AssignStmt).getValue() and - square(s) - ) + e.isUse() and + exists(SsaVariable v, Expr s | v.getVariable() = e.getVariable() | + s = v.getDefinition().getNode().getParentNode().(AssignStmt).getValue() and + square(s) + ) } predicate square(Expr e) { - squareOp(e) - or - squareMul(e) - or - squareRef(e) + squareOp(e) + or + squareMul(e) + or + squareRef(e) } -from - Call c, - BinaryExpr s +from Call c, BinaryExpr s where - c.getFunc().toString() = "sqrt" and - c.getArg(0) = s and - s.getOp() instanceof Add and - square(s.getLeft()) and square(s.getRight()) -select - c, "Pythagorean calculation with sub-optimal numerics" \ No newline at end of file + c.getFunc().toString() = "sqrt" and + c.getArg(0) = s and + s.getOp() instanceof Add and + square(s.getLeft()) and + square(s.getRight()) +select c, "Pythagorean calculation with sub-optimal numerics" diff --git a/python/ql/src/Security/CWE-020/IncompleteHostnameRegExp.ql b/python/ql/src/Security/CWE-020/IncompleteHostnameRegExp.ql index 59c7d804b5d..3fb7046f8cc 100644 --- a/python/ql/src/Security/CWE-020/IncompleteHostnameRegExp.ql +++ b/python/ql/src/Security/CWE-020/IncompleteHostnameRegExp.ql @@ -21,7 +21,8 @@ private string commonTopLevelDomainRegex() { result = "com|org|edu|gov|uk|net|io */ bindingset[pattern] predicate isIncompleteHostNameRegExpPattern(string pattern, string hostPart) { - hostPart = pattern + hostPart = + pattern .regexpCapture("(?i).*" + // an unescaped single `.` "(? 1 and problem = "multiple toStrings()" and what = o.toString() ) @@ -122,55 +163,64 @@ predicate source_object_sanity(string clsname, string problem, string what) { predicate ssa_sanity(string clsname, string problem, string what) { /* Zero or one definitions of each SSA variable */ - exists(SsaVariable var | - clsname = var.getAQlClass() | - uniqueness_error(strictcount(var.getDefinition()), "getDefinition", problem) and what = var.getId() + exists(SsaVariable var | clsname = var.getAQlClass() | + uniqueness_error(strictcount(var.getDefinition()), "getDefinition", problem) and + what = var.getId() ) or /* Dominance criterion: Definition *must* dominate *all* uses. */ exists(SsaVariable var, ControlFlowNode defn, ControlFlowNode use | - defn = var.getDefinition() and use = var.getAUse() | - not defn.strictlyDominates(use) and not defn = use and + defn = var.getDefinition() and use = var.getAUse() + | + not defn.strictlyDominates(use) and + not defn = use and /* Phi nodes which share a flow node with a use come *before* the use */ not (exists(var.getAPhiInput()) and defn = use) and - clsname = var.getAQlClass() and problem = "a definition which does not dominate a use at " + use.getLocation() and what = var.getId() + " at " + var.getLocation() + clsname = var.getAQlClass() and + problem = "a definition which does not dominate a use at " + use.getLocation() and + what = var.getId() + " at " + var.getLocation() ) or /* Minimality of phi nodes */ exists(SsaVariable var | strictcount(var.getAPhiInput()) = 1 and - var.getAPhiInput().getDefinition().getBasicBlock().strictlyDominates(var.getDefinition().getBasicBlock()) - | - clsname = var.getAQlClass() and problem = " a definition which is dominated by the definition of an incoming phi edge." and what = var.getId() + " at " + var.getLocation() + var + .getAPhiInput() + .getDefinition() + .getBasicBlock() + .strictlyDominates(var.getDefinition().getBasicBlock()) + | + clsname = var.getAQlClass() and + problem = " a definition which is dominated by the definition of an incoming phi edge." and + what = var.getId() + " at " + var.getLocation() ) } predicate function_object_sanity(string clsname, string problem, string what) { - exists(FunctionObject func | - clsname = func.getAQlClass() | + exists(FunctionObject func | clsname = func.getAQlClass() | what = func.getName() and ( count(func.descriptiveString()) = 0 and problem = "no descriptiveString()" or - exists(int c | - c = strictcount(func.descriptiveString()) and c > 1 | + exists(int c | c = strictcount(func.descriptiveString()) and c > 1 | problem = c + "descriptiveString()s" ) ) - or + or not exists(func.getName()) and what = "?" and problem = "no name" ) - } predicate multiple_origins_per_object(Object obj) { - not obj.isC() and not obj instanceof ModuleObject and - exists(ControlFlowNode use, Context ctx | strictcount(ControlFlowNode orig | use.refersTo(ctx, obj, _, orig)) > 1) + not obj.isC() and + not obj instanceof ModuleObject and + exists(ControlFlowNode use, Context ctx | + strictcount(ControlFlowNode orig | use.refersTo(ctx, obj, _, orig)) > 1 + ) } predicate intermediate_origins(ControlFlowNode use, ControlFlowNode inter, Object obj) { - exists(ControlFlowNode orig, Context ctx | - not inter = orig | + exists(ControlFlowNode orig, Context ctx | not inter = orig | use.refersTo(ctx, obj, _, inter) and inter.refersTo(ctx, obj, _, orig) and // It can sometimes happen that two different modules (e.g. cPickle and Pickle) @@ -181,8 +231,10 @@ predicate intermediate_origins(ControlFlowNode use, ControlFlowNode inter, Objec predicate points_to_sanity(string clsname, string problem, string what) { exists(Object obj | - multiple_origins_per_object(obj) and clsname = obj.getAQlClass() and - problem = "multiple origins for an object" and what = obj.toString() + multiple_origins_per_object(obj) and + clsname = obj.getAQlClass() and + problem = "multiple origins for an object" and + what = obj.toString() ) or exists(ControlFlowNode use, ControlFlowNode inter, Object obj | @@ -194,8 +246,8 @@ predicate points_to_sanity(string clsname, string problem, string what) { } predicate jump_to_definition_sanity(string clsname, string problem, string what) { - problem = "multiple (jump-to) definitions" and - exists(Expr use | + problem = "multiple (jump-to) definitions" and + exists(Expr use | strictcount(getUniqueDefinition(use)) > 1 and clsname = use.getAQlClass() and what = use.toString() @@ -208,10 +260,12 @@ predicate file_sanity(string clsname, string problem, string what) { problem = "has same name as a folder" and what = file.getAbsolutePath() and what = folder.getAbsolutePath() - ) or + ) + or exists(Container f | clsname = f.getAQlClass() and - uniqueness_error(count(f.toString()), "toString", problem) and what = "file " + f.getName() + uniqueness_error(count(f.toString()), "toString", problem) and + what = "file " + f.getName() ) } @@ -228,17 +282,17 @@ predicate class_value_sanity(string clsname, string problem, string what) { } from string clsname, string problem, string what -where -ast_sanity(clsname, problem, what) or -location_sanity(clsname, problem, what)or -scope_sanity(clsname, problem, what) or -cfg_sanity(clsname, problem, what) or -ssa_sanity(clsname, problem, what) or -builtin_object_sanity(clsname, problem, what) or -source_object_sanity(clsname, problem, what) or -function_object_sanity(clsname, problem, what) or -points_to_sanity(clsname, problem, what) or -jump_to_definition_sanity(clsname, problem, what) or -file_sanity(clsname, problem, what) or -class_value_sanity(clsname, problem, what) +where + ast_sanity(clsname, problem, what) or + location_sanity(clsname, problem, what) or + scope_sanity(clsname, problem, what) or + cfg_sanity(clsname, problem, what) or + ssa_sanity(clsname, problem, what) or + builtin_object_sanity(clsname, problem, what) or + source_object_sanity(clsname, problem, what) or + function_object_sanity(clsname, problem, what) or + points_to_sanity(clsname, problem, what) or + jump_to_definition_sanity(clsname, problem, what) or + file_sanity(clsname, problem, what) or + class_value_sanity(clsname, problem, what) select clsname + " " + what + " has " + problem diff --git a/python/ql/src/analysis/Summary.ql b/python/ql/src/analysis/Summary.ql index ba2fee0b4a8..55564edb16e 100644 --- a/python/ql/src/analysis/Summary.ql +++ b/python/ql/src/analysis/Summary.ql @@ -1,38 +1,43 @@ -/** Summarize a snapshot +/** + * Summarize a snapshot */ import python from string key, string value where -key = "Extractor version" and py_flags_versioned("extractor.version", value, _) -or -key = "Snapshot build time" and exists(date d | snapshotDate(d) and value = d.toString()) -or -key = "Interpreter version" and -exists(string major, string minor | - py_flags_versioned("version.major", major, _) and - py_flags_versioned("version.minor", minor, _) and - value = major + "." + minor -) -or -key = "Build platform" and -exists(string raw | - py_flags_versioned("sys.platform", raw, _) | - if raw = "win32" then - value = "Windows" - else if raw = "linux2" then - value = "Linux" - else if raw = "darwin" then - value = "OSX" - else - value = raw -) -or -key = "Source location" and sourceLocationPrefix(value) -or -key = "Lines of code (source)" and value = sum(ModuleMetrics m | exists(m.getFile().getRelativePath()) | m.getNumberOfLinesOfCode()).toString() -or -key = "Lines of code (total)" and value = sum(ModuleMetrics m | any() | m.getNumberOfLinesOfCode()).toString() - + key = "Extractor version" and py_flags_versioned("extractor.version", value, _) + or + key = "Snapshot build time" and + exists(date d | snapshotDate(d) and value = d.toString()) + or + key = "Interpreter version" and + exists(string major, string minor | + py_flags_versioned("version.major", major, _) and + py_flags_versioned("version.minor", minor, _) and + value = major + "." + minor + ) + or + key = "Build platform" and + exists(string raw | py_flags_versioned("sys.platform", raw, _) | + if raw = "win32" + then value = "Windows" + else + if raw = "linux2" + then value = "Linux" + else + if raw = "darwin" + then value = "OSX" + else value = raw + ) + or + key = "Source location" and sourceLocationPrefix(value) + or + key = "Lines of code (source)" and + value = + sum(ModuleMetrics m | exists(m.getFile().getRelativePath()) | m.getNumberOfLinesOfCode()) + .toString() + or + key = "Lines of code (total)" and + value = sum(ModuleMetrics m | any() | m.getNumberOfLinesOfCode()).toString() select key, value diff --git a/python/ql/src/analysis/TypeHierarchyFailure.ql b/python/ql/src/analysis/TypeHierarchyFailure.ql index 8aac3ea236b..c4c91005743 100644 --- a/python/ql/src/analysis/TypeHierarchyFailure.ql +++ b/python/ql/src/analysis/TypeHierarchyFailure.ql @@ -9,8 +9,6 @@ import python - from Class cls, string reason -where -exists(ClassObject c | c.getPyClass() = cls | c.failedInference(reason)) +where exists(ClassObject c | c.getPyClass() = cls | c.failedInference(reason)) select cls, "Inference of class hierarchy failed for class '" + cls.getName() + "': " + reason + "." diff --git a/python/ql/src/analysis/TypeInferenceFailure.ql b/python/ql/src/analysis/TypeInferenceFailure.ql index 1b8237d65a1..0e6e42e8385 100644 --- a/python/ql/src/analysis/TypeInferenceFailure.ql +++ b/python/ql/src/analysis/TypeInferenceFailure.ql @@ -6,10 +6,11 @@ * @id py/type-inference-failure * @deprecated */ + import python - from ControlFlowNode f, Object o -where f.refersTo(o) and -not exists(ClassObject c | f.refersTo(o, c, _)) -select o, "Type inference fails for 'object'." \ No newline at end of file +where + f.refersTo(o) and + not exists(ClassObject c | f.refersTo(o, c, _)) +select o, "Type inference fails for 'object'." diff --git a/python/ql/src/external/DuplicateBlock.ql b/python/ql/src/external/DuplicateBlock.ql index f9a75f437a2..38aed20739f 100644 --- a/python/ql/src/external/DuplicateBlock.ql +++ b/python/ql/src/external/DuplicateBlock.ql @@ -14,21 +14,21 @@ * @precision medium * @id py/duplicate-block */ + import python import CodeDuplication predicate sorted_by_location(DuplicateBlock x, DuplicateBlock y) { - if x.sourceFile() = y.sourceFile() then - x.sourceStartLine() < y.sourceStartLine() - else - x.sourceFile().getAbsolutePath() < y.sourceFile().getAbsolutePath() + if x.sourceFile() = y.sourceFile() + then x.sourceStartLine() < y.sourceStartLine() + else x.sourceFile().getAbsolutePath() < y.sourceFile().getAbsolutePath() } from DuplicateBlock d, DuplicateBlock other -where d.sourceLines() > 10 and - other.getEquivalenceClass() = d.getEquivalenceClass() and - sorted_by_location(other, d) -select - d, - "Duplicate code: " + d.sourceLines() + " lines are duplicated at " + - other.sourceFile().getShortName() + ":" + other.sourceStartLine().toString() +where + d.sourceLines() > 10 and + other.getEquivalenceClass() = d.getEquivalenceClass() and + sorted_by_location(other, d) +select d, + "Duplicate code: " + d.sourceLines() + " lines are duplicated at " + + other.sourceFile().getShortName() + ":" + other.sourceStartLine().toString() diff --git a/python/ql/src/external/DuplicateFunction.ql b/python/ql/src/external/DuplicateFunction.ql index ddf587caf68..b638f6fb5b2 100644 --- a/python/ql/src/external/DuplicateFunction.ql +++ b/python/ql/src/external/DuplicateFunction.ql @@ -13,19 +13,17 @@ * @precision high * @id py/duplicate-function */ + import python import CodeDuplication -predicate relevant(Function m) { - m.getMetrics().getNumberOfLinesOfCode() > 5 -} +predicate relevant(Function m) { m.getMetrics().getNumberOfLinesOfCode() > 5 } from Function m, Function other, string message, int percent -where duplicateScopes(m, other, percent, message) - and relevant(m) - and percent > 95.0 - and not duplicateScopes(m.getEnclosingModule(), other.getEnclosingModule(), _, _) - and not duplicateScopes(m.getScope(), other.getScope(), _, _) -select m, message, - other, - other.getName() +where + duplicateScopes(m, other, percent, message) and + relevant(m) and + percent > 95.0 and + not duplicateScopes(m.getEnclosingModule(), other.getEnclosingModule(), _, _) and + not duplicateScopes(m.getScope(), other.getScope(), _, _) +select m, message, other, other.getName() diff --git a/python/ql/src/external/MostlyDuplicateClass.ql b/python/ql/src/external/MostlyDuplicateClass.ql index 7a6f0b7587d..88169ab897f 100644 --- a/python/ql/src/external/MostlyDuplicateClass.ql +++ b/python/ql/src/external/MostlyDuplicateClass.ql @@ -13,12 +13,13 @@ * @precision high * @id py/mostly-duplicate-class */ + import python import CodeDuplication from Class c, Class other, string message -where duplicateScopes(c, other, _, message) - and count(c.getAStmt()) > 3 - and not duplicateScopes(c.getEnclosingModule(), _, _, _) +where + duplicateScopes(c, other, _, message) and + count(c.getAStmt()) > 3 and + not duplicateScopes(c.getEnclosingModule(), _, _, _) select c, message, other, other.getName() - diff --git a/python/ql/src/external/MostlyDuplicateFile.ql b/python/ql/src/external/MostlyDuplicateFile.ql index 57178d8846e..78df1a4166e 100644 --- a/python/ql/src/external/MostlyDuplicateFile.ql +++ b/python/ql/src/external/MostlyDuplicateFile.ql @@ -13,6 +13,7 @@ * @precision high * @id py/mostly-duplicate-file */ + import python import CodeDuplication diff --git a/python/ql/src/external/MostlySimilarFile.ql b/python/ql/src/external/MostlySimilarFile.ql index 4bdcce626c9..97413885962 100644 --- a/python/ql/src/external/MostlySimilarFile.ql +++ b/python/ql/src/external/MostlySimilarFile.ql @@ -9,11 +9,11 @@ * duplicate-code * statistical * non-attributable - * @problem.severity recommendation * @sub-severity low * @precision high * @id py/mostly-similar-file */ + import python import CodeDuplication diff --git a/python/ql/src/external/SimilarFunction.ql b/python/ql/src/external/SimilarFunction.ql index 9d0a3f72cfb..bcd63a41dcf 100644 --- a/python/ql/src/external/SimilarFunction.ql +++ b/python/ql/src/external/SimilarFunction.ql @@ -13,23 +13,18 @@ * @precision very-high * @id py/similar-function */ + import python import CodeDuplication -predicate relevant(Function m) { - m.getMetrics().getNumberOfLinesOfCode() > 10 -} +predicate relevant(Function m) { m.getMetrics().getNumberOfLinesOfCode() > 10 } from Function m, Function other, string message, int percent -where similarScopes(m, other, percent, message) and +where + similarScopes(m, other, percent, message) and relevant(m) and percent > 95.0 and not duplicateScopes(m, other, _, _) and not duplicateScopes(m.getEnclosingModule(), other.getEnclosingModule(), _, _) and not duplicateScopes(m.getScope(), other.getScope(), _, _) -select m, message, - other, - other.getName() - - - +select m, message, other, other.getName() diff --git a/python/ql/test/2/library-tests/ControlFlow/Exceptions/Handles.ql b/python/ql/test/2/library-tests/ControlFlow/Exceptions/Handles.ql index f5279480573..620944de5b9 100644 --- a/python/ql/test/2/library-tests/ControlFlow/Exceptions/Handles.ql +++ b/python/ql/test/2/library-tests/ControlFlow/Exceptions/Handles.ql @@ -1,6 +1,5 @@ - import python from ExceptFlowNode ex, Value val where ex.handledException(val, _, _) -select ex.getLocation().getStartLine(), ex.toString(), val.toString() \ No newline at end of file +select ex.getLocation().getStartLine(), ex.toString(), val.toString() diff --git a/python/ql/test/2/library-tests/ControlFlow/Exceptions/Known.ql b/python/ql/test/2/library-tests/ControlFlow/Exceptions/Known.ql index 6fe92327f62..56498054f51 100644 --- a/python/ql/test/2/library-tests/ControlFlow/Exceptions/Known.ql +++ b/python/ql/test/2/library-tests/ControlFlow/Exceptions/Known.ql @@ -1,5 +1,4 @@ - import python from RaisingNode r -select r.getLocation().getStartLine(), r.toString(), r.getARaisedType().toString() \ No newline at end of file +select r.getLocation().getStartLine(), r.toString(), r.getARaisedType().toString() diff --git a/python/ql/test/2/library-tests/ControlFlow/Exceptions/Likely.ql b/python/ql/test/2/library-tests/ControlFlow/Exceptions/Likely.ql index d23a5efe2f4..80831a9ca54 100644 --- a/python/ql/test/2/library-tests/ControlFlow/Exceptions/Likely.ql +++ b/python/ql/test/2/library-tests/ControlFlow/Exceptions/Likely.ql @@ -1,7 +1,7 @@ - import python from ControlFlowNode r, ControlFlowNode s -where s = r.getAnExceptionalSuccessor() and -not r.(RaisingNode).unlikelySuccessor(s) -select r.getLocation().getStartLine(), r.toString(), s.getLocation().getStartLine(), s.toString() \ No newline at end of file +where + s = r.getAnExceptionalSuccessor() and + not r.(RaisingNode).unlikelySuccessor(s) +select r.getLocation().getStartLine(), r.toString(), s.getLocation().getStartLine(), s.toString() diff --git a/python/ql/test/2/library-tests/ControlFlow/Exceptions/Unknown.ql b/python/ql/test/2/library-tests/ControlFlow/Exceptions/Unknown.ql index d8db11d9f1b..29bad86bf0f 100644 --- a/python/ql/test/2/library-tests/ControlFlow/Exceptions/Unknown.ql +++ b/python/ql/test/2/library-tests/ControlFlow/Exceptions/Unknown.ql @@ -1,6 +1,5 @@ - import python from RaisingNode r where r.raisesUnknownType() -select r.getLocation().getStartLine(), r.toString() \ No newline at end of file +select r.getLocation().getStartLine(), r.toString() diff --git a/python/ql/test/2/library-tests/PointsTo/import_time/Pruned.ql b/python/ql/test/2/library-tests/PointsTo/import_time/Pruned.ql index a10b6bef24a..94a1db9b83d 100644 --- a/python/ql/test/2/library-tests/PointsTo/import_time/Pruned.ql +++ b/python/ql/test/2/library-tests/PointsTo/import_time/Pruned.ql @@ -1,11 +1,12 @@ - import python import semmle.python.pointsto.PointsTo import semmle.python.pointsto.PointsToContext from ControlFlowNode f, Location l, Context c - -where not PointsToInternal::reachableBlock(f.getBasicBlock(), c) and c.isImport() and -(f.getNode() instanceof FunctionExpr or f.getNode() instanceof ClassExpr) and -l = f.getLocation() and l.getFile().getShortName() = "test.py" +where + not PointsToInternal::reachableBlock(f.getBasicBlock(), c) and + c.isImport() and + (f.getNode() instanceof FunctionExpr or f.getNode() instanceof ClassExpr) and + l = f.getLocation() and + l.getFile().getShortName() = "test.py" select l.getStartLine() diff --git a/python/ql/test/2/library-tests/PointsTo/imports/Runtime.ql b/python/ql/test/2/library-tests/PointsTo/imports/Runtime.ql index 25097057d07..44a35b27b27 100644 --- a/python/ql/test/2/library-tests/PointsTo/imports/Runtime.ql +++ b/python/ql/test/2/library-tests/PointsTo/imports/Runtime.ql @@ -1,9 +1,10 @@ - import python from int line, ControlFlowNode f, Object o, ControlFlowNode orig -where - not f.getLocation().getFile().inStdlib() and - f.refersTo(o, orig) and line = f.getLocation().getStartLine() and line != 0 and - not o instanceof NumericObject // Omit sys.hexversion as it will change between machines +where + not f.getLocation().getFile().inStdlib() and + f.refersTo(o, orig) and + line = f.getLocation().getStartLine() and + line != 0 and + not o instanceof NumericObject // Omit sys.hexversion as it will change between machines select f.getLocation().getFile().getShortName(), line, f.toString(), o.toString(), orig.toString() diff --git a/python/ql/test/2/library-tests/PointsTo/metaclass/test.ql b/python/ql/test/2/library-tests/PointsTo/metaclass/test.ql index b658eb84474..68eec976105 100644 --- a/python/ql/test/2/library-tests/PointsTo/metaclass/test.ql +++ b/python/ql/test/2/library-tests/PointsTo/metaclass/test.ql @@ -1,4 +1,3 @@ - import python from ClassObject cls diff --git a/python/ql/test/2/library-tests/PointsTo/origin_uniqueness/Origin.ql b/python/ql/test/2/library-tests/PointsTo/origin_uniqueness/Origin.ql index 70ef57c16c2..6cd800ac399 100644 --- a/python/ql/test/2/library-tests/PointsTo/origin_uniqueness/Origin.ql +++ b/python/ql/test/2/library-tests/PointsTo/origin_uniqueness/Origin.ql @@ -1,14 +1,11 @@ import python -string short_loc(Location l) { - result = l.getFile().getShortName() + ":" + l.getStartLine() -} +string short_loc(Location l) { result = l.getFile().getShortName() + ":" + l.getStartLine() } from ControlFlowNode use, Object obj, ControlFlowNode orig, int line - -where use.refersTo(obj, orig) and -use.getLocation().getFile().getShortName() = "test.py" and -line = use.getLocation().getStartLine() and -not line = 0 - +where + use.refersTo(obj, orig) and + use.getLocation().getFile().getShortName() = "test.py" and + line = use.getLocation().getStartLine() and + not line = 0 select line, use.toString(), obj.toString(), short_loc(orig.getLocation()) diff --git a/python/ql/test/2/library-tests/classes/attr/class_attr.ql b/python/ql/test/2/library-tests/classes/attr/class_attr.ql index 0b283debd5d..3b7bf8b3ba0 100644 --- a/python/ql/test/2/library-tests/classes/attr/class_attr.ql +++ b/python/ql/test/2/library-tests/classes/attr/class_attr.ql @@ -7,7 +7,9 @@ import python from ClassObject cls, int line, string name, Object obj -where cls.hasLocationInfo(_, line, _, _, _) -and obj = cls.lookupAttribute(name) and -not cls.isC() and not name.matches("\\_\\_%\\_\\_") -select line, cls.toString(), name, obj.toString() \ No newline at end of file +where + cls.hasLocationInfo(_, line, _, _, _) and + obj = cls.lookupAttribute(name) and + not cls.isC() and + not name.matches("\\_\\_%\\_\\_") +select line, cls.toString(), name, obj.toString() diff --git a/python/ql/test/2/library-tests/classes/attr/class_has_attr.ql b/python/ql/test/2/library-tests/classes/attr/class_has_attr.ql index a274a1dd95b..2f16aa4ca97 100644 --- a/python/ql/test/2/library-tests/classes/attr/class_has_attr.ql +++ b/python/ql/test/2/library-tests/classes/attr/class_has_attr.ql @@ -7,7 +7,9 @@ import python from ClassObject cls, int line, string name -where cls.hasLocationInfo(_, line, _, _, _) -and cls.hasAttribute(name) and -not cls.isC() and not name.matches("\\_\\_%\\_\\_") +where + cls.hasLocationInfo(_, line, _, _, _) and + cls.hasAttribute(name) and + not cls.isC() and + not name.matches("\\_\\_%\\_\\_") select line, cls.toString(), name diff --git a/python/ql/test/2/library-tests/classes/attr/list_attr.ql b/python/ql/test/2/library-tests/classes/attr/list_attr.ql index 2977030252a..aad2d9489c3 100644 --- a/python/ql/test/2/library-tests/classes/attr/list_attr.ql +++ b/python/ql/test/2/library-tests/classes/attr/list_attr.ql @@ -7,10 +7,10 @@ import python from ClassObject cls, string name, Object what -where -(cls.getName() = "list" or - cls.getASuperType().getName() = "list" -) -and -cls.lookupAttribute(name) = what +where + ( + cls.getName() = "list" or + cls.getASuperType().getName() = "list" + ) and + cls.lookupAttribute(name) = what select cls.toString(), name, what.toString() diff --git a/python/ql/test/2/library-tests/classes/mro/C3.ql b/python/ql/test/2/library-tests/classes/mro/C3.ql index d04f49af51c..c4b0dd896d6 100644 --- a/python/ql/test/2/library-tests/classes/mro/C3.ql +++ b/python/ql/test/2/library-tests/classes/mro/C3.ql @@ -1,18 +1,12 @@ - import python import semmle.python.pointsto.MRO import semmle.python.pointsto.PointsTo import semmle.python.objects.ObjectInternal ClassList mro(ClassObjectInternal cls) { - if Types::isNewStyle(cls) then - result = Mro::newStyleMro(cls) - else - result = Mro::oldStyleMro(cls) + if Types::isNewStyle(cls) then result = Mro::newStyleMro(cls) else result = Mro::oldStyleMro(cls) } from ClassObjectInternal cls where not cls.isBuiltin() - select cls.toString(), mro(cls) - diff --git a/python/ql/test/2/library-tests/classes/mro/mro.ql b/python/ql/test/2/library-tests/classes/mro/mro.ql index 0695e6ce5b8..122d31c4a9b 100644 --- a/python/ql/test/2/library-tests/classes/mro/mro.ql +++ b/python/ql/test/2/library-tests/classes/mro/mro.ql @@ -1,8 +1,7 @@ - - import python from ClassObject cls, ClassObject l, ClassObject r -where not cls.isC() and -r = cls.nextInMro(l) +where + not cls.isC() and + r = cls.nextInMro(l) select cls.toString(), l.toString(), r.toString() diff --git a/python/ql/test/2/library-tests/comprehensions/SanityCheck.ql b/python/ql/test/2/library-tests/comprehensions/SanityCheck.ql index 29dc596401c..475505620f4 100644 --- a/python/ql/test/2/library-tests/comprehensions/SanityCheck.ql +++ b/python/ql/test/2/library-tests/comprehensions/SanityCheck.ql @@ -4,4 +4,6 @@ import python - select count(Comprehension c | count(c.toString()) != 1 or count(c.getLocation()) != 1 or not exists(c.getAFlowNode())) +select count(Comprehension c | + count(c.toString()) != 1 or count(c.getLocation()) != 1 or not exists(c.getAFlowNode()) + ) diff --git a/python/ql/test/2/library-tests/locations/general/AllLocations.ql b/python/ql/test/2/library-tests/locations/general/AllLocations.ql index 981d4560d87..9e6fcb00a05 100644 --- a/python/ql/test/2/library-tests/locations/general/AllLocations.ql +++ b/python/ql/test/2/library-tests/locations/general/AllLocations.ql @@ -9,8 +9,7 @@ import python from string classname where -exists(AstNode node | not exists(node.getLocation()) and classname = node.getAQlClass()) -or -exists(ControlFlowNode node | not exists(node.getLocation()) and classname = node.getAQlClass()) - + exists(AstNode node | not exists(node.getLocation()) and classname = node.getAQlClass()) + or + exists(ControlFlowNode node | not exists(node.getLocation()) and classname = node.getAQlClass()) select classname diff --git a/python/ql/test/2/library-tests/locations/general/Locations.ql b/python/ql/test/2/library-tests/locations/general/Locations.ql index 874eecbdb9f..b2e7f4b164d 100644 --- a/python/ql/test/2/library-tests/locations/general/Locations.ql +++ b/python/ql/test/2/library-tests/locations/general/Locations.ql @@ -1,6 +1,5 @@ import python - from AstNode ast, Location l where ast.getLocation() = l -select ast.getAQlClass(), l.getStartLine(), l.getStartColumn(), l.getEndLine(), l.getEndColumn() \ No newline at end of file +select ast.getAQlClass(), l.getStartLine(), l.getStartColumn(), l.getEndLine(), l.getEndColumn() diff --git a/python/ql/test/2/library-tests/locations/general/Prefix.ql b/python/ql/test/2/library-tests/locations/general/Prefix.ql index ad608f84cc2..bee9e555cc6 100644 --- a/python/ql/test/2/library-tests/locations/general/Prefix.ql +++ b/python/ql/test/2/library-tests/locations/general/Prefix.ql @@ -1,5 +1,4 @@ import python - -from StrConst s -select s.getLocation().getStartLine(), s.getText(), s.getPrefix() \ No newline at end of file +from StrConst s +select s.getLocation().getStartLine(), s.getText(), s.getPrefix() diff --git a/python/ql/test/2/library-tests/locations/keywords/Locations.ql b/python/ql/test/2/library-tests/locations/keywords/Locations.ql index b638ea81e14..afe685d0864 100644 --- a/python/ql/test/2/library-tests/locations/keywords/Locations.ql +++ b/python/ql/test/2/library-tests/locations/keywords/Locations.ql @@ -1,6 +1,5 @@ import python - from Keyword k, Location l where k.getLocation() = l -select l.getStartLine(), l.getStartColumn(), l.getEndLine(), l.getEndColumn() \ No newline at end of file +select l.getStartLine(), l.getStartColumn(), l.getEndLine(), l.getEndColumn() diff --git a/python/ql/test/2/library-tests/locations/strings/test.ql b/python/ql/test/2/library-tests/locations/strings/test.ql index 4a23a61d0da..be3052d9500 100644 --- a/python/ql/test/2/library-tests/locations/strings/test.ql +++ b/python/ql/test/2/library-tests/locations/strings/test.ql @@ -2,4 +2,4 @@ import python from StrConst s, int bl, int bc, int el, int ec where s.getLocation().hasLocationInfo(_, bl, bc, el, ec) -select bl, bc, el, ec, s.getText() \ No newline at end of file +select bl, bc, el, ec, s.getText() diff --git a/python/ql/test/2/library-tests/modules/general/import_test.ql b/python/ql/test/2/library-tests/modules/general/import_test.ql index 026dcf2c690..94f8c1447ca 100644 --- a/python/ql/test/2/library-tests/modules/general/import_test.ql +++ b/python/ql/test/2/library-tests/modules/general/import_test.ql @@ -1,7 +1,9 @@ import python from ImportExpr ie, string m, string t, string r -where m = ie.getImportedModuleName() and -(if ie.isTop() then t = "top" else t = "bottom") and -(if ie.isRelative() then r= "relative" else r = "absolute") -select ie.getScope().toString(), ie.getLocation().getStartLine(), ie.toString(), ie.getLevel(), t, r, m +where + m = ie.getImportedModuleName() and + (if ie.isTop() then t = "top" else t = "bottom") and + (if ie.isRelative() then r = "relative" else r = "absolute") +select ie.getScope().toString(), ie.getLocation().getStartLine(), ie.toString(), ie.getLevel(), t, + r, m diff --git a/python/ql/test/2/library-tests/modules/general/moduleobject_test.ql b/python/ql/test/2/library-tests/modules/general/moduleobject_test.ql index e3fde98513f..50f79a57aed 100644 --- a/python/ql/test/2/library-tests/modules/general/moduleobject_test.ql +++ b/python/ql/test/2/library-tests/modules/general/moduleobject_test.ql @@ -1,4 +1,3 @@ - import python from ModuleObject m, string name diff --git a/python/ql/test/2/library-tests/modules/package_members/module_import_as.ql b/python/ql/test/2/library-tests/modules/package_members/module_import_as.ql index 9109fcb98a8..50ded7b4124 100644 --- a/python/ql/test/2/library-tests/modules/package_members/module_import_as.ql +++ b/python/ql/test/2/library-tests/modules/package_members/module_import_as.ql @@ -2,4 +2,4 @@ import python from ModuleObject m, string name where not m.isC() and m.importedAs(name) -select m.toString(), name \ No newline at end of file +select m.toString(), name diff --git a/python/ql/test/2/library-tests/objects/Literals.ql b/python/ql/test/2/library-tests/objects/Literals.ql index f83f4e722da..ad6e1181cfd 100644 --- a/python/ql/test/2/library-tests/objects/Literals.ql +++ b/python/ql/test/2/library-tests/objects/Literals.ql @@ -1,8 +1,6 @@ - /* Test that there are no literals that do not have a corresponding object. */ import python - string repr(Expr e) { result = e.(Num).getN() or result = e.(Bytes).getS() or @@ -10,7 +8,5 @@ string repr(Expr e) { } from ImmutableLiteral l -where -not exists(l.getLiteralObject()) - -select l.getLocation().getStartLine(), repr(l) \ No newline at end of file +where not exists(l.getLiteralObject()) +select l.getLocation().getStartLine(), repr(l) diff --git a/python/ql/test/2/library-tests/types/classes/mro_test.ql b/python/ql/test/2/library-tests/types/classes/mro_test.ql index 181c8205289..fa2ac44d4d2 100644 --- a/python/ql/test/2/library-tests/types/classes/mro_test.ql +++ b/python/ql/test/2/library-tests/types/classes/mro_test.ql @@ -1,7 +1,5 @@ - import python from ClassObject cls where not cls.isC() select cls.toString(), cls.getMro() - diff --git a/python/ql/test/2/library-tests/types/classes/new_style.ql b/python/ql/test/2/library-tests/types/classes/new_style.ql index 5c66eff3e60..a0cd38b9e62 100644 --- a/python/ql/test/2/library-tests/types/classes/new_style.ql +++ b/python/ql/test/2/library-tests/types/classes/new_style.ql @@ -1,13 +1,8 @@ - import python from ClassObject cls, string style -where not cls.isC() and -not cls.failedInference() and -( - if cls.isNewStyle() then - style = "new" - else - style = "old" -) +where + not cls.isC() and + not cls.failedInference() and + (if cls.isNewStyle() then style = "new" else style = "old") select cls.toString(), style diff --git a/python/ql/test/2/library-tests/types/exceptions/ExitRaises.ql b/python/ql/test/2/library-tests/types/exceptions/ExitRaises.ql index 33c6b003b99..8e4c47a3e74 100644 --- a/python/ql/test/2/library-tests/types/exceptions/ExitRaises.ql +++ b/python/ql/test/2/library-tests/types/exceptions/ExitRaises.ql @@ -2,5 +2,4 @@ import python from RaisingNode r, Scope s, ClassObject cls where r.viableExceptionalExit(s, cls) - select r.getLocation().getStartLine(), r.toString(), s.toString(), cls.toString() diff --git a/python/ql/test/2/library-tests/types/exceptions/Raises.ql b/python/ql/test/2/library-tests/types/exceptions/Raises.ql index b003fd03dfa..aa477f718a2 100644 --- a/python/ql/test/2/library-tests/types/exceptions/Raises.ql +++ b/python/ql/test/2/library-tests/types/exceptions/Raises.ql @@ -1,13 +1,12 @@ - import python from PyFunctionObject f, string type -where +where type = f.getARaisedType().toString() or type = "Unknown" and f.raisesUnknownType() or not exists(f.getARaisedType()) and - not f.raisesUnknownType() and type = "None" - -select f.toString(), type \ No newline at end of file + not f.raisesUnknownType() and + type = "None" +select f.toString(), type diff --git a/python/ql/test/2/library-tests/types/functions/Calls.ql b/python/ql/test/2/library-tests/types/functions/Calls.ql index 87ee8a1f9d2..6fc188753e5 100644 --- a/python/ql/test/2/library-tests/types/functions/Calls.ql +++ b/python/ql/test/2/library-tests/types/functions/Calls.ql @@ -1,4 +1,3 @@ - import python from FunctionObject func, ControlFlowNode call diff --git a/python/ql/test/2/library-tests/types/functions/Never.ql b/python/ql/test/2/library-tests/types/functions/Never.ql index 3dcf47ffd4d..1e43ead7dce 100644 --- a/python/ql/test/2/library-tests/types/functions/Never.ql +++ b/python/ql/test/2/library-tests/types/functions/Never.ql @@ -2,4 +2,4 @@ import python from FunctionObject func where func.neverReturns() -select func.getOrigin().getLocation().getStartLine(), func.getName() \ No newline at end of file +select func.getOrigin().getLocation().getStartLine(), func.getName() diff --git a/python/ql/test/2/library-tests/types/functions/ReturnTypes.ql b/python/ql/test/2/library-tests/types/functions/ReturnTypes.ql index a200a947ab0..beb955e1188 100644 --- a/python/ql/test/2/library-tests/types/functions/ReturnTypes.ql +++ b/python/ql/test/2/library-tests/types/functions/ReturnTypes.ql @@ -1,7 +1,5 @@ - import python from PyFunctionObject func, ClassObject ret_type where func.getAnInferredReturnType() = ret_type - select func.getOrigin().getLocation().getStartLine(), func.getName(), ret_type.toString() diff --git a/python/ql/test/2/library-tests/types/properties/BuiltinProperties.ql b/python/ql/test/2/library-tests/types/properties/BuiltinProperties.ql index 7fd60f2e058..6ff0563e787 100644 --- a/python/ql/test/2/library-tests/types/properties/BuiltinProperties.ql +++ b/python/ql/test/2/library-tests/types/properties/BuiltinProperties.ql @@ -1,7 +1,8 @@ import python from ClassObject cls, string name, BuiltinPropertyObject p -where cls.declaredAttribute(name) = p and -(cls = theObjectType() or cls = theListType() or cls = theTypeType()) - -select cls.toString(), name, p.toString(), p.getGetter().toString(), p.getSetter().toString(), p.getDeleter().toString() +where + cls.declaredAttribute(name) = p and + (cls = theObjectType() or cls = theListType() or cls = theTypeType()) +select cls.toString(), name, p.toString(), p.getGetter().toString(), p.getSetter().toString(), + p.getDeleter().toString() diff --git a/python/ql/test/3/library-tests/ControlFlow/Exceptions/Handles.ql b/python/ql/test/3/library-tests/ControlFlow/Exceptions/Handles.ql index f5279480573..620944de5b9 100644 --- a/python/ql/test/3/library-tests/ControlFlow/Exceptions/Handles.ql +++ b/python/ql/test/3/library-tests/ControlFlow/Exceptions/Handles.ql @@ -1,6 +1,5 @@ - import python from ExceptFlowNode ex, Value val where ex.handledException(val, _, _) -select ex.getLocation().getStartLine(), ex.toString(), val.toString() \ No newline at end of file +select ex.getLocation().getStartLine(), ex.toString(), val.toString() diff --git a/python/ql/test/3/library-tests/ControlFlow/Exceptions/Known.ql b/python/ql/test/3/library-tests/ControlFlow/Exceptions/Known.ql index 6fe92327f62..56498054f51 100644 --- a/python/ql/test/3/library-tests/ControlFlow/Exceptions/Known.ql +++ b/python/ql/test/3/library-tests/ControlFlow/Exceptions/Known.ql @@ -1,5 +1,4 @@ - import python from RaisingNode r -select r.getLocation().getStartLine(), r.toString(), r.getARaisedType().toString() \ No newline at end of file +select r.getLocation().getStartLine(), r.toString(), r.getARaisedType().toString() diff --git a/python/ql/test/3/library-tests/ControlFlow/Exceptions/Likely.ql b/python/ql/test/3/library-tests/ControlFlow/Exceptions/Likely.ql index d23a5efe2f4..80831a9ca54 100644 --- a/python/ql/test/3/library-tests/ControlFlow/Exceptions/Likely.ql +++ b/python/ql/test/3/library-tests/ControlFlow/Exceptions/Likely.ql @@ -1,7 +1,7 @@ - import python from ControlFlowNode r, ControlFlowNode s -where s = r.getAnExceptionalSuccessor() and -not r.(RaisingNode).unlikelySuccessor(s) -select r.getLocation().getStartLine(), r.toString(), s.getLocation().getStartLine(), s.toString() \ No newline at end of file +where + s = r.getAnExceptionalSuccessor() and + not r.(RaisingNode).unlikelySuccessor(s) +select r.getLocation().getStartLine(), r.toString(), s.getLocation().getStartLine(), s.toString() diff --git a/python/ql/test/3/library-tests/ControlFlow/Exceptions/Unknown.ql b/python/ql/test/3/library-tests/ControlFlow/Exceptions/Unknown.ql index d8db11d9f1b..29bad86bf0f 100644 --- a/python/ql/test/3/library-tests/ControlFlow/Exceptions/Unknown.ql +++ b/python/ql/test/3/library-tests/ControlFlow/Exceptions/Unknown.ql @@ -1,6 +1,5 @@ - import python from RaisingNode r where r.raisesUnknownType() -select r.getLocation().getStartLine(), r.toString() \ No newline at end of file +select r.getLocation().getStartLine(), r.toString() diff --git a/python/ql/test/3/library-tests/PointsTo/attributes/Test.ql b/python/ql/test/3/library-tests/PointsTo/attributes/Test.ql index 575d347fc10..cc191d7c7d8 100644 --- a/python/ql/test/3/library-tests/PointsTo/attributes/Test.ql +++ b/python/ql/test/3/library-tests/PointsTo/attributes/Test.ql @@ -1,7 +1,5 @@ import python from ControlFlowNode f, Object o, ControlFlowNode x - where f.refersTo(o, x) - select f.getLocation().getStartLine(), f.toString(), o.toString(), x.getLocation().getStartLine() diff --git a/python/ql/test/3/library-tests/PointsTo/attributes/TestWithType.ql b/python/ql/test/3/library-tests/PointsTo/attributes/TestWithType.ql index 47b1cbc5434..0c6149c38b1 100644 --- a/python/ql/test/3/library-tests/PointsTo/attributes/TestWithType.ql +++ b/python/ql/test/3/library-tests/PointsTo/attributes/TestWithType.ql @@ -1,7 +1,6 @@ import python from ControlFlowNode f, Object o, ClassObject c, ControlFlowNode x - where f.refersTo(o, c, x) - -select f.getLocation().getStartLine(), f.toString(), o.toString(), c.toString(), x.getLocation().getStartLine() +select f.getLocation().getStartLine(), f.toString(), o.toString(), c.toString(), + x.getLocation().getStartLine() diff --git a/python/ql/test/3/library-tests/PointsTo/consts/BooleanConstants.ql b/python/ql/test/3/library-tests/PointsTo/consts/BooleanConstants.ql index a4543881042..6215714a25e 100644 --- a/python/ql/test/3/library-tests/PointsTo/consts/BooleanConstants.ql +++ b/python/ql/test/3/library-tests/PointsTo/consts/BooleanConstants.ql @@ -2,13 +2,8 @@ import python import semmle.python.pointsto.PointsTo from ControlFlowNode f, Context c, boolean b - -where -exists(Object obj | - PointsTo::points_to(f, c, obj, _, _) and obj.booleanValue() = b -) and -not exists(Object obj | - PointsTo::points_to(f, c, obj, _, _) and not obj.booleanValue() = b -) - -select f.getLocation().getFile().getShortName(), f.getLocation().getStartLine(), f.toString(), c.toString(), b +where + exists(Object obj | PointsTo::points_to(f, c, obj, _, _) and obj.booleanValue() = b) and + not exists(Object obj | PointsTo::points_to(f, c, obj, _, _) and not obj.booleanValue() = b) +select f.getLocation().getFile().getShortName(), f.getLocation().getStartLine(), f.toString(), + c.toString(), b diff --git a/python/ql/test/3/library-tests/PointsTo/import_time/Pruned.ql b/python/ql/test/3/library-tests/PointsTo/import_time/Pruned.ql index 844992f663e..d07dc65c34f 100644 --- a/python/ql/test/3/library-tests/PointsTo/import_time/Pruned.ql +++ b/python/ql/test/3/library-tests/PointsTo/import_time/Pruned.ql @@ -1,7 +1,9 @@ - import python import semmle.python.pointsto.PointsTo from ControlFlowNode f, Location l -where not PointsToInternal::reachableBlock(f.getBasicBlock(), _) and l = f.getLocation() and l.getFile().getShortName() = "test.py" +where + not PointsToInternal::reachableBlock(f.getBasicBlock(), _) and + l = f.getLocation() and + l.getFile().getShortName() = "test.py" select l.getStartLine() diff --git a/python/ql/test/3/library-tests/PointsTo/inheritance/Calls.ql b/python/ql/test/3/library-tests/PointsTo/inheritance/Calls.ql index d35ac04bb30..f91d207fc70 100644 --- a/python/ql/test/3/library-tests/PointsTo/inheritance/Calls.ql +++ b/python/ql/test/3/library-tests/PointsTo/inheritance/Calls.ql @@ -1,8 +1,5 @@ - import python from Call c, FunctionObject f - where f.getACall().getNode() = c - select c.getLocation().getStartLine(), f.toString(), f.getFunction().getLocation().getStartLine() diff --git a/python/ql/test/3/library-tests/PointsTo/metaclass/test.ql b/python/ql/test/3/library-tests/PointsTo/metaclass/test.ql index b658eb84474..68eec976105 100644 --- a/python/ql/test/3/library-tests/PointsTo/metaclass/test.ql +++ b/python/ql/test/3/library-tests/PointsTo/metaclass/test.ql @@ -1,4 +1,3 @@ - import python from ClassObject cls diff --git a/python/ql/test/3/library-tests/PointsTo/regressions/subprocess-assert/ClassValue.ql b/python/ql/test/3/library-tests/PointsTo/regressions/subprocess-assert/ClassValue.ql index b6f1ce2da98..e21a864b8bb 100644 --- a/python/ql/test/3/library-tests/PointsTo/regressions/subprocess-assert/ClassValue.ql +++ b/python/ql/test/3/library-tests/PointsTo/regressions/subprocess-assert/ClassValue.ql @@ -1,10 +1,11 @@ import python // as used in semmle.python.filters.Tests - from ClassValue c, string base where c.getScope().getLocation().getFile().getShortName().matches("mwe%.py") and c.getName() = "MyTest" and - if exists(c.getABaseType()) then base = c.getABaseType().toString() else base = "" + if exists(c.getABaseType()) + then base = c.getABaseType().toString() + else base = "" select c, base diff --git a/python/ql/test/3/library-tests/PointsTo/typehints/Values.ql b/python/ql/test/3/library-tests/PointsTo/typehints/Values.ql index d8e877aa437..8716d38f086 100644 --- a/python/ql/test/3/library-tests/PointsTo/typehints/Values.ql +++ b/python/ql/test/3/library-tests/PointsTo/typehints/Values.ql @@ -1,8 +1,7 @@ - import python from ControlFlowNode f, Context ctx, Value v, ControlFlowNode origin where - f.pointsTo(ctx, v, origin) and - f.getLocation().getFile().getBaseName() = "test.py" + f.pointsTo(ctx, v, origin) and + f.getLocation().getFile().getBaseName() = "test.py" select f.getLocation(), f.toString(), ctx, v diff --git a/python/ql/test/3/library-tests/classes/attr/class_attr.ql b/python/ql/test/3/library-tests/classes/attr/class_attr.ql index 0b283debd5d..3b7bf8b3ba0 100644 --- a/python/ql/test/3/library-tests/classes/attr/class_attr.ql +++ b/python/ql/test/3/library-tests/classes/attr/class_attr.ql @@ -7,7 +7,9 @@ import python from ClassObject cls, int line, string name, Object obj -where cls.hasLocationInfo(_, line, _, _, _) -and obj = cls.lookupAttribute(name) and -not cls.isC() and not name.matches("\\_\\_%\\_\\_") -select line, cls.toString(), name, obj.toString() \ No newline at end of file +where + cls.hasLocationInfo(_, line, _, _, _) and + obj = cls.lookupAttribute(name) and + not cls.isC() and + not name.matches("\\_\\_%\\_\\_") +select line, cls.toString(), name, obj.toString() diff --git a/python/ql/test/3/library-tests/classes/attr/class_has_attr.ql b/python/ql/test/3/library-tests/classes/attr/class_has_attr.ql index a274a1dd95b..2f16aa4ca97 100644 --- a/python/ql/test/3/library-tests/classes/attr/class_has_attr.ql +++ b/python/ql/test/3/library-tests/classes/attr/class_has_attr.ql @@ -7,7 +7,9 @@ import python from ClassObject cls, int line, string name -where cls.hasLocationInfo(_, line, _, _, _) -and cls.hasAttribute(name) and -not cls.isC() and not name.matches("\\_\\_%\\_\\_") +where + cls.hasLocationInfo(_, line, _, _, _) and + cls.hasAttribute(name) and + not cls.isC() and + not name.matches("\\_\\_%\\_\\_") select line, cls.toString(), name diff --git a/python/ql/test/3/library-tests/classes/meta/meta.ql b/python/ql/test/3/library-tests/classes/meta/meta.ql index c295fc330f2..96e26b3f060 100644 --- a/python/ql/test/3/library-tests/classes/meta/meta.ql +++ b/python/ql/test/3/library-tests/classes/meta/meta.ql @@ -1,4 +1,4 @@ import python from ClassExpr cls -select cls.toString(), cls.getMetaClass().toString() \ No newline at end of file +select cls.toString(), cls.getMetaClass().toString() diff --git a/python/ql/test/3/library-tests/classes/meta/meta_obj.ql b/python/ql/test/3/library-tests/classes/meta/meta_obj.ql index f4f91869069..e85127a9305 100644 --- a/python/ql/test/3/library-tests/classes/meta/meta_obj.ql +++ b/python/ql/test/3/library-tests/classes/meta/meta_obj.ql @@ -2,4 +2,4 @@ import python from ClassObject cls where not cls.isC() -select cls.toString(), cls.getAnInferredType().toString() \ No newline at end of file +select cls.toString(), cls.getAnInferredType().toString() diff --git a/python/ql/test/3/library-tests/classes/mro/mro.ql b/python/ql/test/3/library-tests/classes/mro/mro.ql index 87f7e35c7bc..2c710a18eeb 100644 --- a/python/ql/test/3/library-tests/classes/mro/mro.ql +++ b/python/ql/test/3/library-tests/classes/mro/mro.ql @@ -7,6 +7,7 @@ import python from ClassObject cls, ClassObject l, ClassObject r -where not cls.isC() and -r = cls.nextInMro(l) +where + not cls.isC() and + r = cls.nextInMro(l) select cls.toString(), l.toString(), r.toString() diff --git a/python/ql/test/3/library-tests/classes/mro/mro_index.ql b/python/ql/test/3/library-tests/classes/mro/mro_index.ql index f8398bcb737..641667e28f1 100644 --- a/python/ql/test/3/library-tests/classes/mro/mro_index.ql +++ b/python/ql/test/3/library-tests/classes/mro/mro_index.ql @@ -7,6 +7,7 @@ import python from ClassObject cls, ClassObject sup, int index -where sup = cls.getMroItem(index) and -not cls.isC() +where + sup = cls.getMroItem(index) and + not cls.isC() select cls.toString(), index, sup.toString() diff --git a/python/ql/test/3/library-tests/locations/annotations/Locations.ql b/python/ql/test/3/library-tests/locations/annotations/Locations.ql index 66428d5e8ad..211f6ee47df 100644 --- a/python/ql/test/3/library-tests/locations/annotations/Locations.ql +++ b/python/ql/test/3/library-tests/locations/annotations/Locations.ql @@ -1,6 +1,5 @@ import python - from AstNode a, Location l where a.getLocation() = l -select l.getStartLine(), l.getStartColumn(), l.getEndLine(), l.getEndColumn(), a.toString() \ No newline at end of file +select l.getStartLine(), l.getStartColumn(), l.getEndLine(), l.getEndColumn(), a.toString() diff --git a/python/ql/test/3/library-tests/locations/general/AllLocations.ql b/python/ql/test/3/library-tests/locations/general/AllLocations.ql index 981d4560d87..9e6fcb00a05 100644 --- a/python/ql/test/3/library-tests/locations/general/AllLocations.ql +++ b/python/ql/test/3/library-tests/locations/general/AllLocations.ql @@ -9,8 +9,7 @@ import python from string classname where -exists(AstNode node | not exists(node.getLocation()) and classname = node.getAQlClass()) -or -exists(ControlFlowNode node | not exists(node.getLocation()) and classname = node.getAQlClass()) - + exists(AstNode node | not exists(node.getLocation()) and classname = node.getAQlClass()) + or + exists(ControlFlowNode node | not exists(node.getLocation()) and classname = node.getAQlClass()) select classname diff --git a/python/ql/test/3/library-tests/locations/general/Locations.ql b/python/ql/test/3/library-tests/locations/general/Locations.ql index 874eecbdb9f..b2e7f4b164d 100644 --- a/python/ql/test/3/library-tests/locations/general/Locations.ql +++ b/python/ql/test/3/library-tests/locations/general/Locations.ql @@ -1,6 +1,5 @@ import python - from AstNode ast, Location l where ast.getLocation() = l -select ast.getAQlClass(), l.getStartLine(), l.getStartColumn(), l.getEndLine(), l.getEndColumn() \ No newline at end of file +select ast.getAQlClass(), l.getStartLine(), l.getStartColumn(), l.getEndLine(), l.getEndColumn() diff --git a/python/ql/test/3/library-tests/locations/general/Prefix.ql b/python/ql/test/3/library-tests/locations/general/Prefix.ql index ad608f84cc2..bee9e555cc6 100644 --- a/python/ql/test/3/library-tests/locations/general/Prefix.ql +++ b/python/ql/test/3/library-tests/locations/general/Prefix.ql @@ -1,5 +1,4 @@ import python - -from StrConst s -select s.getLocation().getStartLine(), s.getText(), s.getPrefix() \ No newline at end of file +from StrConst s +select s.getLocation().getStartLine(), s.getText(), s.getPrefix() diff --git a/python/ql/test/3/library-tests/locations/keywords/Locations.ql b/python/ql/test/3/library-tests/locations/keywords/Locations.ql index b638ea81e14..afe685d0864 100644 --- a/python/ql/test/3/library-tests/locations/keywords/Locations.ql +++ b/python/ql/test/3/library-tests/locations/keywords/Locations.ql @@ -1,6 +1,5 @@ import python - from Keyword k, Location l where k.getLocation() = l -select l.getStartLine(), l.getStartColumn(), l.getEndLine(), l.getEndColumn() \ No newline at end of file +select l.getStartLine(), l.getStartColumn(), l.getEndLine(), l.getEndColumn() diff --git a/python/ql/test/3/library-tests/modules/general/import_test.ql b/python/ql/test/3/library-tests/modules/general/import_test.ql index 026dcf2c690..94f8c1447ca 100644 --- a/python/ql/test/3/library-tests/modules/general/import_test.ql +++ b/python/ql/test/3/library-tests/modules/general/import_test.ql @@ -1,7 +1,9 @@ import python from ImportExpr ie, string m, string t, string r -where m = ie.getImportedModuleName() and -(if ie.isTop() then t = "top" else t = "bottom") and -(if ie.isRelative() then r= "relative" else r = "absolute") -select ie.getScope().toString(), ie.getLocation().getStartLine(), ie.toString(), ie.getLevel(), t, r, m +where + m = ie.getImportedModuleName() and + (if ie.isTop() then t = "top" else t = "bottom") and + (if ie.isRelative() then r = "relative" else r = "absolute") +select ie.getScope().toString(), ie.getLocation().getStartLine(), ie.toString(), ie.getLevel(), t, + r, m diff --git a/python/ql/test/3/library-tests/modules/general/moduleobject_test.ql b/python/ql/test/3/library-tests/modules/general/moduleobject_test.ql index 39c8aaab471..a3a1ac6b185 100644 --- a/python/ql/test/3/library-tests/modules/general/moduleobject_test.ql +++ b/python/ql/test/3/library-tests/modules/general/moduleobject_test.ql @@ -1,4 +1,3 @@ - import python from ModuleObject m, string name diff --git a/python/ql/test/3/library-tests/taint/unpacking/TestTaint.ql b/python/ql/test/3/library-tests/taint/unpacking/TestTaint.ql index 92657b1fef9..8347bd25433 100644 --- a/python/ql/test/3/library-tests/taint/unpacking/TestTaint.ql +++ b/python/ql/test/3/library-tests/taint/unpacking/TestTaint.ql @@ -15,4 +15,5 @@ where taint_string = tainted.getTaintKind().toString() ) ) -select arg.getLocation().toString(), call.getScope().(Function).getName(), arg.toString(), taint_string +select arg.getLocation().toString(), call.getScope().(Function).getName(), arg.toString(), + taint_string diff --git a/python/ql/test/3/library-tests/types/classes/mro_test.ql b/python/ql/test/3/library-tests/types/classes/mro_test.ql index cb067035076..04b65ae2bef 100644 --- a/python/ql/test/3/library-tests/types/classes/mro_test.ql +++ b/python/ql/test/3/library-tests/types/classes/mro_test.ql @@ -1,7 +1,5 @@ - import python from ClassObject cls, ClassObject sup where not cls.isC() select cls.toString(), sup.toString(), cls.nextInMro(sup).toString() - diff --git a/python/ql/test/3/library-tests/types/exceptions/Raises.ql b/python/ql/test/3/library-tests/types/exceptions/Raises.ql index b003fd03dfa..aa477f718a2 100644 --- a/python/ql/test/3/library-tests/types/exceptions/Raises.ql +++ b/python/ql/test/3/library-tests/types/exceptions/Raises.ql @@ -1,13 +1,12 @@ - import python from PyFunctionObject f, string type -where +where type = f.getARaisedType().toString() or type = "Unknown" and f.raisesUnknownType() or not exists(f.getARaisedType()) and - not f.raisesUnknownType() and type = "None" - -select f.toString(), type \ No newline at end of file + not f.raisesUnknownType() and + type = "None" +select f.toString(), type diff --git a/python/ql/test/3/library-tests/types/exceptions/Viable.ql b/python/ql/test/3/library-tests/types/exceptions/Viable.ql index 544b0a0d0b6..e28fa1a907c 100644 --- a/python/ql/test/3/library-tests/types/exceptions/Viable.ql +++ b/python/ql/test/3/library-tests/types/exceptions/Viable.ql @@ -1,7 +1,6 @@ - - import python from RaisingNode r, ControlFlowNode n, ClassObject ex where r.viableExceptionEdge(n, ex) -select r.getLocation().getStartLine(), n.getLocation().getStartLine(), r.getNode().toString(), n.getNode().toString(), ex.toString() +select r.getLocation().getStartLine(), n.getLocation().getStartLine(), r.getNode().toString(), + n.getNode().toString(), ex.toString() diff --git a/python/ql/test/3/library-tests/types/functions/Calls.ql b/python/ql/test/3/library-tests/types/functions/Calls.ql index 608ad79bdfb..6fc188753e5 100644 --- a/python/ql/test/3/library-tests/types/functions/Calls.ql +++ b/python/ql/test/3/library-tests/types/functions/Calls.ql @@ -1,7 +1,5 @@ - import python from FunctionObject func, ControlFlowNode call where func.getACall() = call select call.getLocation().getStartLine(), call.toString(), func.toString() - diff --git a/python/ql/test/3/library-tests/types/functions/Never.ql b/python/ql/test/3/library-tests/types/functions/Never.ql index 3dcf47ffd4d..1e43ead7dce 100644 --- a/python/ql/test/3/library-tests/types/functions/Never.ql +++ b/python/ql/test/3/library-tests/types/functions/Never.ql @@ -2,4 +2,4 @@ import python from FunctionObject func where func.neverReturns() -select func.getOrigin().getLocation().getStartLine(), func.getName() \ No newline at end of file +select func.getOrigin().getLocation().getStartLine(), func.getName() diff --git a/python/ql/test/3/library-tests/types/functions/ReturnTypes.ql b/python/ql/test/3/library-tests/types/functions/ReturnTypes.ql index a200a947ab0..beb955e1188 100644 --- a/python/ql/test/3/library-tests/types/functions/ReturnTypes.ql +++ b/python/ql/test/3/library-tests/types/functions/ReturnTypes.ql @@ -1,7 +1,5 @@ - import python from PyFunctionObject func, ClassObject ret_type where func.getAnInferredReturnType() = ret_type - select func.getOrigin().getLocation().getStartLine(), func.getName(), ret_type.toString() diff --git a/python/ql/test/3/library-tests/types/namespaces/NameSpace.ql b/python/ql/test/3/library-tests/types/namespaces/NameSpace.ql index 6997fd80635..4a35fae7e8b 100644 --- a/python/ql/test/3/library-tests/types/namespaces/NameSpace.ql +++ b/python/ql/test/3/library-tests/types/namespaces/NameSpace.ql @@ -8,17 +8,17 @@ import python from Scope s, string name, Object val -where name != "__name__" and -( - exists(ModuleObject m | - m.getModule() = s and - m.attributeRefersTo(name, val, _) - ) - or - exists(ClassObject cls | - cls.getPyClass() = s and - cls.declaredAttribute(name) = val - ) -) - -select s.toString(), name, val.toString() \ No newline at end of file +where + name != "__name__" and + ( + exists(ModuleObject m | + m.getModule() = s and + m.attributeRefersTo(name, val, _) + ) + or + exists(ClassObject cls | + cls.getPyClass() = s and + cls.declaredAttribute(name) = val + ) + ) +select s.toString(), name, val.toString() diff --git a/python/ql/test/3/library-tests/types/properties/BuiltinProperties.ql b/python/ql/test/3/library-tests/types/properties/BuiltinProperties.ql index 7fd60f2e058..6ff0563e787 100644 --- a/python/ql/test/3/library-tests/types/properties/BuiltinProperties.ql +++ b/python/ql/test/3/library-tests/types/properties/BuiltinProperties.ql @@ -1,7 +1,8 @@ import python from ClassObject cls, string name, BuiltinPropertyObject p -where cls.declaredAttribute(name) = p and -(cls = theObjectType() or cls = theListType() or cls = theTypeType()) - -select cls.toString(), name, p.toString(), p.getGetter().toString(), p.getSetter().toString(), p.getDeleter().toString() +where + cls.declaredAttribute(name) = p and + (cls = theObjectType() or cls = theListType() or cls = theTypeType()) +select cls.toString(), name, p.toString(), p.getGetter().toString(), p.getSetter().toString(), + p.getDeleter().toString() diff --git a/python/ql/test/library-tests/ControlFlow/PointsToSupport/UseFromDefinition.ql b/python/ql/test/library-tests/ControlFlow/PointsToSupport/UseFromDefinition.ql index 41efa249c31..54e7ed36333 100644 --- a/python/ql/test/library-tests/ControlFlow/PointsToSupport/UseFromDefinition.ql +++ b/python/ql/test/library-tests/ControlFlow/PointsToSupport/UseFromDefinition.ql @@ -1,17 +1,15 @@ - import python /*Find any Definition, assigned value pairs that 'valueForDefinition' misses */ - Expr assignedValue(Name n) { exists(Assign a | a.getATarget() = n and result = a.getValue()) or exists(Alias a | a.getAsname() = n and result = a.getValue()) } -from Name def, DefinitionNode d -where d = def.getAFlowNode() and - exists(assignedValue(def)) and - not d.getValue().getNode() = assignedValue(def) - -select def.toString(), assignedValue(def) \ No newline at end of file +from Name def, DefinitionNode d +where + d = def.getAFlowNode() and + exists(assignedValue(def)) and + not d.getValue().getNode() = assignedValue(def) +select def.toString(), assignedValue(def) diff --git a/python/ql/test/library-tests/ControlFlow/augassign/AugAssignFlow.ql b/python/ql/test/library-tests/ControlFlow/augassign/AugAssignFlow.ql index d356ea5de43..a4b98183c27 100644 --- a/python/ql/test/library-tests/ControlFlow/augassign/AugAssignFlow.ql +++ b/python/ql/test/library-tests/ControlFlow/augassign/AugAssignFlow.ql @@ -1,10 +1,10 @@ import python -int lineof(ControlFlowNode f) { - result = f.getNode().getLocation().getStartLine() -} +int lineof(ControlFlowNode f) { result = f.getNode().getLocation().getStartLine() } from ControlFlowNode defn, ControlFlowNode use -where defn.getNode() = use.getNode() -and defn.isStore() and use.isLoad() +where + defn.getNode() = use.getNode() and + defn.isStore() and + use.isLoad() select defn.toString(), use.toString(), lineof(defn) diff --git a/python/ql/test/library-tests/ControlFlow/augassign/Kind.ql b/python/ql/test/library-tests/ControlFlow/augassign/Kind.ql index 8ac3a4de0c1..c97f8446345 100644 --- a/python/ql/test/library-tests/ControlFlow/augassign/Kind.ql +++ b/python/ql/test/library-tests/ControlFlow/augassign/Kind.ql @@ -1,21 +1,16 @@ - import python string kind(ControlFlowNode f) { - if f.isAugLoad() then - result = "aug load" + if f.isAugLoad() + then result = "aug load" else ( - if f.isAugStore() then - result = "aug store" + if f.isAugStore() + then result = "aug store" else ( - if f.isLoad() then - result = "load" - else ( - f.isStore() and result = "store" - ) + if f.isLoad() then result = "load" else (f.isStore() and result = "store") ) - ) + ) } from ControlFlowNode cfg -select cfg.getLocation().getStartLine(), cfg, kind(cfg) \ No newline at end of file +select cfg.getLocation().getStartLine(), cfg, kind(cfg) diff --git a/python/ql/test/library-tests/ControlFlow/augassign/SSA.ql b/python/ql/test/library-tests/ControlFlow/augassign/SSA.ql index 7706226bcfa..0222099924b 100644 --- a/python/ql/test/library-tests/ControlFlow/augassign/SSA.ql +++ b/python/ql/test/library-tests/ControlFlow/augassign/SSA.ql @@ -7,7 +7,6 @@ import python - from ControlFlowNode defn, SsaVariable v, AugAssign a, BinaryExpr b -where v.getDefinition() = defn and a.getOperation() = b and b.contains((Expr)defn.getNode()) -select defn.toString(), defn.getNode().getLocation().getStartLine() \ No newline at end of file +where v.getDefinition() = defn and a.getOperation() = b and b.contains(defn.getNode().(Expr)) +select defn.toString(), defn.getNode().getLocation().getStartLine() diff --git a/python/ql/test/library-tests/ControlFlow/comparison/Compare.ql b/python/ql/test/library-tests/ControlFlow/comparison/Compare.ql index 5e66d239419..13e4736e6d9 100644 --- a/python/ql/test/library-tests/ControlFlow/comparison/Compare.ql +++ b/python/ql/test/library-tests/ControlFlow/comparison/Compare.ql @@ -8,10 +8,11 @@ import python from CompareNode c, NameNode l, NameNode r, Cmpop op, int line, Variable vl, Variable vr -where c.operands(l, op, r) and -line = c.getLocation().getStartLine() and -line = l.getLocation().getStartLine() and -line = r.getLocation().getStartLine() and -l.uses(vl) and r.uses(vr) +where + c.operands(l, op, r) and + line = c.getLocation().getStartLine() and + line = l.getLocation().getStartLine() and + line = r.getLocation().getStartLine() and + l.uses(vl) and + r.uses(vr) select line, c.toString(), vl.getId(), vr.getId(), op.getSymbol() - diff --git a/python/ql/test/library-tests/ControlFlow/delete/test.ql b/python/ql/test/library-tests/ControlFlow/delete/test.ql index 517733b70d6..2aaa45ea719 100644 --- a/python/ql/test/library-tests/ControlFlow/delete/test.ql +++ b/python/ql/test/library-tests/ControlFlow/delete/test.ql @@ -2,4 +2,5 @@ import python from ControlFlowNode p, ControlFlowNode s where p.getASuccessor() = s -select p.getLocation().getStartLine().toString(), p.toString(), s.getLocation().getStartLine(), s.toString() \ No newline at end of file +select p.getLocation().getStartLine().toString(), p.toString(), s.getLocation().getStartLine(), + s.toString() diff --git a/python/ql/test/library-tests/ControlFlow/dominators/DominatesSanity.ql b/python/ql/test/library-tests/ControlFlow/dominators/DominatesSanity.ql index cb53879e63b..d39328e44c7 100644 --- a/python/ql/test/library-tests/ControlFlow/dominators/DominatesSanity.ql +++ b/python/ql/test/library-tests/ControlFlow/dominators/DominatesSanity.ql @@ -1,9 +1,8 @@ - import python -select count(BasicBlock b1, BasicBlock b2 -| b1 = b2.getImmediateDominator+() and not b1.strictlyDominates(b2) -), -count(BasicBlock b1, BasicBlock b2 -| not b1 = b2.getImmediateDominator+() and b1.strictlyDominates(b2) -) +select count(BasicBlock b1, BasicBlock b2 | + b1 = b2.getImmediateDominator+() and not b1.strictlyDominates(b2) + ), + count(BasicBlock b1, BasicBlock b2 | + not b1 = b2.getImmediateDominator+() and b1.strictlyDominates(b2) + ) diff --git a/python/ql/test/library-tests/ControlFlow/dominators/idom.ql b/python/ql/test/library-tests/ControlFlow/dominators/idom.ql index 940624c6b20..cd948b6ff10 100644 --- a/python/ql/test/library-tests/ControlFlow/dominators/idom.ql +++ b/python/ql/test/library-tests/ControlFlow/dominators/idom.ql @@ -8,9 +8,8 @@ import python /* This query should *never* produce a result */ - from ControlFlowNode f -where not exists(f.getImmediateDominator()) -and not f.getNode() instanceof Scope +where + not exists(f.getImmediateDominator()) and + not f.getNode() instanceof Scope select f - diff --git a/python/ql/test/library-tests/ControlFlow/general/Comments.ql b/python/ql/test/library-tests/ControlFlow/general/Comments.ql index e93c8aae330..71d00f1a8d4 100644 --- a/python/ql/test/library-tests/ControlFlow/general/Comments.ql +++ b/python/ql/test/library-tests/ControlFlow/general/Comments.ql @@ -3,4 +3,3 @@ import python from Module m, int n where n = m.getMetrics().getNumberOfLinesOfComments() select m.toString(), n - diff --git a/python/ql/test/library-tests/ControlFlow/general/Cyclo.ql b/python/ql/test/library-tests/ControlFlow/general/Cyclo.ql index 6ca0327ab0b..fb801a29002 100644 --- a/python/ql/test/library-tests/ControlFlow/general/Cyclo.ql +++ b/python/ql/test/library-tests/ControlFlow/general/Cyclo.ql @@ -2,5 +2,3 @@ import python from Function func select func.toString(), func.getMetrics().getCyclomaticComplexity() - - diff --git a/python/ql/test/library-tests/ControlFlow/general/ImmediateDominatorCheck.ql b/python/ql/test/library-tests/ControlFlow/general/ImmediateDominatorCheck.ql index f038fd8d77a..66758604be2 100644 --- a/python/ql/test/library-tests/ControlFlow/general/ImmediateDominatorCheck.ql +++ b/python/ql/test/library-tests/ControlFlow/general/ImmediateDominatorCheck.ql @@ -1,16 +1,19 @@ - - import python -predicate -can_reach_from_entry_without_passing(ControlFlowNode target, ControlFlowNode pass) { - target != pass and target.getScope() = pass.getScope() and - (target.isEntryNode() or - exists(ControlFlowNode pre | target.getAPredecessor() = pre and can_reach_from_entry_without_passing(pre, pass))) +predicate can_reach_from_entry_without_passing(ControlFlowNode target, ControlFlowNode pass) { + target != pass and + target.getScope() = pass.getScope() and + ( + target.isEntryNode() + or + exists(ControlFlowNode pre | + target.getAPredecessor() = pre and can_reach_from_entry_without_passing(pre, pass) + ) + ) } from ControlFlowNode node, ControlFlowNode dom -where dom = node.getImmediateDominator() -and -can_reach_from_entry_without_passing(node, dom) +where + dom = node.getImmediateDominator() and + can_reach_from_entry_without_passing(node, dom) select node.toString(), dom.toString() diff --git a/python/ql/test/library-tests/ControlFlow/general/Lines.ql b/python/ql/test/library-tests/ControlFlow/general/Lines.ql index 60046ef3242..dabbe2bbf58 100644 --- a/python/ql/test/library-tests/ControlFlow/general/Lines.ql +++ b/python/ql/test/library-tests/ControlFlow/general/Lines.ql @@ -1,7 +1,8 @@ import python from Scope s, int n -where exists(Function f | f = s | n = f.getMetrics().getNumberOfLines()) or -exists(Module m | m = s | n = m.getMetrics().getNumberOfLines()) +where + exists(Function f | f = s | n = f.getMetrics().getNumberOfLines()) + or + exists(Module m | m = s | n = m.getMetrics().getNumberOfLines()) select s.toString(), n - diff --git a/python/ql/test/library-tests/ControlFlow/general/Reaches.ql b/python/ql/test/library-tests/ControlFlow/general/Reaches.ql index 548be578a76..3412e6a99bd 100644 --- a/python/ql/test/library-tests/ControlFlow/general/Reaches.ql +++ b/python/ql/test/library-tests/ControlFlow/general/Reaches.ql @@ -1,9 +1,8 @@ import python predicate reaches_exit(Name u) { - u.uses(_) and - exists(ControlFlowNode f, BasicBlock b | - f.getNode() = u and f.getBasicBlock() = b | + u.uses(_) and + exists(ControlFlowNode f, BasicBlock b | f.getNode() = u and f.getBasicBlock() = b | b.reachesExit() ) } diff --git a/python/ql/test/library-tests/ControlFlow/raising_stmts/RaisingFlow.ql b/python/ql/test/library-tests/ControlFlow/raising_stmts/RaisingFlow.ql index bfc884f7bac..35e43acaa12 100644 --- a/python/ql/test/library-tests/ControlFlow/raising_stmts/RaisingFlow.ql +++ b/python/ql/test/library-tests/ControlFlow/raising_stmts/RaisingFlow.ql @@ -6,12 +6,10 @@ import python from ControlFlowNode p, ControlFlowNode s, string kind -where p.getASuccessor() = s and -(if s = p.getAnExceptionalSuccessor() then - kind = "exception" - else - kind = " normal " -) and -not p.getNode() instanceof Scope and -not s.getNode() instanceof Scope -select p.getNode().getLocation().getStartLine(), p.toString(), kind, s.getNode().getLocation().getStartLine(), s +where + p.getASuccessor() = s and + (if s = p.getAnExceptionalSuccessor() then kind = "exception" else kind = " normal ") and + not p.getNode() instanceof Scope and + not s.getNode() instanceof Scope +select p.getNode().getLocation().getStartLine(), p.toString(), kind, + s.getNode().getLocation().getStartLine(), s diff --git a/python/ql/test/library-tests/ControlFlow/splitting/NodeCount.ql b/python/ql/test/library-tests/ControlFlow/splitting/NodeCount.ql index d9d5efbb494..c743952f2b1 100644 --- a/python/ql/test/library-tests/ControlFlow/splitting/NodeCount.ql +++ b/python/ql/test/library-tests/ControlFlow/splitting/NodeCount.ql @@ -1,8 +1,11 @@ import python from AstNode a, Scope s -where not a instanceof Import and not a instanceof If and not a instanceof AssignStmt and not a instanceof ExprStmt and -a.getScope() = s and -s instanceof Function -select -a.getLocation().getStartLine(), s.getName(), a, count(a.getAFlowNode()) +where + not a instanceof Import and + not a instanceof If and + not a instanceof AssignStmt and + not a instanceof ExprStmt and + a.getScope() = s and + s instanceof Function +select a.getLocation().getStartLine(), s.getName(), a, count(a.getAFlowNode()) diff --git a/python/ql/test/library-tests/ControlFlow/splitting/SuccessorCount.ql b/python/ql/test/library-tests/ControlFlow/splitting/SuccessorCount.ql index d865d9061c3..0941d2f2024 100644 --- a/python/ql/test/library-tests/ControlFlow/splitting/SuccessorCount.ql +++ b/python/ql/test/library-tests/ControlFlow/splitting/SuccessorCount.ql @@ -1,9 +1,8 @@ import python from ControlFlowNode p, Scope s -where -p.getScope() = s and -(exists (p.getATrueSuccessor()) or exists(p.getAFalseSuccessor())) and -s instanceof Function -select -p.getLocation().getStartLine(), s.getName(), p, strictcount(p.getASuccessor()) +where + p.getScope() = s and + (exists(p.getATrueSuccessor()) or exists(p.getAFalseSuccessor())) and + s instanceof Function +select p.getLocation().getStartLine(), s.getName(), p, strictcount(p.getASuccessor()) diff --git a/python/ql/test/library-tests/ControlFlow/ssa/defns/test.ql b/python/ql/test/library-tests/ControlFlow/ssa/defns/test.ql index c8ce2855455..d4cff3d6122 100644 --- a/python/ql/test/library-tests/ControlFlow/ssa/defns/test.ql +++ b/python/ql/test/library-tests/ControlFlow/ssa/defns/test.ql @@ -2,5 +2,5 @@ import python from SsaVariable var, SsaVariable def where def = var.getAnUltimateDefinition() -select var.getLocation().getFile().getShortName(), -var.toString(), var.getLocation().getStartLine(), def, def.getLocation().getStartLine() +select var.getLocation().getFile().getShortName(), var.toString(), var.getLocation().getStartLine(), + def, def.getLocation().getStartLine() diff --git a/python/ql/test/library-tests/ControlFlow/ssa/deletions/test.ql b/python/ql/test/library-tests/ControlFlow/ssa/deletions/test.ql index b220553d07b..feafac5a6c7 100644 --- a/python/ql/test/library-tests/ControlFlow/ssa/deletions/test.ql +++ b/python/ql/test/library-tests/ControlFlow/ssa/deletions/test.ql @@ -1,14 +1,13 @@ import python - from SsaVariable v, string kind, ControlFlowNode use, int line -where use = v.getAUse() and -( - kind = "delete" and v.getDefinition().isDelete() - or - kind = "other " and not v.getDefinition().isDelete() -) -and line = use.getLocation().getStartLine() -and line != 0 - +where + use = v.getAUse() and + ( + kind = "delete" and v.getDefinition().isDelete() + or + kind = "other " and not v.getDefinition().isDelete() + ) and + line = use.getLocation().getStartLine() and + line != 0 select line, use.toString(), v.getId(), kind diff --git a/python/ql/test/library-tests/ControlFlow/ssa/phi-nodes/phi_input_test.ql b/python/ql/test/library-tests/ControlFlow/ssa/phi-nodes/phi_input_test.ql index 5cfb210da24..fb2c8f20da8 100644 --- a/python/ql/test/library-tests/ControlFlow/ssa/phi-nodes/phi_input_test.ql +++ b/python/ql/test/library-tests/ControlFlow/ssa/phi-nodes/phi_input_test.ql @@ -2,6 +2,5 @@ import python from SsaVariable var, SsaVariable arg, BasicBlock pred where pred = var.getPredecessorBlockForPhiArgument(arg) -select var.getLocation().getFile().getShortName(), -var.toString(), var.getLocation().getStartLine(), arg, arg.getLocation().getStartLine(), pred.getLastNode().getLocation().getStartLine() - +select var.getLocation().getFile().getShortName(), var.toString(), var.getLocation().getStartLine(), + arg, arg.getLocation().getStartLine(), pred.getLastNode().getLocation().getStartLine() diff --git a/python/ql/test/library-tests/ControlFlow/ssa/phi-nodes/test.ql b/python/ql/test/library-tests/ControlFlow/ssa/phi-nodes/test.ql index 6c4f617e172..a8aef8cc72d 100644 --- a/python/ql/test/library-tests/ControlFlow/ssa/phi-nodes/test.ql +++ b/python/ql/test/library-tests/ControlFlow/ssa/phi-nodes/test.ql @@ -2,6 +2,5 @@ import python from SsaVariable var, SsaVariable arg where arg = var.getAPhiInput() -select var.getLocation().getFile().getShortName(), -var.toString(), var.getLocation().getStartLine(), arg, arg.getLocation().getStartLine() - +select var.getLocation().getFile().getShortName(), var.toString(), var.getLocation().getStartLine(), + arg, arg.getLocation().getStartLine() diff --git a/python/ql/test/library-tests/ControlFlow/ssa/undefined/test.ql b/python/ql/test/library-tests/ControlFlow/ssa/undefined/test.ql index df5df70d827..41b08ec0591 100644 --- a/python/ql/test/library-tests/ControlFlow/ssa/undefined/test.ql +++ b/python/ql/test/library-tests/ControlFlow/ssa/undefined/test.ql @@ -1,7 +1,5 @@ - import python from SsaVariable var where var.maybeUndefined() -select -var.getDefinition().getLocation().getStartLine(), var.toString() +select var.getDefinition().getLocation().getStartLine(), var.toString() diff --git a/python/ql/test/library-tests/ControlFlow/ssa/uses/test.ql b/python/ql/test/library-tests/ControlFlow/ssa/uses/test.ql index 9a3f4e92452..e120b6e1657 100644 --- a/python/ql/test/library-tests/ControlFlow/ssa/uses/test.ql +++ b/python/ql/test/library-tests/ControlFlow/ssa/uses/test.ql @@ -2,5 +2,5 @@ import python from ControlFlowNode use, SsaVariable def where def.getAUse() = use -select use.getLocation().getFile().getShortName(), -use.toString(), use.getLocation().getStartLine(), def.toString(), def.getLocation().getStartLine() +select use.getLocation().getFile().getShortName(), use.toString(), use.getLocation().getStartLine(), + def.toString(), def.getLocation().getStartLine() diff --git a/python/ql/test/library-tests/ControlFlow/ssa/vars/test.ql b/python/ql/test/library-tests/ControlFlow/ssa/vars/test.ql index 5e2dd530ad9..1892974be9b 100644 --- a/python/ql/test/library-tests/ControlFlow/ssa/vars/test.ql +++ b/python/ql/test/library-tests/ControlFlow/ssa/vars/test.ql @@ -1,7 +1,4 @@ import python from SsaVariable var - -select var.getLocation().getFile().getShortName(), -var, var.getLocation().getStartLine() - +select var.getLocation().getFile().getShortName(), var, var.getLocation().getStartLine() diff --git a/python/ql/test/library-tests/ControlFlow/successors/Successors.ql b/python/ql/test/library-tests/ControlFlow/successors/Successors.ql index 20567e057d1..802ed60962b 100644 --- a/python/ql/test/library-tests/ControlFlow/successors/Successors.ql +++ b/python/ql/test/library-tests/ControlFlow/successors/Successors.ql @@ -3,16 +3,15 @@ import semmle.python.TestUtils from ControlFlowNode p, ControlFlowNode s, string what where -s = p.getAFalseSuccessor() and what = "false" -or -s = p.getATrueSuccessor() and what = "true" -or -s = p.getAnExceptionalSuccessor() and what = "exceptional" -or -s = p.getANormalSuccessor() and what = "normal" -or -// Add fake edges for node that raise out of scope -p.isExceptionalExit(_) and s = p.getScope().getEntryNode() and what = "exit" - -select compact_location(p.getNode()), p.getNode().toString(), - compact_location(s.getNode()), s.getNode().toString(), what + s = p.getAFalseSuccessor() and what = "false" + or + s = p.getATrueSuccessor() and what = "true" + or + s = p.getAnExceptionalSuccessor() and what = "exceptional" + or + s = p.getANormalSuccessor() and what = "normal" + or + // Add fake edges for node that raise out of scope + p.isExceptionalExit(_) and s = p.getScope().getEntryNode() and what = "exit" +select compact_location(p.getNode()), p.getNode().toString(), compact_location(s.getNode()), + s.getNode().toString(), what diff --git a/python/ql/test/library-tests/ControlFlow/truefalse/ExceptionalSuccessors.ql b/python/ql/test/library-tests/ControlFlow/truefalse/ExceptionalSuccessors.ql index 163f57bcd06..352b1d2890d 100644 --- a/python/ql/test/library-tests/ControlFlow/truefalse/ExceptionalSuccessors.ql +++ b/python/ql/test/library-tests/ControlFlow/truefalse/ExceptionalSuccessors.ql @@ -9,8 +9,8 @@ import python from ControlFlowNode p, ControlFlowNode s where -s = p.getAnExceptionalSuccessor() -or -// Add fake edges for node that raise out of scope -p.isExceptionalExit(_) and s = p.getScope().getEntryNode() + s = p.getAnExceptionalSuccessor() + or + // Add fake edges for node that raise out of scope + p.isExceptionalExit(_) and s = p.getScope().getEntryNode() select p.getLocation().getFile().getShortName(), p.getLocation().getStartLine(), p, s.toString() diff --git a/python/ql/test/library-tests/ControlFlow/truefalse/TrueAndFalseSuccessor.ql b/python/ql/test/library-tests/ControlFlow/truefalse/TrueAndFalseSuccessor.ql index d5d8323a3a2..b2ca6cbd5ca 100644 --- a/python/ql/test/library-tests/ControlFlow/truefalse/TrueAndFalseSuccessor.ql +++ b/python/ql/test/library-tests/ControlFlow/truefalse/TrueAndFalseSuccessor.ql @@ -1,7 +1,5 @@ - - import python from ControlFlowNode f where f.getATrueSuccessor() = f.getAFalseSuccessor() -select f.toString() \ No newline at end of file +select f.toString() diff --git a/python/ql/test/library-tests/ControlFlow/truefalse/TrueFalseSuccessors.ql b/python/ql/test/library-tests/ControlFlow/truefalse/TrueFalseSuccessors.ql index 3320f06b8c7..1dedb90ea49 100644 --- a/python/ql/test/library-tests/ControlFlow/truefalse/TrueFalseSuccessors.ql +++ b/python/ql/test/library-tests/ControlFlow/truefalse/TrueFalseSuccessors.ql @@ -9,7 +9,8 @@ import python from ControlFlowNode p, ControlFlowNode s, string which where -s = p.getAFalseSuccessor() and which = "False" -or -s = p.getATrueSuccessor() and which = "True" -select p.getLocation().getFile().getShortName(), p.getLocation().getStartLine(), p, s.toString(), which + s = p.getAFalseSuccessor() and which = "False" + or + s = p.getATrueSuccessor() and which = "True" +select p.getLocation().getFile().getShortName(), p.getLocation().getStartLine(), p, s.toString(), + which diff --git a/python/ql/test/library-tests/ControlFlow/try/test_ssa.ql b/python/ql/test/library-tests/ControlFlow/try/test_ssa.ql index 8df422495fb..8ac7583b627 100644 --- a/python/ql/test/library-tests/ControlFlow/try/test_ssa.ql +++ b/python/ql/test/library-tests/ControlFlow/try/test_ssa.ql @@ -2,6 +2,5 @@ import python from SsaVariable var, ControlFlowNode use where use = var.getAUse() -select var.getLocation().getFile().getShortName(), -var.toString(), var.getLocation().getStartLine(), use.toString(), use.getLocation().getStartLine() - +select var.getLocation().getFile().getShortName(), var.toString(), var.getLocation().getStartLine(), + use.toString(), use.getLocation().getStartLine() diff --git a/python/ql/test/library-tests/DefUse/Definitions.ql b/python/ql/test/library-tests/DefUse/Definitions.ql index 049bb7b9a82..52b00f42146 100644 --- a/python/ql/test/library-tests/DefUse/Definitions.ql +++ b/python/ql/test/library-tests/DefUse/Definitions.ql @@ -9,4 +9,4 @@ import python from Name d where d.defines(_) -select d.getId(), d.getLocation().getStartLine() \ No newline at end of file +select d.getId(), d.getLocation().getStartLine() diff --git a/python/ql/test/library-tests/DefUse/Uses.ql b/python/ql/test/library-tests/DefUse/Uses.ql index bb02c6b5fac..ada93f740fb 100644 --- a/python/ql/test/library-tests/DefUse/Uses.ql +++ b/python/ql/test/library-tests/DefUse/Uses.ql @@ -9,4 +9,4 @@ import python from Name u where u.uses(_) -select u.getId(), u.getLocation().getStartLine() \ No newline at end of file +select u.getId(), u.getLocation().getStartLine() diff --git a/python/ql/test/library-tests/DuplicateCode/Duplicate.ql b/python/ql/test/library-tests/DuplicateCode/Duplicate.ql index dfa9c11bf68..c680d481398 100644 --- a/python/ql/test/library-tests/DuplicateCode/Duplicate.ql +++ b/python/ql/test/library-tests/DuplicateCode/Duplicate.ql @@ -6,16 +6,18 @@ */ import python - import external.CodeDuplication predicate lexically_sorted(DuplicateBlock dup1, DuplicateBlock dup2) { - dup1.sourceFile().getAbsolutePath() < dup2.sourceFile().getAbsolutePath() - or - dup1.sourceFile().getAbsolutePath() = dup2.sourceFile().getAbsolutePath() and dup1.sourceStartLine() < dup2.sourceStartLine() + dup1.sourceFile().getAbsolutePath() < dup2.sourceFile().getAbsolutePath() + or + dup1.sourceFile().getAbsolutePath() = dup2.sourceFile().getAbsolutePath() and + dup1.sourceStartLine() < dup2.sourceStartLine() } from DuplicateBlock dup1, DuplicateBlock dup2 -where dup1.getEquivalenceClass() = dup2.getEquivalenceClass() -and lexically_sorted(dup1, dup2) -select dup1.toString(), dup2.toString(), dup1.sourceFile().getShortName(), dup1.sourceStartLine(), dup1.sourceEndLine() +where + dup1.getEquivalenceClass() = dup2.getEquivalenceClass() and + lexically_sorted(dup1, dup2) +select dup1.toString(), dup2.toString(), dup1.sourceFile().getShortName(), dup1.sourceStartLine(), + dup1.sourceEndLine() diff --git a/python/ql/test/library-tests/DuplicateCode/DuplicateStatements.ql b/python/ql/test/library-tests/DuplicateCode/DuplicateStatements.ql index a4243bca968..17904ea65cd 100644 --- a/python/ql/test/library-tests/DuplicateCode/DuplicateStatements.ql +++ b/python/ql/test/library-tests/DuplicateCode/DuplicateStatements.ql @@ -10,16 +10,17 @@ import external.CodeDuplication predicate mostlyDuplicateFunction(Function f) { exists(int covered, int total, Function other, int percent | - duplicateStatements(f, other, covered, total) and - covered != total and - total > 5 and - covered * 100 / total = percent and - percent > 80 and - not exists(Scope s | s = f.getScope*() | duplicateScopes(s, _, _, _)) + duplicateStatements(f, other, covered, total) and + covered != total and + total > 5 and + covered * 100 / total = percent and + percent > 80 and + not exists(Scope s | s = f.getScope*() | duplicateScopes(s, _, _, _)) ) } from Stmt s -where mostlyDuplicateFunction(s.getScope()) and -not duplicateStatement(s.getScope(), _, s, _) -select s.toString(), s.getLocation().toString() \ No newline at end of file +where + mostlyDuplicateFunction(s.getScope()) and + not duplicateStatement(s.getScope(), _, s, _) +select s.toString(), s.getLocation().toString() diff --git a/python/ql/test/library-tests/DuplicateCode/Similar.ql b/python/ql/test/library-tests/DuplicateCode/Similar.ql index 338ec5602ef..528908336d8 100644 --- a/python/ql/test/library-tests/DuplicateCode/Similar.ql +++ b/python/ql/test/library-tests/DuplicateCode/Similar.ql @@ -6,16 +6,17 @@ */ import python - import external.CodeDuplication predicate lexically_sorted(SimilarBlock dup1, SimilarBlock dup2) { - dup1.sourceFile().getAbsolutePath() < dup2.sourceFile().getAbsolutePath() - or - dup1.sourceFile().getAbsolutePath() = dup2.sourceFile().getAbsolutePath() and dup1.sourceStartLine() < dup2.sourceStartLine() + dup1.sourceFile().getAbsolutePath() < dup2.sourceFile().getAbsolutePath() + or + dup1.sourceFile().getAbsolutePath() = dup2.sourceFile().getAbsolutePath() and + dup1.sourceStartLine() < dup2.sourceStartLine() } from SimilarBlock dup1, SimilarBlock dup2 -where dup1.getEquivalenceClass() = dup2.getEquivalenceClass() -and lexically_sorted(dup1, dup2) +where + dup1.getEquivalenceClass() = dup2.getEquivalenceClass() and + lexically_sorted(dup1, dup2) select dup1, dup2, dup1.sourceFile().getShortName(), dup1.sourceStartLine(), dup1.sourceEndLine() diff --git a/python/ql/test/library-tests/PointsTo/absent/Absent.ql b/python/ql/test/library-tests/PointsTo/absent/Absent.ql index d21c2b339ae..95cdf3a1084 100644 --- a/python/ql/test/library-tests/PointsTo/absent/Absent.ql +++ b/python/ql/test/library-tests/PointsTo/absent/Absent.ql @@ -1,8 +1,6 @@ - import python import semmle.python.objects.Modules from Value val, ControlFlowNode f where f.pointsTo(val) select f, val - diff --git a/python/ql/test/library-tests/PointsTo/api/ClassValue.ql b/python/ql/test/library-tests/PointsTo/api/ClassValue.ql index 1c0c53d0bcd..a71380b7603 100644 --- a/python/ql/test/library-tests/PointsTo/api/ClassValue.ql +++ b/python/ql/test/library-tests/PointsTo/api/ClassValue.ql @@ -11,5 +11,4 @@ where cls = ClassValue::classmethod() and description = "classmethod" or cls = ClassValue::bool().getMro().getItem(2) and description = "object" - -select cls, description \ No newline at end of file +select cls, description diff --git a/python/ql/test/library-tests/PointsTo/api/Constants.ql b/python/ql/test/library-tests/PointsTo/api/Constants.ql index 73ff6750c4d..39763e6fc24 100644 --- a/python/ql/test/library-tests/PointsTo/api/Constants.ql +++ b/python/ql/test/library-tests/PointsTo/api/Constants.ql @@ -1,20 +1,16 @@ - import python from string txt, Value val where -exists(string s | - txt = "u'" + s + "'" and val = Value::forUnicode(s) + exists(string s | + txt = "u'" + s + "'" and val = Value::forUnicode(s) + or + txt = "b'" + s + "'" and val = Value::forBytes(s) + | + s = "a" or s = "b" or s = "c" or s = "d" + ) or - txt = "b'" + s + "'" and val = Value::forBytes(s) - | - s = "a" or s = "b" or s = "c" or s = "d" -) -or -exists(int i | - txt = i.toString() and val = Value::forInt(i) - | - i in [1..10] or i in [1000..1010] -) - + exists(int i | txt = i.toString() and val = Value::forInt(i) | + i in [1 .. 10] or i in [1000 .. 1010] + ) select txt, val diff --git a/python/ql/test/library-tests/PointsTo/api/QualifedNames.ql b/python/ql/test/library-tests/PointsTo/api/QualifedNames.ql index 8c82e2d106f..226b2520521 100644 --- a/python/ql/test/library-tests/PointsTo/api/QualifedNames.ql +++ b/python/ql/test/library-tests/PointsTo/api/QualifedNames.ql @@ -1,16 +1,15 @@ - import python from FunctionValue v, string name -where name = v.getQualifiedName() and -( - v = Value::named("len") - or - v instanceof PythonFunctionValue - or - v = Value::named("sys.exit") - or - v = Value::named("list").(ClassValue).lookup("append") -) - -select v, name \ No newline at end of file +where + name = v.getQualifiedName() and + ( + v = Value::named("len") + or + v instanceof PythonFunctionValue + or + v = Value::named("sys.exit") + or + v = Value::named("list").(ClassValue).lookup("append") + ) +select v, name diff --git a/python/ql/test/library-tests/PointsTo/api/Value.ql b/python/ql/test/library-tests/PointsTo/api/Value.ql index 674dce5a299..23d78317764 100644 --- a/python/ql/test/library-tests/PointsTo/api/Value.ql +++ b/python/ql/test/library-tests/PointsTo/api/Value.ql @@ -2,11 +2,12 @@ import python from Value val, string name where - val = Value::named(name) - and + val = Value::named(name) and ( - name = "bool" or name = "sys" or name = "sys.argv" or - name = "ValueError" or name = "slice" + name = "bool" or + name = "sys" or + name = "sys.argv" or + name = "ValueError" or + name = "slice" ) - -select val, name \ No newline at end of file +select val, name diff --git a/python/ql/test/library-tests/PointsTo/calls/Argument.ql b/python/ql/test/library-tests/PointsTo/calls/Argument.ql index e88baf75791..1678c02c182 100644 --- a/python/ql/test/library-tests/PointsTo/calls/Argument.ql +++ b/python/ql/test/library-tests/PointsTo/calls/Argument.ql @@ -2,4 +2,4 @@ import python from ControlFlowNode arg, FunctionObject func, int i where arg = func.getArgumentForCall(_, i) -select arg.getLocation().getStartLine(), i, arg.toString(), func.toString() \ No newline at end of file +select arg.getLocation().getStartLine(), i, arg.toString(), func.toString() diff --git a/python/ql/test/library-tests/PointsTo/calls/Call.ql b/python/ql/test/library-tests/PointsTo/calls/Call.ql index d1cfbdad690..94c4212cc64 100644 --- a/python/ql/test/library-tests/PointsTo/calls/Call.ql +++ b/python/ql/test/library-tests/PointsTo/calls/Call.ql @@ -1,7 +1,5 @@ - import python from ControlFlowNode call, FunctionObject func - where call = func.getACall() -select call.getLocation().getStartLine(), call.toString(), func.toString() \ No newline at end of file +select call.getLocation().getStartLine(), call.toString(), func.toString() diff --git a/python/ql/test/library-tests/PointsTo/comparisons/PointsTo.ql b/python/ql/test/library-tests/PointsTo/comparisons/PointsTo.ql index 804ae3a61df..958306c53e6 100644 --- a/python/ql/test/library-tests/PointsTo/comparisons/PointsTo.ql +++ b/python/ql/test/library-tests/PointsTo/comparisons/PointsTo.ql @@ -1,4 +1,3 @@ - import python import semmle.python.objects.ObjectAPI diff --git a/python/ql/test/library-tests/PointsTo/customise/test.ql b/python/ql/test/library-tests/PointsTo/customise/test.ql index dca091e2e4f..8aea8b05b18 100644 --- a/python/ql/test/library-tests/PointsTo/customise/test.ql +++ b/python/ql/test/library-tests/PointsTo/customise/test.ql @@ -1,15 +1,15 @@ - import python import semmle.python.types.Extensions -/* Customise: Claim any function called has_type_XXX return any class +/* + * Customise: Claim any function called has_type_XXX return any class * whose name matches XXX */ -class HasTypeFact extends CustomPointsToOriginFact { +class HasTypeFact extends CustomPointsToOriginFact { HasTypeFact() { exists(FunctionObject func, string name | - func.getACall() = this and + func.getACall() = this and name = func.getName() and name.prefix("has_type_".length()) = "has_type_" ) @@ -17,19 +17,19 @@ class HasTypeFact extends CustomPointsToOriginFact { override predicate pointsTo(Object value, ClassObject cls) { exists(FunctionObject func, string name | - func.getACall() = this and + func.getACall() = this and name = func.getName() and - name.prefix("has_type_".length()) = "has_type_" | + name.prefix("has_type_".length()) = "has_type_" + | cls.getName() = name.suffix("has_type_".length()) ) and value = this } - } - from int line, ControlFlowNode f, Object o, ClassObject c -where f.getLocation().getStartLine() = line and - exists(Comment ct | ct.getLocation().getStartLine() < line) and - f.refersTo(o, c, _) +where + f.getLocation().getStartLine() = line and + exists(Comment ct | ct.getLocation().getStartLine() < line) and + f.refersTo(o, c, _) select line, f.toString(), o.toString(), c.toString() diff --git a/python/ql/test/library-tests/PointsTo/decorators/Test.ql b/python/ql/test/library-tests/PointsTo/decorators/Test.ql index af274849a26..3aff12a3a1f 100644 --- a/python/ql/test/library-tests/PointsTo/decorators/Test.ql +++ b/python/ql/test/library-tests/PointsTo/decorators/Test.ql @@ -3,9 +3,8 @@ import python // We don't care about the internals of functools which vary from // version to version, just the end result. from NameNode f, Object o, ControlFlowNode x, int line - -where f.refersTo(o, x) and -f.getLocation().getFile().getBaseName() = "test.py" and -line = f.getLocation().getStartLine() - +where + f.refersTo(o, x) and + f.getLocation().getFile().getBaseName() = "test.py" and + line = f.getLocation().getStartLine() select line, f.toString(), o.toString(), x.getLocation().toString() diff --git a/python/ql/test/library-tests/PointsTo/decorators/Values.ql b/python/ql/test/library-tests/PointsTo/decorators/Values.ql index 2e752466c55..712cc025786 100644 --- a/python/ql/test/library-tests/PointsTo/decorators/Values.ql +++ b/python/ql/test/library-tests/PointsTo/decorators/Values.ql @@ -1,10 +1,9 @@ - import python import semmle.python.pointsto.PointsTo import semmle.python.objects.ObjectInternal from NameNode f, Context ctx, ObjectInternal v where - f.getLocation().getFile().getBaseName() = "test.py" and - PointsTo::pointsTo(f, ctx, v, _) + f.getLocation().getFile().getBaseName() = "test.py" and + PointsTo::pointsTo(f, ctx, v, _) select f, ctx, v diff --git a/python/ql/test/library-tests/PointsTo/extensions/Extend.ql b/python/ql/test/library-tests/PointsTo/extensions/Extend.ql index af4a696ea4f..14082905ce4 100644 --- a/python/ql/test/library-tests/PointsTo/extensions/Extend.ql +++ b/python/ql/test/library-tests/PointsTo/extensions/Extend.ql @@ -1,13 +1,8 @@ - - import python - import semmle.python.pointsto.PointsTo private import semmle.python.types.Extensions - class CfgExtension extends CustomPointsToOriginFact { - CfgExtension() { this.(NameNode).getId() = "one" or @@ -24,23 +19,23 @@ class CfgExtension extends CustomPointsToOriginFact { } } -class AttributeExtension extends CustomPointsToAttribute { - +class AttributeExtension extends CustomPointsToAttribute { AttributeExtension() { this = this } - override predicate attributePointsTo(string name, Object value, ClassObject cls, ControlFlowNode origin) { - cls = theIntType() and origin = any(Module m).getEntryNode() and + override predicate attributePointsTo( + string name, Object value, ClassObject cls, ControlFlowNode origin + ) { + cls = theIntType() and + origin = any(Module m).getEntryNode() and ( name = "three" and value.(NumericObject).intValue() = 3 or name = "four" and value.(NumericObject).intValue() = 4 ) } - } class NoClassExtension extends CustomPointsToObjectFact { - NoClassExtension() { this = this } override predicate pointsTo(Object value) { @@ -48,24 +43,17 @@ class NoClassExtension extends CustomPointsToObjectFact { or this.(NameNode).getId() = "six" and value.(NumericObject).intValue() = 6 } - } /* Check that we can use old API without causing non-monotonic recursion */ class RecurseIntoOldPointsTo extends CustomPointsToOriginFact { - - RecurseIntoOldPointsTo() { - PointsTo::points_to(this, _, unknownValue(), _, _) - } + RecurseIntoOldPointsTo() { PointsTo::points_to(this, _, unknownValue(), _, _) } override predicate pointsTo(Object value, ClassObject cls) { value = unknownValue() and cls = theUnknownType() } } - from ControlFlowNode f, Object o where f.getLocation().getFile().getBaseName() = "test.py" and f.refersTo(o) select f, o.toString() - - diff --git a/python/ql/test/library-tests/PointsTo/functions/Calls.ql b/python/ql/test/library-tests/PointsTo/functions/Calls.ql index 6f1e8cf8bd3..2833c2e60be 100644 --- a/python/ql/test/library-tests/PointsTo/functions/Calls.ql +++ b/python/ql/test/library-tests/PointsTo/functions/Calls.ql @@ -1,12 +1,11 @@ - import python from CallNode call, FunctionObject func, string kind -where -(func.getAMethodCall() = call and kind = "method" - or - func.getAFunctionCall() = call and kind = "function" -) -and -call.getLocation().getFile().getShortName().matches("odasa%") +where + ( + func.getAMethodCall() = call and kind = "method" + or + func.getAFunctionCall() = call and kind = "function" + ) and + call.getLocation().getFile().getShortName().matches("odasa%") select call.getLocation().getStartLine(), call.toString(), func.toString(), kind diff --git a/python/ql/test/library-tests/PointsTo/functions/NeverReturns.ql b/python/ql/test/library-tests/PointsTo/functions/NeverReturns.ql index ebb69fc7a0f..c576651a8e6 100644 --- a/python/ql/test/library-tests/PointsTo/functions/NeverReturns.ql +++ b/python/ql/test/library-tests/PointsTo/functions/NeverReturns.ql @@ -1,4 +1,3 @@ - import python from FunctionObject f diff --git a/python/ql/test/library-tests/PointsTo/functions/test.ql b/python/ql/test/library-tests/PointsTo/functions/test.ql index dd1a070d99f..f520f6b2254 100644 --- a/python/ql/test/library-tests/PointsTo/functions/test.ql +++ b/python/ql/test/library-tests/PointsTo/functions/test.ql @@ -1,9 +1,7 @@ import python from Call c, FunctionObject f - -where c.getFunc().(Attribute).getObject().(Name).getId() = "self" -and -f.getACall().getNode() = c - +where + c.getFunc().(Attribute).getObject().(Name).getId() = "self" and + f.getACall().getNode() = c select c.getLocation().getStartLine(), f.toString() diff --git a/python/ql/test/library-tests/PointsTo/general/GlobalPointsTo.ql b/python/ql/test/library-tests/PointsTo/general/GlobalPointsTo.ql index 147b7835e24..a7b9403a18d 100644 --- a/python/ql/test/library-tests/PointsTo/general/GlobalPointsTo.ql +++ b/python/ql/test/library-tests/PointsTo/general/GlobalPointsTo.ql @@ -1,10 +1,9 @@ - import python import interesting from int line, ControlFlowNode f, Object o, ImportTimeScope n -where -of_interest(f, line) and -f.refersTo(o) and -f.getScope() = n +where + of_interest(f, line) and + f.refersTo(o) and + f.getScope() = n select n.toString(), line, f.toString(), o.toString() diff --git a/python/ql/test/library-tests/PointsTo/general/LocalPointsTo.ql b/python/ql/test/library-tests/PointsTo/general/LocalPointsTo.ql index 00144c87601..342a329746e 100644 --- a/python/ql/test/library-tests/PointsTo/general/LocalPointsTo.ql +++ b/python/ql/test/library-tests/PointsTo/general/LocalPointsTo.ql @@ -10,7 +10,7 @@ import interesting import Util from int line, ControlFlowNode f, Object o -where - of_interest(f, line) and - f.refersTo(o) +where + of_interest(f, line) and + f.refersTo(o) select line, f.toString(), repr(o) diff --git a/python/ql/test/library-tests/PointsTo/general/LocalPointsToType.ql b/python/ql/test/library-tests/PointsTo/general/LocalPointsToType.ql index 693d0b2b84b..c80de106c3d 100644 --- a/python/ql/test/library-tests/PointsTo/general/LocalPointsToType.ql +++ b/python/ql/test/library-tests/PointsTo/general/LocalPointsToType.ql @@ -1,10 +1,9 @@ - import python import interesting import Util from int line, ControlFlowNode f, Object o, ClassObject cls -where - of_interest(f, line) and - f.refersTo(o, cls, _) +where + of_interest(f, line) and + f.refersTo(o, cls, _) select line, f.toString(), repr(o), repr(cls) diff --git a/python/ql/test/library-tests/PointsTo/global/Global.ql b/python/ql/test/library-tests/PointsTo/global/Global.ql index 8aa0453645f..d9b8a246d11 100644 --- a/python/ql/test/library-tests/PointsTo/global/Global.ql +++ b/python/ql/test/library-tests/PointsTo/global/Global.ql @@ -1,14 +1,11 @@ - import python - - import python import semmle.python.pointsto.PointsTo import semmle.python.pointsto.PointsToContext import semmle.python.objects.ObjectInternal from ControlFlowNode f, PointsToContext ctx, Value obj, ControlFlowNode orig -where exists(ExprStmt s | s.getValue().getAFlowNode() = f) and -PointsTo::pointsTo(f, ctx, obj, orig) - +where + exists(ExprStmt s | s.getValue().getAFlowNode() = f) and + PointsTo::pointsTo(f, ctx, obj, orig) select ctx, f, obj.toString(), orig diff --git a/python/ql/test/library-tests/PointsTo/guarded/PointsTo.ql b/python/ql/test/library-tests/PointsTo/guarded/PointsTo.ql index 98644b02e99..b545f6e6a18 100644 --- a/python/ql/test/library-tests/PointsTo/guarded/PointsTo.ql +++ b/python/ql/test/library-tests/PointsTo/guarded/PointsTo.ql @@ -1,7 +1,8 @@ import python from ControlFlowNode f, Object o, ControlFlowNode x - -where f.refersTo(o, x) and exists(CallNode call | call.getFunction().getNode().(Name).getId() = "use" and call.getArg(0) = f) - -select f.getLocation().getFile().getShortName(), f.getLocation().getStartLine(), f.toString(), o.toString(), x.getLocation().getStartLine() +where + f.refersTo(o, x) and + exists(CallNode call | call.getFunction().getNode().(Name).getId() = "use" and call.getArg(0) = f) +select f.getLocation().getFile().getShortName(), f.getLocation().getStartLine(), f.toString(), + o.toString(), x.getLocation().getStartLine() diff --git a/python/ql/test/library-tests/PointsTo/guarded/PointsToWithType.ql b/python/ql/test/library-tests/PointsTo/guarded/PointsToWithType.ql index 83bbd5e42ba..2bf6b6b62a9 100644 --- a/python/ql/test/library-tests/PointsTo/guarded/PointsToWithType.ql +++ b/python/ql/test/library-tests/PointsTo/guarded/PointsToWithType.ql @@ -1,7 +1,8 @@ import python from ControlFlowNode f, Object o, ClassObject c, ControlFlowNode x - -where f.refersTo(o, c, x) and exists(CallNode call | call.getFunction().getNode().(Name).getId() = "use" and call.getArg(0) = f) - -select f.getLocation().getFile().getShortName(), f.getLocation().getStartLine(), f.toString(), o.toString(), c.toString(), x.getLocation().getStartLine() +where + f.refersTo(o, c, x) and + exists(CallNode call | call.getFunction().getNode().(Name).getId() = "use" and call.getArg(0) = f) +select f.getLocation().getFile().getShortName(), f.getLocation().getStartLine(), f.toString(), + o.toString(), c.toString(), x.getLocation().getStartLine() diff --git a/python/ql/test/library-tests/PointsTo/import_star/Values.ql b/python/ql/test/library-tests/PointsTo/import_star/Values.ql index f5bfe1bfeac..b54b8c6c78d 100644 --- a/python/ql/test/library-tests/PointsTo/import_star/Values.ql +++ b/python/ql/test/library-tests/PointsTo/import_star/Values.ql @@ -1,7 +1,5 @@ - import python from ControlFlowNode f, Context ctx, Value v, ControlFlowNode origin -where - f.pointsTo(ctx, v, origin) +where f.pointsTo(ctx, v, origin) select f, ctx, v diff --git a/python/ql/test/library-tests/PointsTo/imports/Runtime.ql b/python/ql/test/library-tests/PointsTo/imports/Runtime.ql index 4a25bff744a..4d917aa5af6 100644 --- a/python/ql/test/library-tests/PointsTo/imports/Runtime.ql +++ b/python/ql/test/library-tests/PointsTo/imports/Runtime.ql @@ -1,8 +1,9 @@ - import python from int line, ControlFlowNode f, Object o, ControlFlowNode orig -where - not f.getLocation().getFile().inStdlib() and - f.refersTo(o, orig) and line = f.getLocation().getStartLine() and line != 0 +where + not f.getLocation().getFile().inStdlib() and + f.refersTo(o, orig) and + line = f.getLocation().getStartLine() and + line != 0 select f.getLocation().getFile().getShortName(), line, f.toString(), o.toString(), orig.toString() diff --git a/python/ql/test/library-tests/PointsTo/imports/RuntimeWithType.ql b/python/ql/test/library-tests/PointsTo/imports/RuntimeWithType.ql index eca5e965ea8..7e915d04573 100644 --- a/python/ql/test/library-tests/PointsTo/imports/RuntimeWithType.ql +++ b/python/ql/test/library-tests/PointsTo/imports/RuntimeWithType.ql @@ -1,8 +1,10 @@ - import python from int line, ControlFlowNode f, Object o, ClassObject cls, ControlFlowNode orig -where - not f.getLocation().getFile().inStdlib() and - f.refersTo(o, cls, orig) and line = f.getLocation().getStartLine() and line != 0 -select f.getLocation().getFile().getShortName(), line, f.toString(), o.toString(), cls.toString(), orig.toString() +where + not f.getLocation().getFile().inStdlib() and + f.refersTo(o, cls, orig) and + line = f.getLocation().getStartLine() and + line != 0 +select f.getLocation().getFile().getShortName(), line, f.toString(), o.toString(), cls.toString(), + orig.toString() diff --git a/python/ql/test/library-tests/PointsTo/indexing/Test.ql b/python/ql/test/library-tests/PointsTo/indexing/Test.ql index 70b62e825f7..825cb1cf3be 100644 --- a/python/ql/test/library-tests/PointsTo/indexing/Test.ql +++ b/python/ql/test/library-tests/PointsTo/indexing/Test.ql @@ -1,8 +1,7 @@ import python from ControlFlowNode f, Object o, ControlFlowNode x - -where f.refersTo(o, x) and -f.getLocation().getFile().getBaseName() = "test.py" - +where + f.refersTo(o, x) and + f.getLocation().getFile().getBaseName() = "test.py" select f.getLocation().getStartLine(), f.toString(), o.toString(), x.getLocation().getStartLine() diff --git a/python/ql/test/library-tests/PointsTo/indexing/TestWithType.ql b/python/ql/test/library-tests/PointsTo/indexing/TestWithType.ql index 6b0c8b8460d..e11999a75de 100644 --- a/python/ql/test/library-tests/PointsTo/indexing/TestWithType.ql +++ b/python/ql/test/library-tests/PointsTo/indexing/TestWithType.ql @@ -1,8 +1,8 @@ import python from ControlFlowNode f, Object o, ClassObject c, ControlFlowNode x - -where f.refersTo(o, c, x) and -f.getLocation().getFile().getBaseName() = "test.py" - -select f.getLocation().getStartLine(), f.toString(), o.toString(), c.toString(), x.getLocation().getStartLine() +where + f.refersTo(o, c, x) and + f.getLocation().getFile().getBaseName() = "test.py" +select f.getLocation().getStartLine(), f.toString(), o.toString(), c.toString(), + x.getLocation().getStartLine() diff --git a/python/ql/test/library-tests/PointsTo/inheritance/BaseTypes.ql b/python/ql/test/library-tests/PointsTo/inheritance/BaseTypes.ql index 27b2ed4ce2f..c4677b7df51 100644 --- a/python/ql/test/library-tests/PointsTo/inheritance/BaseTypes.ql +++ b/python/ql/test/library-tests/PointsTo/inheritance/BaseTypes.ql @@ -1,7 +1,7 @@ - import python from ClassObject cls, ClassObject base, int n -where not cls.isBuiltin() and -base = cls.getBaseType(n) +where + not cls.isBuiltin() and + base = cls.getBaseType(n) select cls.toString(), n, base.toString() diff --git a/python/ql/test/library-tests/PointsTo/inheritance/Calls.ql b/python/ql/test/library-tests/PointsTo/inheritance/Calls.ql index d35ac04bb30..f91d207fc70 100644 --- a/python/ql/test/library-tests/PointsTo/inheritance/Calls.ql +++ b/python/ql/test/library-tests/PointsTo/inheritance/Calls.ql @@ -1,8 +1,5 @@ - import python from Call c, FunctionObject f - where f.getACall().getNode() = c - select c.getLocation().getStartLine(), f.toString(), f.getFunction().getLocation().getStartLine() diff --git a/python/ql/test/library-tests/PointsTo/inheritance/Declared.ql b/python/ql/test/library-tests/PointsTo/inheritance/Declared.ql index aefdb8894bd..def579bb22d 100644 --- a/python/ql/test/library-tests/PointsTo/inheritance/Declared.ql +++ b/python/ql/test/library-tests/PointsTo/inheritance/Declared.ql @@ -1,4 +1,3 @@ - import python import semmle.python.pointsto.PointsTo import semmle.python.objects.ObjectInternal diff --git a/python/ql/test/library-tests/PointsTo/inheritance/Declares.ql b/python/ql/test/library-tests/PointsTo/inheritance/Declares.ql index ee837e66478..be4d9ef5711 100644 --- a/python/ql/test/library-tests/PointsTo/inheritance/Declares.ql +++ b/python/ql/test/library-tests/PointsTo/inheritance/Declares.ql @@ -1,4 +1,3 @@ - import python import semmle.python.pointsto.Base diff --git a/python/ql/test/library-tests/PointsTo/inheritance/Lookup.ql b/python/ql/test/library-tests/PointsTo/inheritance/Lookup.ql index bf020de465b..13d3eece75f 100644 --- a/python/ql/test/library-tests/PointsTo/inheritance/Lookup.ql +++ b/python/ql/test/library-tests/PointsTo/inheritance/Lookup.ql @@ -1,4 +1,3 @@ - import python import semmle.python.pointsto.PointsTo import semmle.python.objects.ObjectInternal diff --git a/python/ql/test/library-tests/PointsTo/inheritance/MetaClass.ql b/python/ql/test/library-tests/PointsTo/inheritance/MetaClass.ql index 064cc2ca688..3768116ff11 100644 --- a/python/ql/test/library-tests/PointsTo/inheritance/MetaClass.ql +++ b/python/ql/test/library-tests/PointsTo/inheritance/MetaClass.ql @@ -1,8 +1,7 @@ - import python from ClassObject cls, ClassObject meta -where not cls.isBuiltin() and -meta = cls.getMetaClass() +where + not cls.isBuiltin() and + meta = cls.getMetaClass() select cls.toString(), meta.toString() - diff --git a/python/ql/test/library-tests/PointsTo/inheritance/Mro.ql b/python/ql/test/library-tests/PointsTo/inheritance/Mro.ql index 38767957493..7fdd431c216 100644 --- a/python/ql/test/library-tests/PointsTo/inheritance/Mro.ql +++ b/python/ql/test/library-tests/PointsTo/inheritance/Mro.ql @@ -1,14 +1,10 @@ - import python - private import semmle.python.objects.ObjectInternal private import semmle.python.pointsto.PointsTo /** Make unknown type visible */ class UnknownType extends UnknownClassInternal { - override string toString() { result = "*UNKNOWN TYPE" } - } from ClassObjectInternal c diff --git a/python/ql/test/library-tests/PointsTo/inheritance/Self.ql b/python/ql/test/library-tests/PointsTo/inheritance/Self.ql index a72da5f5248..050690fd1cb 100644 --- a/python/ql/test/library-tests/PointsTo/inheritance/Self.ql +++ b/python/ql/test/library-tests/PointsTo/inheritance/Self.ql @@ -1,4 +1,3 @@ - import python from NameNode n, Object value, ClassObject cls diff --git a/python/ql/test/library-tests/PointsTo/inheritance/SuperTypes.ql b/python/ql/test/library-tests/PointsTo/inheritance/SuperTypes.ql index 0793957f2e4..7810c607787 100644 --- a/python/ql/test/library-tests/PointsTo/inheritance/SuperTypes.ql +++ b/python/ql/test/library-tests/PointsTo/inheritance/SuperTypes.ql @@ -1,7 +1,7 @@ - import python from ClassObject cls, ClassObject sup -where not cls.isBuiltin() and -sup = cls.getASuperType() +where + not cls.isBuiltin() and + sup = cls.getASuperType() select cls.toString(), sup.toString() diff --git a/python/ql/test/library-tests/PointsTo/local/LocalPointsTo.ql b/python/ql/test/library-tests/PointsTo/local/LocalPointsTo.ql index d3cde3b0771..996b8597d5e 100644 --- a/python/ql/test/library-tests/PointsTo/local/LocalPointsTo.ql +++ b/python/ql/test/library-tests/PointsTo/local/LocalPointsTo.ql @@ -1,10 +1,9 @@ - import python import semmle.python.pointsto.PointsTo import semmle.python.objects.ObjectInternal from ControlFlowNode f, ObjectInternal obj, ControlFlowNode orig -where exists(ExprStmt s | s.getValue().getAFlowNode() = f) and -PointsTo::pointsTo(f, _, obj, orig) - +where + exists(ExprStmt s | s.getValue().getAFlowNode() = f) and + PointsTo::pointsTo(f, _, obj, orig) select f, obj.toString(), orig diff --git a/python/ql/test/library-tests/PointsTo/lookup/Lookup.ql b/python/ql/test/library-tests/PointsTo/lookup/Lookup.ql index febbda03f03..67aff9597c2 100644 --- a/python/ql/test/library-tests/PointsTo/lookup/Lookup.ql +++ b/python/ql/test/library-tests/PointsTo/lookup/Lookup.ql @@ -1,12 +1,13 @@ import python from string l, NameNode n -where n.getLocation().getFile().getShortName() = "test.py" and -( - n.isGlobal() and l = "global" - or - n.isLocal() and l = "local" - or - n.isNonLocal() and l = "non-local" -) +where + n.getLocation().getFile().getShortName() = "test.py" and + ( + n.isGlobal() and l = "global" + or + n.isLocal() and l = "local" + or + n.isNonLocal() and l = "non-local" + ) select n.getLocation().getStartLine(), n.getId(), l diff --git a/python/ql/test/library-tests/PointsTo/metaclass/Failed.ql b/python/ql/test/library-tests/PointsTo/metaclass/Failed.ql index 4fe75b70572..d9cb2f019a6 100644 --- a/python/ql/test/library-tests/PointsTo/metaclass/Failed.ql +++ b/python/ql/test/library-tests/PointsTo/metaclass/Failed.ql @@ -1,9 +1,7 @@ - import python from ClassObject cls, string reason - -where cls.getPyClass().getEnclosingModule().getName() = "test" -and cls.failedInference(reason) - +where + cls.getPyClass().getEnclosingModule().getName() = "test" and + cls.failedInference(reason) select cls, reason diff --git a/python/ql/test/library-tests/PointsTo/metaclass/Mro.ql b/python/ql/test/library-tests/PointsTo/metaclass/Mro.ql index ec3257a8627..5a10701ef83 100644 --- a/python/ql/test/library-tests/PointsTo/metaclass/Mro.ql +++ b/python/ql/test/library-tests/PointsTo/metaclass/Mro.ql @@ -1,14 +1,10 @@ - import python - private import semmle.python.objects.ObjectInternal private import semmle.python.pointsto.PointsTo /** Make unknown type visible */ class UnknownType extends UnknownClassInternal { - override string toString() { result = "*UNKNOWN TYPE" } - } from PythonClassObjectInternal cls diff --git a/python/ql/test/library-tests/PointsTo/metaclass/Style.ql b/python/ql/test/library-tests/PointsTo/metaclass/Style.ql index 8c5d6913e15..29feef64ec1 100644 --- a/python/ql/test/library-tests/PointsTo/metaclass/Style.ql +++ b/python/ql/test/library-tests/PointsTo/metaclass/Style.ql @@ -1,13 +1,11 @@ - - import python - from ClassObject cls, string style -where cls.getPyClass().getEnclosingModule().getName() = "test" -and ( - cls.isNewStyle() and style = "new" - or - cls.isOldStyle() and style = "old" -) +where + cls.getPyClass().getEnclosingModule().getName() = "test" and + ( + cls.isNewStyle() and style = "new" + or + cls.isOldStyle() and style = "old" + ) select cls, style diff --git a/python/ql/test/library-tests/PointsTo/metaclass/test.ql b/python/ql/test/library-tests/PointsTo/metaclass/test.ql index 5b80203e60f..17b90483315 100644 --- a/python/ql/test/library-tests/PointsTo/metaclass/test.ql +++ b/python/ql/test/library-tests/PointsTo/metaclass/test.ql @@ -1,12 +1,9 @@ - import python private import semmle.python.objects.ObjectInternal /** Make unknown type visible */ class UnknownType extends UnknownClassInternal { - override string toString() { result = "*UNKNOWN TYPE" } - } from ClassObject cls diff --git a/python/ql/test/library-tests/PointsTo/new/Call.ql b/python/ql/test/library-tests/PointsTo/new/Call.ql index f740b0060f6..f014001f315 100644 --- a/python/ql/test/library-tests/PointsTo/new/Call.ql +++ b/python/ql/test/library-tests/PointsTo/new/Call.ql @@ -1,8 +1,6 @@ - import python import Util from ControlFlowNode call, FunctionObject func - where call = func.getACall() -select locate(call.getLocation(), "abdglq"), call.toString(), func.getQualifiedName() \ No newline at end of file +select locate(call.getLocation(), "abdglq"), call.toString(), func.getQualifiedName() diff --git a/python/ql/test/library-tests/PointsTo/new/ClassMethod.ql b/python/ql/test/library-tests/PointsTo/new/ClassMethod.ql index 2d13f2ae851..5ad6fabd380 100644 --- a/python/ql/test/library-tests/PointsTo/new/ClassMethod.ql +++ b/python/ql/test/library-tests/PointsTo/new/ClassMethod.ql @@ -1,9 +1,8 @@ - import python import semmle.python.types.Descriptors import Util from ClassMethodObject cm, CallNode call where call = cm.getACall() -select locate(call.getLocation(), "lp"), cm.getFunction().toString(), cm.(ControlFlowNode).getLocation().toString() - +select locate(call.getLocation(), "lp"), cm.getFunction().toString(), + cm.(ControlFlowNode).getLocation().toString() diff --git a/python/ql/test/library-tests/PointsTo/new/Dataflow.ql b/python/ql/test/library-tests/PointsTo/new/Dataflow.ql index c2ed05aa9dc..47a12acee53 100755 --- a/python/ql/test/library-tests/PointsTo/new/Dataflow.ql +++ b/python/ql/test/library-tests/PointsTo/new/Dataflow.ql @@ -1,8 +1,7 @@ - - import python import Util from EssaVariable v, EssaDefinition def where def = v.getDefinition() and not v.getSourceVariable() instanceof SpecialSsaSourceVariable -select locate(def.getLocation(), "abdefghijknrs_"), v.getRepresentation() + " = " + def.getRepresentation() +select locate(def.getLocation(), "abdefghijknrs_"), + v.getRepresentation() + " = " + def.getRepresentation() diff --git a/python/ql/test/library-tests/PointsTo/new/Definitions.ql b/python/ql/test/library-tests/PointsTo/new/Definitions.ql index dbaac3b09f9..5abcb663e16 100644 --- a/python/ql/test/library-tests/PointsTo/new/Definitions.ql +++ b/python/ql/test/library-tests/PointsTo/new/Definitions.ql @@ -1,8 +1,6 @@ - import python - import Util from EssaDefinition def, Variable v where v = def.getSourceVariable() and not v instanceof SpecialSsaSourceVariable -select locate(def.getLocation(), "abdgk"), v.toString(), def.getAQlClass() \ No newline at end of file +select locate(def.getLocation(), "abdgk"), v.toString(), def.getAQlClass() diff --git a/python/ql/test/library-tests/PointsTo/new/Live.ql b/python/ql/test/library-tests/PointsTo/new/Live.ql index 51f2b4e04a7..4bcb7da27e6 100644 --- a/python/ql/test/library-tests/PointsTo/new/Live.ql +++ b/python/ql/test/library-tests/PointsTo/new/Live.ql @@ -1,14 +1,10 @@ - import python import semmle.python.essa.SsaCompute - import Util from Variable var, BasicBlock b, ControlFlowNode loc, string end where -Liveness::liveAtEntry(var, b) and end = "entry" and loc = b.getNode(0) -or -Liveness::liveAtExit(var, b) and end = "exit" and loc = b.getLastNode() - - -select var, locate(loc.getLocation(), "b"), end \ No newline at end of file + Liveness::liveAtEntry(var, b) and end = "entry" and loc = b.getNode(0) + or + Liveness::liveAtExit(var, b) and end = "exit" and loc = b.getLastNode() +select var, locate(loc.getLocation(), "b"), end diff --git a/python/ql/test/library-tests/PointsTo/new/NameSpace.ql b/python/ql/test/library-tests/PointsTo/new/NameSpace.ql index 4e30796dc0b..18fd5e9e37c 100644 --- a/python/ql/test/library-tests/PointsTo/new/NameSpace.ql +++ b/python/ql/test/library-tests/PointsTo/new/NameSpace.ql @@ -2,17 +2,17 @@ import python import Util from Scope s, string name, Object val -where name != "__name__" and -( - exists(ModuleObject m | - m.getModule() = s and - m.attributeRefersTo(name, val, _) - ) - or - exists(ClassObject cls | - cls.getPyClass() = s and - cls.declaredAttribute(name) = val - ) -) - -select locate(s.getLocation(), "abcdghijklopqrs"), s.toString(), name, repr(val) \ No newline at end of file +where + name != "__name__" and + ( + exists(ModuleObject m | + m.getModule() = s and + m.attributeRefersTo(name, val, _) + ) + or + exists(ClassObject cls | + cls.getPyClass() = s and + cls.declaredAttribute(name) = val + ) + ) +select locate(s.getLocation(), "abcdghijklopqrs"), s.toString(), name, repr(val) diff --git a/python/ql/test/library-tests/PointsTo/new/Parameters.ql b/python/ql/test/library-tests/PointsTo/new/Parameters.ql index e3a76f9dc70..50c08a6fa0d 100644 --- a/python/ql/test/library-tests/PointsTo/new/Parameters.ql +++ b/python/ql/test/library-tests/PointsTo/new/Parameters.ql @@ -1,10 +1,6 @@ - import python - import Util from ParameterDefinition param, boolean self -where -if param.isSelf() then self = true else self = false - +where if param.isSelf() then self = true else self = false select locate(param.getLocation(), "g"), param.toString(), self diff --git a/python/ql/test/library-tests/PointsTo/new/PointsToMissing.ql b/python/ql/test/library-tests/PointsTo/new/PointsToMissing.ql index 341c6f28745..044d33c2887 100644 --- a/python/ql/test/library-tests/PointsTo/new/PointsToMissing.ql +++ b/python/ql/test/library-tests/PointsTo/new/PointsToMissing.ql @@ -4,7 +4,6 @@ import semmle.python.pointsto.PointsTo import semmle.python.objects.ObjectInternal /* This test should return _no_ results. */ - predicate relevant_node(ControlFlowNode n) { exists(CallNode c | c.getFunction().(NameNode).getId() = "check" and @@ -14,8 +13,8 @@ predicate relevant_node(ControlFlowNode n) { exists(Comment c, string filepath, int bl | n.getNode().getScope().getLocation().hasLocationInfo(filepath, bl, _, _, _) and c.getLocation().hasLocationInfo(filepath, bl, _, _, _) and - c.getText().matches("%check") - and not n.(NameNode).isStore() + c.getText().matches("%check") and + not n.(NameNode).isStore() ) } diff --git a/python/ql/test/library-tests/PointsTo/new/PointsToNone.ql b/python/ql/test/library-tests/PointsTo/new/PointsToNone.ql index 3bebd98bff1..c5009ad4cb6 100644 --- a/python/ql/test/library-tests/PointsTo/new/PointsToNone.ql +++ b/python/ql/test/library-tests/PointsTo/new/PointsToNone.ql @@ -2,8 +2,5 @@ import python import Util from ControlFlowNode f, ControlFlowNode x - -where -f.refersTo(theNoneObject(), _, x) - +where f.refersTo(theNoneObject(), _, x) select locate(f.getLocation(), "abcdghijklmopqr"), f.toString(), x.getLocation().getStartLine() diff --git a/python/ql/test/library-tests/PointsTo/new/PointsToUnknown.ql b/python/ql/test/library-tests/PointsTo/new/PointsToUnknown.ql index 9c9c432717f..27ebf200ee2 100644 --- a/python/ql/test/library-tests/PointsTo/new/PointsToUnknown.ql +++ b/python/ql/test/library-tests/PointsTo/new/PointsToUnknown.ql @@ -4,7 +4,5 @@ import semmle.python.pointsto.PointsTo import semmle.python.objects.ObjectInternal from ControlFlowNode f, ControlFlowNode x - where PointsTo::pointsTo(f, _, ObjectInternal::unknown(), x) - select locate(f.getLocation(), "abchr"), f.toString(), x.getLocation().getStartLine() diff --git a/python/ql/test/library-tests/PointsTo/new/PointsToWithContext.ql b/python/ql/test/library-tests/PointsTo/new/PointsToWithContext.ql index e2ef1fc3c61..56a58642f1c 100755 --- a/python/ql/test/library-tests/PointsTo/new/PointsToWithContext.ql +++ b/python/ql/test/library-tests/PointsTo/new/PointsToWithContext.ql @@ -4,7 +4,6 @@ import semmle.python.pointsto.PointsTo import semmle.python.pointsto.PointsToContext from ControlFlowNode f, Object o, ClassObject c, ControlFlowNode x, PointsToContext ctx - where PointsTo::points_to(f, ctx, o, c, x) - -select locate(f.getLocation(), "abeghijklmnpqrstu"), f.toString(), repr(o), repr(c), x.getLocation().getStartLine(), ctx +select locate(f.getLocation(), "abeghijklmnpqrstu"), f.toString(), repr(o), repr(c), + x.getLocation().getStartLine(), ctx diff --git a/python/ql/test/library-tests/PointsTo/new/PointsToWithType.ql b/python/ql/test/library-tests/PointsTo/new/PointsToWithType.ql index 0c845f6bc3c..ed04a0b3dc3 100644 --- a/python/ql/test/library-tests/PointsTo/new/PointsToWithType.ql +++ b/python/ql/test/library-tests/PointsTo/new/PointsToWithType.ql @@ -3,7 +3,6 @@ import Util import semmle.python.pointsto.PointsTo from ControlFlowNode f, Object o, ClassObject c, ControlFlowNode x - where PointsTo::points_to(f, _, o, c, x) - -select locate(f.getLocation(), "abdeghijkls"), f.toString(), repr(o), repr(c), x.getLocation().getStartLine() +select locate(f.getLocation(), "abdeghijkls"), f.toString(), repr(o), repr(c), + x.getLocation().getStartLine() diff --git a/python/ql/test/library-tests/PointsTo/new/Precedes.ql b/python/ql/test/library-tests/PointsTo/new/Precedes.ql index 959ec181f5f..bda245eca6d 100644 --- a/python/ql/test/library-tests/PointsTo/new/Precedes.ql +++ b/python/ql/test/library-tests/PointsTo/new/Precedes.ql @@ -1,8 +1,7 @@ - import python import Util from Scope pre, Scope post where pre.precedes(post) - -select locate(pre.getLocation(), "q"), pre.toString(), locate(post.getLocation(), "q"), post.toString() +select locate(pre.getLocation(), "q"), pre.toString(), locate(post.getLocation(), "q"), + post.toString() diff --git a/python/ql/test/library-tests/PointsTo/new/Reachable.ql b/python/ql/test/library-tests/PointsTo/new/Reachable.ql index 577d724c8e6..f8b2f0585eb 100644 --- a/python/ql/test/library-tests/PointsTo/new/Reachable.ql +++ b/python/ql/test/library-tests/PointsTo/new/Reachable.ql @@ -1,4 +1,3 @@ - import python private import semmle.python.pointsto.PointsTo import Util diff --git a/python/ql/test/library-tests/PointsTo/new/SSA.ql b/python/ql/test/library-tests/PointsTo/new/SSA.ql index 6c30a5f031f..6c154f57e57 100644 --- a/python/ql/test/library-tests/PointsTo/new/SSA.ql +++ b/python/ql/test/library-tests/PointsTo/new/SSA.ql @@ -1,11 +1,12 @@ - import python private import semmle.python.pointsto.PointsTo private import semmle.python.pointsto.PointsToContext import Util from EssaVariable v, EssaDefinition def, Object o, ClassObject cls -where def = v.getDefinition() and -not v.getSourceVariable() instanceof SpecialSsaSourceVariable and -PointsTo::ssa_variable_points_to(v, _, o, cls, _) -select locate(def.getLocation(), "abcdegjqmns_"), v.getRepresentation() + " = " + def.getRepresentation(), repr(o), repr(cls) +where + def = v.getDefinition() and + not v.getSourceVariable() instanceof SpecialSsaSourceVariable and + PointsTo::ssa_variable_points_to(v, _, o, cls, _) +select locate(def.getLocation(), "abcdegjqmns_"), + v.getRepresentation() + " = " + def.getRepresentation(), repr(o), repr(cls) diff --git a/python/ql/test/library-tests/PointsTo/new/Sanity.ql b/python/ql/test/library-tests/PointsTo/new/Sanity.ql index 5559354362c..8c3347f6682 100644 --- a/python/ql/test/library-tests/PointsTo/new/Sanity.ql +++ b/python/ql/test/library-tests/PointsTo/new/Sanity.ql @@ -1,98 +1,119 @@ - import python import semmle.python.pointsto.PointsTo import semmle.python.objects.ObjectInternal predicate ssa_sanity(string clsname, string problem, string what) { /* Exactly one definition of each SSA variable */ - exists(EssaVariable var | - clsname = var.getAQlClass() | + exists(EssaVariable var | clsname = var.getAQlClass() | /* Exactly one definition of each SSA variable */ - count(var.getDefinition()) != 1 and problem = " has " + count(var.getDefinition()) + " definitions." and + count(var.getDefinition()) != 1 and + problem = " has " + count(var.getDefinition()) + " definitions." and what = "SSA variable " + var.getSourceVariable().getName() or /* Backing variable */ - not exists(var.getSourceVariable()) and problem = "An SSA variable has no backing variable." and + not exists(var.getSourceVariable()) and + problem = "An SSA variable has no backing variable." and what = "An SSA variable" or - count(var.getSourceVariable()) != 1 and problem = var.getSourceVariable().getName() + " has " + count(var.getSourceVariable()) + " backing variables." and + count(var.getSourceVariable()) != 1 and + problem = + var.getSourceVariable().getName() + " has " + count(var.getSourceVariable()) + + " backing variables." and what = "SSA variable " + var.getSourceVariable().getName() ) or /* Exactly one location */ exists(EssaDefinition def | clsname = def.getAQlClass() and - what = "SSA Definition " + def.getSourceVariable().getName() + " in " + def.getSourceVariable().(Variable).getScope().getName() and - count(def.getLocation()) != 1 and problem = " has " + count(def.getLocation()) + " locations" + what = + "SSA Definition " + def.getSourceVariable().getName() + " in " + + def.getSourceVariable().(Variable).getScope().getName() and + count(def.getLocation()) != 1 and + problem = " has " + count(def.getLocation()) + " locations" ) or /* Must have a source variable */ exists(EssaDefinition def | clsname = def.getAQlClass() and not exists(def.getSourceVariable()) and - what = " at " + def.getLocation() and + what = " at " + def.getLocation() and problem = "has not source variable" ) - or + or /* Variables must have exactly one representation */ exists(EssaVariable var | clsname = var.getAQlClass() and - what = "SSA variable " + var.getSourceVariable().getName() + " defined at " + var.getDefinition().getLocation() and - count(var.getRepresentation()) != 1 and problem = " has " + count(var.getRepresentation()) + " representations" + what = + "SSA variable " + var.getSourceVariable().getName() + " defined at " + + var.getDefinition().getLocation() and + count(var.getRepresentation()) != 1 and + problem = " has " + count(var.getRepresentation()) + " representations" ) or /* Definitions must have exactly one representation */ exists(EssaDefinition def | clsname = def.getAQlClass() and what = "SSA definition " + def.getSourceVariable().getName() + " at " + def.getLocation() and - count(def.getRepresentation()) != 1 and problem = " has " + count(def.getRepresentation()) + " representations: " + def.getRepresentation() + count(def.getRepresentation()) != 1 and + problem = + " has " + count(def.getRepresentation()) + " representations: " + def.getRepresentation() ) or /* Refinements must have exactly one input */ exists(EssaNodeRefinement ref | clsname = ref.getAQlClass() and what = "Refinement " + ref.getSourceVariable().getName() + " at " + ref.getLocation() and - count(ref.getInput()) != 1 and problem = " has " + count(ref.getInput()) + " inputs: " + ref.getInput().getRepresentation() + count(ref.getInput()) != 1 and + problem = " has " + count(ref.getInput()) + " inputs: " + ref.getInput().getRepresentation() ) or - /* Ideally filter nodes should have exactly one input, but it is not a big deal - * if we prune away the input, leaving it with none. */ + /* + * Ideally filter nodes should have exactly one input, but it is not a big deal + * if we prune away the input, leaving it with none. + */ + exists(EssaEdgeRefinement def | clsname = def.getAQlClass() and - what = def.getSourceVariable().getName() + " at " + def.getLocation() | - count(def.getInput()) > 1 and problem =" has " + count(def.getInput()) + " inputs." + what = def.getSourceVariable().getName() + " at " + def.getLocation() + | + count(def.getInput()) > 1 and problem = " has " + count(def.getInput()) + " inputs." ) or /* Each use has only one reaching SSA variable */ exists(ControlFlowNode use, SsaSourceVariable v, int c | c = strictcount(EssaVariable s | s.getAUse() = use and s.getSourceVariable() = v) and - clsname = use.getAQlClass() and c != 1 and - what = use + " at " + use.getLocation() and - problem =" has " + c + " SSA variables reaching." + clsname = use.getAQlClass() and + c != 1 and + what = use + " at " + use.getLocation() and + problem = " has " + c + " SSA variables reaching." ) or /* Python-specific subclasses of EssaDefinitions should be disjoint and complete */ exists(EssaDefinition def | clsname = def.getAQlClass() and - what = def.getVariable().getName() + " at " + def.getLocation() and - problem = "has non-disjoint subclasses" | - strictcount(def.getAQlClass()) > 2 or + what = def.getVariable().getName() + " at " + def.getLocation() and + problem = "has non-disjoint subclasses" + | + strictcount(def.getAQlClass()) > 2 + or /* OK if method call and argument overlap: `x.foo(x)` */ strictcount(def.getAQlClass()) > 1 and - not clsname = "ArgumentRefinement" and not clsname = "SelfCallsiteRefinement" + not clsname = "ArgumentRefinement" and + not clsname = "SelfCallsiteRefinement" ) or exists(EssaDefinition def | clsname = def.getAQlClass() and clsname.prefix(4) = "Essa" and - what = " at " + def.getLocation() and + what = " at " + def.getLocation() and problem = "not covered by Python-specific subclass." ) or // All modules should have __name__ exists(Module m | - what = " at " + m.getLocation() and - clsname = "Module" | + what = " at " + m.getLocation() and + clsname = "Module" + | not exists(m.getName()) and problem = "does not have a name" or @@ -113,7 +134,8 @@ predicate undefined_sanity(string clsname, string problem, string what) { /* Variables may be undefined, but values cannot be */ exists(ControlFlowNode f | PointsToInternal::pointsTo(f, _, ObjectInternal::undefined(), _) and - clsname = f.getAQlClass() and not clsname = "AnyNode" and + clsname = f.getAQlClass() and + not clsname = "AnyNode" and problem = " points-to an undefined variable" and what = f.toString() ) @@ -122,4 +144,3 @@ predicate undefined_sanity(string clsname, string problem, string what) { from string clsname, string problem, string what where ssa_sanity(clsname, problem, what) or undefined_sanity(clsname, problem, what) select clsname, what, problem - diff --git a/python/ql/test/library-tests/PointsTo/new/SourceEdgeDefinitions.ql b/python/ql/test/library-tests/PointsTo/new/SourceEdgeDefinitions.ql index 08928b0c9f0..8cf0b4c15a6 100644 --- a/python/ql/test/library-tests/PointsTo/new/SourceEdgeDefinitions.ql +++ b/python/ql/test/library-tests/PointsTo/new/SourceEdgeDefinitions.ql @@ -1,7 +1,5 @@ - import python import semmle.python.pointsto.PointsTo - import Util from SsaSourceVariable var, ControlFlowNode use, BasicBlock pred diff --git a/python/ql/test/library-tests/PointsTo/new/SourceNodeDefinitions.ql b/python/ql/test/library-tests/PointsTo/new/SourceNodeDefinitions.ql index 53e5d69953e..a1547da65c6 100644 --- a/python/ql/test/library-tests/PointsTo/new/SourceNodeDefinitions.ql +++ b/python/ql/test/library-tests/PointsTo/new/SourceNodeDefinitions.ql @@ -1,14 +1,13 @@ - import python import semmle.python.pointsto.PointsTo - import Util from SsaSourceVariable var, ControlFlowNode defn, string kind -where not var instanceof SpecialSsaSourceVariable and -( - var.hasDefiningNode(defn) and kind = "definition" - or - var.hasRefinement(_, defn) and kind = "refinement" -) +where + not var instanceof SpecialSsaSourceVariable and + ( + var.hasDefiningNode(defn) and kind = "definition" + or + var.hasRefinement(_, defn) and kind = "refinement" + ) select locate(defn.getLocation(), "ab"), var.(Variable), defn.toString(), kind diff --git a/python/ql/test/library-tests/PointsTo/new/SsaAttr.ql b/python/ql/test/library-tests/PointsTo/new/SsaAttr.ql index 4a4d83160c3..dc71ac5df65 100644 --- a/python/ql/test/library-tests/PointsTo/new/SsaAttr.ql +++ b/python/ql/test/library-tests/PointsTo/new/SsaAttr.ql @@ -1,12 +1,11 @@ - import python private import semmle.python.pointsto.PointsTo private import semmle.python.objects.ObjectInternal import Util from EssaVariable var, string name, ObjectInternal o, Context ctx -where AttributePointsTo::variableAttributePointsTo(var, ctx, name, o, _) and not var.getSourceVariable() instanceof SpecialSsaSourceVariable -select -locate(var.getDefinition().getLocation(), "abdfgikm"), var.getRepresentation(), -name, var.getDefinition().getRepresentation(), o, ctx - +where + AttributePointsTo::variableAttributePointsTo(var, ctx, name, o, _) and + not var.getSourceVariable() instanceof SpecialSsaSourceVariable +select locate(var.getDefinition().getLocation(), "abdfgikm"), var.getRepresentation(), name, + var.getDefinition().getRepresentation(), o, ctx diff --git a/python/ql/test/library-tests/PointsTo/new/SsaUses.ql b/python/ql/test/library-tests/PointsTo/new/SsaUses.ql index 9c01da90a59..2a8e8f1e750 100644 --- a/python/ql/test/library-tests/PointsTo/new/SsaUses.ql +++ b/python/ql/test/library-tests/PointsTo/new/SsaUses.ql @@ -1,4 +1,3 @@ - import python import semmle.python.pointsto.PointsTo import Util diff --git a/python/ql/test/library-tests/PointsTo/new/TestEvaluate.ql b/python/ql/test/library-tests/PointsTo/new/TestEvaluate.ql index 0a17a3e118a..2367df63b63 100644 --- a/python/ql/test/library-tests/PointsTo/new/TestEvaluate.ql +++ b/python/ql/test/library-tests/PointsTo/new/TestEvaluate.ql @@ -1,19 +1,19 @@ - import python import semmle.python.pointsto.PointsTo import semmle.python.pointsto.PointsToContext import Util - -from ControlFlowNode test, ControlFlowNode use, ObjectInternal val, boolean eval, PointsToContext ctx, ControlFlowNode origin, string what -where -not use instanceof NameConstantNode and -not use.getNode() instanceof ImmutableLiteral and -eval = Conditionals::testEvaluates(test, use, ctx, val, origin) and -( - what = val.getSource().(Object).toString() - or - not exists(val.getSource()) and what = origin.getNode().toString() -) -select locate(test.getLocation(), "bc"), test.getNode().toString(), eval.toString(), use.getNode().toString(), what - +from + ControlFlowNode test, ControlFlowNode use, ObjectInternal val, boolean eval, PointsToContext ctx, + ControlFlowNode origin, string what +where + not use instanceof NameConstantNode and + not use.getNode() instanceof ImmutableLiteral and + eval = Conditionals::testEvaluates(test, use, ctx, val, origin) and + ( + what = val.getSource().(Object).toString() + or + not exists(val.getSource()) and what = origin.getNode().toString() + ) +select locate(test.getLocation(), "bc"), test.getNode().toString(), eval.toString(), + use.getNode().toString(), what diff --git a/python/ql/test/library-tests/PointsTo/new/Values.ql b/python/ql/test/library-tests/PointsTo/new/Values.ql index 8e6bd9c9f00..754fcfede54 100644 --- a/python/ql/test/library-tests/PointsTo/new/Values.ql +++ b/python/ql/test/library-tests/PointsTo/new/Values.ql @@ -1,9 +1,7 @@ - import python import Util - from ControlFlowNode f, Context ctx, Value v, ControlFlowNode origin -where - f.pointsTo(ctx, v, origin) -select locate(f.getLocation(), "abeghijklmnpqrstu"), f.toString(), ctx, vrepr(v), vrepr(v.getClass()) +where f.pointsTo(ctx, v, origin) +select locate(f.getLocation(), "abeghijklmnpqrstu"), f.toString(), ctx, vrepr(v), + vrepr(v.getClass()) diff --git a/python/ql/test/library-tests/PointsTo/new/VarUses.ql b/python/ql/test/library-tests/PointsTo/new/VarUses.ql index a8ef096821e..56c1ca637a1 100644 --- a/python/ql/test/library-tests/PointsTo/new/VarUses.ql +++ b/python/ql/test/library-tests/PointsTo/new/VarUses.ql @@ -1,8 +1,9 @@ - import python import semmle.python.pointsto.PointsTo import Util from SsaSourceVariable var, ControlFlowNode use -where (use = var.getAUse() or var.hasRefinement(use, _)) and not var instanceof SpecialSsaSourceVariable +where + (use = var.getAUse() or var.hasRefinement(use, _)) and + not var instanceof SpecialSsaSourceVariable select locate(use.getLocation(), "abd"), var.getName(), use.toString() diff --git a/python/ql/test/library-tests/PointsTo/properties/Lookup.ql b/python/ql/test/library-tests/PointsTo/properties/Lookup.ql index 10c32412d85..d7820250723 100644 --- a/python/ql/test/library-tests/PointsTo/properties/Lookup.ql +++ b/python/ql/test/library-tests/PointsTo/properties/Lookup.ql @@ -1,4 +1,3 @@ - import python import semmle.python.pointsto.PointsTo import semmle.python.objects.ObjectInternal diff --git a/python/ql/test/library-tests/PointsTo/properties/Values.ql b/python/ql/test/library-tests/PointsTo/properties/Values.ql index 0173d7d6219..597a54cb641 100644 --- a/python/ql/test/library-tests/PointsTo/properties/Values.ql +++ b/python/ql/test/library-tests/PointsTo/properties/Values.ql @@ -1,4 +1,3 @@ - import python import semmle.python.objects.ObjectInternal @@ -10,6 +9,5 @@ string vrepr(Value v) { } from ControlFlowNode f, Context ctx, Value v, ControlFlowNode origin -where - f.pointsTo(ctx, v, origin) +where f.pointsTo(ctx, v, origin) select f.getLocation(), f.toString(), ctx, vrepr(v), vrepr(v.getClass()) diff --git a/python/ql/test/library-tests/PointsTo/returns/Test.ql b/python/ql/test/library-tests/PointsTo/returns/Test.ql index a30d0ef1c76..8546de90f24 100644 --- a/python/ql/test/library-tests/PointsTo/returns/Test.ql +++ b/python/ql/test/library-tests/PointsTo/returns/Test.ql @@ -1,4 +1,4 @@ import python from PyFunctionObject f -select f.toString(), f.getAnInferredReturnType().toString() \ No newline at end of file +select f.toString(), f.getAnInferredReturnType().toString() diff --git a/python/ql/test/library-tests/PointsTo/subclass/Checks.ql b/python/ql/test/library-tests/PointsTo/subclass/Checks.ql index b164406276e..a82002b1d5f 100644 --- a/python/ql/test/library-tests/PointsTo/subclass/Checks.ql +++ b/python/ql/test/library-tests/PointsTo/subclass/Checks.ql @@ -1,7 +1,6 @@ - import python import semmle.python.pointsto.PointsTo -from Value sup, Value cls +from Value sup, Value cls where Expressions::requireSubClass(cls, sup) select cls, sup diff --git a/python/ql/test/library-tests/PointsTo/subclass/TestEvaluate.ql b/python/ql/test/library-tests/PointsTo/subclass/TestEvaluate.ql index fd32bfcbe64..0f197edeb0a 100644 --- a/python/ql/test/library-tests/PointsTo/subclass/TestEvaluate.ql +++ b/python/ql/test/library-tests/PointsTo/subclass/TestEvaluate.ql @@ -1,12 +1,12 @@ - import python import semmle.python.pointsto.PointsTo import semmle.python.objects.ObjectInternal import semmle.python.pointsto.PointsToContext - -from ControlFlowNode test, ControlFlowNode use, ObjectInternal val, boolean eval, PointsToContext ctx +from + ControlFlowNode test, ControlFlowNode use, ObjectInternal val, boolean eval, PointsToContext ctx where -PointsTo::pointsTo(use, ctx, val, _) and -eval = Conditionals::testEvaluates(test, use, ctx, val, _) -select test.getLocation().getStartLine(), test.getNode().toString(), eval.toString(), use.getNode().toString(), val.toString() + PointsTo::pointsTo(use, ctx, val, _) and + eval = Conditionals::testEvaluates(test, use, ctx, val, _) +select test.getLocation().getStartLine(), test.getNode().toString(), eval.toString(), + use.getNode().toString(), val.toString() diff --git a/python/ql/test/library-tests/PointsTo/subclass/Values.ql b/python/ql/test/library-tests/PointsTo/subclass/Values.ql index 3246ef02764..c50e25c5f36 100644 --- a/python/ql/test/library-tests/PointsTo/subclass/Values.ql +++ b/python/ql/test/library-tests/PointsTo/subclass/Values.ql @@ -1,10 +1,7 @@ - import python import semmle.python.pointsto.PointsTo import semmle.python.objects.ObjectInternal from ControlFlowNode f, ObjectInternal v, ControlFlowNode x - where PointsTo::pointsTo(f, _, v, x) - select f.getLocation().getStartLine(), f.toString(), v, x.getLocation().getStartLine() diff --git a/python/ql/test/library-tests/PointsTo/super/SuperMethodCall.ql b/python/ql/test/library-tests/PointsTo/super/SuperMethodCall.ql index f21b102338f..6245b56f711 100644 --- a/python/ql/test/library-tests/PointsTo/super/SuperMethodCall.ql +++ b/python/ql/test/library-tests/PointsTo/super/SuperMethodCall.ql @@ -1,10 +1,11 @@ - import python import semmle.python.pointsto.PointsTo import semmle.python.pointsto.PointsToContext import semmle.python.objects.ObjectInternal from CallNode call, SuperInstance sup, BoundMethodObjectInternal bm -where call.getFunction().inferredValue() = bm and -call.getFunction().(AttrNode).getObject().inferredValue() = sup -select call.getLocation().getStartLine(), call.toString(), bm.getFunction().getSource().(FunctionObject).getQualifiedName() \ No newline at end of file +where + call.getFunction().inferredValue() = bm and + call.getFunction().(AttrNode).getObject().inferredValue() = sup +select call.getLocation().getStartLine(), call.toString(), + bm.getFunction().getSource().(FunctionObject).getQualifiedName() diff --git a/python/ql/test/library-tests/attributes/SelfAttribute.ql b/python/ql/test/library-tests/attributes/SelfAttribute.ql index 0ccfe5a397c..7ac995d2061 100644 --- a/python/ql/test/library-tests/attributes/SelfAttribute.ql +++ b/python/ql/test/library-tests/attributes/SelfAttribute.ql @@ -1,11 +1,9 @@ - import python import semmle.python.SelfAttribute from SelfAttributeRead sa, int line, string g, string l where -line = sa.getLocation().getStartLine() and -if sa.guardedByHasattr() then g = "guarded" else g = "" and - -if sa.locallyDefined() then l = "defined" else l = "" + line = sa.getLocation().getStartLine() and + (if sa.guardedByHasattr() then g = "guarded" else g = "") and + if sa.locallyDefined() then l = "defined" else l = "" select line, sa.getName(), g + l diff --git a/python/ql/test/library-tests/classes/abstract/Abstract.ql b/python/ql/test/library-tests/classes/abstract/Abstract.ql index 1117bc95790..6773bb22785 100644 --- a/python/ql/test/library-tests/classes/abstract/Abstract.ql +++ b/python/ql/test/library-tests/classes/abstract/Abstract.ql @@ -1,12 +1,7 @@ - import python from ClassObject cls, string abstract where -not cls.isBuiltin() and -if cls.isAbstract() then - abstract = "yes" -else - abstract = "no" - + not cls.isBuiltin() and + if cls.isAbstract() then abstract = "yes" else abstract = "no" select cls.toString(), abstract diff --git a/python/ql/test/library-tests/classes/attr/class_attr.ql b/python/ql/test/library-tests/classes/attr/class_attr.ql index 0b283debd5d..3b7bf8b3ba0 100644 --- a/python/ql/test/library-tests/classes/attr/class_attr.ql +++ b/python/ql/test/library-tests/classes/attr/class_attr.ql @@ -7,7 +7,9 @@ import python from ClassObject cls, int line, string name, Object obj -where cls.hasLocationInfo(_, line, _, _, _) -and obj = cls.lookupAttribute(name) and -not cls.isC() and not name.matches("\\_\\_%\\_\\_") -select line, cls.toString(), name, obj.toString() \ No newline at end of file +where + cls.hasLocationInfo(_, line, _, _, _) and + obj = cls.lookupAttribute(name) and + not cls.isC() and + not name.matches("\\_\\_%\\_\\_") +select line, cls.toString(), name, obj.toString() diff --git a/python/ql/test/library-tests/classes/attr/class_defined_attr.ql b/python/ql/test/library-tests/classes/attr/class_defined_attr.ql index 843b1ed2b3a..ec798dcf190 100644 --- a/python/ql/test/library-tests/classes/attr/class_defined_attr.ql +++ b/python/ql/test/library-tests/classes/attr/class_defined_attr.ql @@ -7,7 +7,9 @@ import python from ClassObject cls, int line, string name, Object obj -where cls.hasLocationInfo(_, line, _, _, _) -and obj = cls.declaredAttribute(name) and -not cls.isC() and not name.matches("\\_\\_%\\_\\_") +where + cls.hasLocationInfo(_, line, _, _, _) and + obj = cls.declaredAttribute(name) and + not cls.isC() and + not name.matches("\\_\\_%\\_\\_") select line, cls.toString(), name, obj.toString() diff --git a/python/ql/test/library-tests/classes/attr/class_defines_attr.ql b/python/ql/test/library-tests/classes/attr/class_defines_attr.ql index e9cfdee5ccd..858d3e49e20 100644 --- a/python/ql/test/library-tests/classes/attr/class_defines_attr.ql +++ b/python/ql/test/library-tests/classes/attr/class_defines_attr.ql @@ -7,7 +7,9 @@ import python from ClassObject cls, int line, string name -where cls.hasLocationInfo(_, line, _, _, _) -and cls.declaresAttribute(name) and -not cls.isC() and not name.matches("\\_\\_%\\_\\_") +where + cls.hasLocationInfo(_, line, _, _, _) and + cls.declaresAttribute(name) and + not cls.isC() and + not name.matches("\\_\\_%\\_\\_") select line, cls.toString(), name diff --git a/python/ql/test/library-tests/classes/attr/class_has_attr.ql b/python/ql/test/library-tests/classes/attr/class_has_attr.ql index a274a1dd95b..2f16aa4ca97 100644 --- a/python/ql/test/library-tests/classes/attr/class_has_attr.ql +++ b/python/ql/test/library-tests/classes/attr/class_has_attr.ql @@ -7,7 +7,9 @@ import python from ClassObject cls, int line, string name -where cls.hasLocationInfo(_, line, _, _, _) -and cls.hasAttribute(name) and -not cls.isC() and not name.matches("\\_\\_%\\_\\_") +where + cls.hasLocationInfo(_, line, _, _, _) and + cls.hasAttribute(name) and + not cls.isC() and + not name.matches("\\_\\_%\\_\\_") select line, cls.toString(), name diff --git a/python/ql/test/library-tests/classes/attr/hash.ql b/python/ql/test/library-tests/classes/attr/hash.ql index b4485634cce..a8ccf6c9d6b 100644 --- a/python/ql/test/library-tests/classes/attr/hash.ql +++ b/python/ql/test/library-tests/classes/attr/hash.ql @@ -7,9 +7,10 @@ import python from ClassObject cls, int line, Object obj -where cls.hasLocationInfo(_, line, _, _, _) -and obj = cls.lookupAttribute("__hash__") and -not cls.isC() and -not obj = theObjectType().lookupAttribute("__hash__") and -not obj = theTypeType().lookupAttribute("__hash__") -select line, cls.toString(), obj.toString() \ No newline at end of file +where + cls.hasLocationInfo(_, line, _, _, _) and + obj = cls.lookupAttribute("__hash__") and + not cls.isC() and + not obj = theObjectType().lookupAttribute("__hash__") and + not obj = theTypeType().lookupAttribute("__hash__") +select line, cls.toString(), obj.toString() diff --git a/python/ql/test/library-tests/classes/mro/C3.ql b/python/ql/test/library-tests/classes/mro/C3.ql index e433971f1eb..981a55893c2 100644 --- a/python/ql/test/library-tests/classes/mro/C3.ql +++ b/python/ql/test/library-tests/classes/mro/C3.ql @@ -1,9 +1,6 @@ - import python import semmle.python.pointsto.MRO from ClassValue cls where not cls.isBuiltin() - select cls.toString(), Mro::newStyleMro(cls) - diff --git a/python/ql/test/library-tests/comments/blocks.ql b/python/ql/test/library-tests/comments/blocks.ql index 3fbb6946c02..ac306cb3f44 100644 --- a/python/ql/test/library-tests/comments/blocks.ql +++ b/python/ql/test/library-tests/comments/blocks.ql @@ -10,4 +10,4 @@ import Lexical.CommentedOutCode from CommentedOutCodeBlock c, int bl, int el where c.hasLocationInfo(_, bl, _, el, _) -select bl, el, c.toString() \ No newline at end of file +select bl, el, c.toString() diff --git a/python/ql/test/library-tests/comments/blocks_not_example.ql b/python/ql/test/library-tests/comments/blocks_not_example.ql index ccc8c0ba50b..19ed6283a3e 100644 --- a/python/ql/test/library-tests/comments/blocks_not_example.ql +++ b/python/ql/test/library-tests/comments/blocks_not_example.ql @@ -1,7 +1,6 @@ - import python import Lexical.CommentedOutCode from CommentedOutCodeBlock c, int bl, int el where c.hasLocationInfo(_, bl, _, el, _) and not c.maybeExampleCode() -select bl, el, c.toString() \ No newline at end of file +select bl, el, c.toString() diff --git a/python/ql/test/library-tests/comments/length.ql b/python/ql/test/library-tests/comments/length.ql index 53d514e6b33..0a15328c35e 100644 --- a/python/ql/test/library-tests/comments/length.ql +++ b/python/ql/test/library-tests/comments/length.ql @@ -1,8 +1,8 @@ - import python import Lexical.CommentedOutCode from CommentBlock block, int line, boolean code -where block.hasLocationInfo(_, line, _, _, _) and -if block instanceof CommentedOutCodeBlock then code = true else code = false +where + block.hasLocationInfo(_, line, _, _, _) and + if block instanceof CommentedOutCodeBlock then code = true else code = false select line, block.length(), code diff --git a/python/ql/test/library-tests/comments/lines.ql b/python/ql/test/library-tests/comments/lines.ql index a07d2ac1953..d71eb039129 100644 --- a/python/ql/test/library-tests/comments/lines.ql +++ b/python/ql/test/library-tests/comments/lines.ql @@ -1,7 +1,6 @@ - import python import Lexical.CommentedOutCode from CommentedOutCodeLine c, int l where l = c.getLocation().getStartLine() -select l, c.toString() \ No newline at end of file +select l, c.toString() diff --git a/python/ql/test/library-tests/comments/lines_not_example.ql b/python/ql/test/library-tests/comments/lines_not_example.ql index e6fcaab9d93..2fa0dec3a4e 100644 --- a/python/ql/test/library-tests/comments/lines_not_example.ql +++ b/python/ql/test/library-tests/comments/lines_not_example.ql @@ -1,7 +1,6 @@ - import python import Lexical.CommentedOutCode from CommentedOutCodeLine c, int l where l = c.getLocation().getStartLine() and not c.maybeExampleCode() -select l, c.toString() \ No newline at end of file +select l, c.toString() diff --git a/python/ql/test/library-tests/comments/type_hint.ql b/python/ql/test/library-tests/comments/type_hint.ql index 55ec57c0d5b..26511a2d97f 100644 --- a/python/ql/test/library-tests/comments/type_hint.ql +++ b/python/ql/test/library-tests/comments/type_hint.ql @@ -1,6 +1,4 @@ - import python from TypeHintComment c select c.getLocation().toString(), c.getText() - diff --git a/python/ql/test/library-tests/comparisons/Compare.ql b/python/ql/test/library-tests/comparisons/Compare.ql index 84d97bbbbe2..558da6fc6d7 100644 --- a/python/ql/test/library-tests/comparisons/Compare.ql +++ b/python/ql/test/library-tests/comparisons/Compare.ql @@ -1,9 +1,6 @@ - import python - import semmle.python.Comparisons from Comparison c, ControlFlowNode l, CompareOp op, float k -where -c.tests(l, op, k) +where c.tests(l, op, k) select c.getLocation().getStartLine(), l + " " + op.repr() + " " + k diff --git a/python/ql/test/library-tests/comparisons/Compare2.ql b/python/ql/test/library-tests/comparisons/Compare2.ql index 70d954a4b0e..ade279c9efd 100644 --- a/python/ql/test/library-tests/comparisons/Compare2.ql +++ b/python/ql/test/library-tests/comparisons/Compare2.ql @@ -1,11 +1,12 @@ - import python - import semmle.python.Comparisons from Comparison c, NameNode l, CompareOp op, NameNode r, float k, string add -where -c.tests(l, op, r, k) -and -(k < 0 and add = "" or k >= 0 and add = "+") +where + c.tests(l, op, r, k) and + ( + k < 0 and add = "" + or + k >= 0 and add = "+" + ) select c.getLocation().getStartLine(), l.getId() + " " + op.repr() + " " + r.getId() + add + k diff --git a/python/ql/test/library-tests/comparisons/CompareControls.ql b/python/ql/test/library-tests/comparisons/CompareControls.ql index 01b35c0ffad..b803e40dfed 100644 --- a/python/ql/test/library-tests/comparisons/CompareControls.ql +++ b/python/ql/test/library-tests/comparisons/CompareControls.ql @@ -1,10 +1,7 @@ - import python - import semmle.python.Comparisons from ComparisonControlBlock comp, SsaVariable v, CompareOp op, float k, BasicBlock b -where -comp.controls(v.getAUse(), op, k, b) - -select comp.getTest().getLocation().getStartLine(), v.getId() + " " + op.repr() + " " + k, b.getNode(0).getLocation().getStartLine() +where comp.controls(v.getAUse(), op, k, b) +select comp.getTest().getLocation().getStartLine(), v.getId() + " " + op.repr() + " " + k, + b.getNode(0).getLocation().getStartLine() diff --git a/python/ql/test/library-tests/comparisons/Implication.ql b/python/ql/test/library-tests/comparisons/Implication.ql index f24d1d42234..f94d8ba184a 100644 --- a/python/ql/test/library-tests/comparisons/Implication.ql +++ b/python/ql/test/library-tests/comparisons/Implication.ql @@ -1,9 +1,6 @@ - import python import semmle.python.Comparisons from Comparison a, Comparison that, boolean thisIsTrue, boolean thatIsTrue - where a.impliesThat(thisIsTrue, that, thatIsTrue) - -select a.getLocation().getStartLine(), thisIsTrue, that.getLocation().getStartLine(), thatIsTrue \ No newline at end of file +select a.getLocation().getStartLine(), thisIsTrue, that.getLocation().getStartLine(), thatIsTrue diff --git a/python/ql/test/library-tests/comprehensions/Flow.ql b/python/ql/test/library-tests/comprehensions/Flow.ql index e19d4d75abe..5fd3a0cc61c 100644 --- a/python/ql/test/library-tests/comprehensions/Flow.ql +++ b/python/ql/test/library-tests/comprehensions/Flow.ql @@ -2,4 +2,4 @@ import python from ControlFlowNode p, ControlFlowNode s where p.getASuccessor() = s -select p.getLocation().getStartLine(), p.toString(), s.getLocation().getStartLine(), s.toString() \ No newline at end of file +select p.getLocation().getStartLine(), p.toString(), s.getLocation().getStartLine(), s.toString() diff --git a/python/ql/test/library-tests/dependencies/Dependencies.ql b/python/ql/test/library-tests/dependencies/Dependencies.ql index b5bedbe7b3c..cab84c4417b 100644 --- a/python/ql/test/library-tests/dependencies/Dependencies.ql +++ b/python/ql/test/library-tests/dependencies/Dependencies.ql @@ -1,8 +1,7 @@ - import python import semmle.python.dependencies.Dependencies from DependencyKind dk, AstNode src, Object target where dk.isADependency(src, target) -select dk.toString(), src.getLocation().getFile().getShortName(), src.getLocation().getStartLine(), src.toString(), target.toString() - +select dk.toString(), src.getLocation().getFile().getShortName(), src.getLocation().getStartLine(), + src.toString(), target.toString() diff --git a/python/ql/test/library-tests/descriptors/Descriptors.ql b/python/ql/test/library-tests/descriptors/Descriptors.ql index 658091bfe4e..dd97b623f7f 100644 --- a/python/ql/test/library-tests/descriptors/Descriptors.ql +++ b/python/ql/test/library-tests/descriptors/Descriptors.ql @@ -1,13 +1,9 @@ - import python from ClassObject cls, string kind -where cls.isDescriptorType() and -/* Exclude bound-method as its name differs between 2 and 3 */ -not cls = theBoundMethodType() and -(if cls.isOverridingDescriptorType() then - kind = "overriding" - else - kind = "non-overriding" -) -select cls.toString(), kind \ No newline at end of file +where + cls.isDescriptorType() and + /* Exclude bound-method as its name differs between 2 and 3 */ + not cls = theBoundMethodType() and + (if cls.isOverridingDescriptorType() then kind = "overriding" else kind = "non-overriding") +select cls.toString(), kind diff --git a/python/ql/test/library-tests/descriptors/Methods.ql b/python/ql/test/library-tests/descriptors/Methods.ql index 75d3092198d..4a2ec39d70c 100644 --- a/python/ql/test/library-tests/descriptors/Methods.ql +++ b/python/ql/test/library-tests/descriptors/Methods.ql @@ -1,15 +1,11 @@ - import python import semmle.python.types.Descriptors -int lineof(Object o) { - result = o.getOrigin().getLocation().getStartLine() -} +int lineof(Object o) { result = o.getOrigin().getLocation().getStartLine() } from Object m, FunctionObject f -where - m.(ClassMethodObject).getFunction() = f - or - m.(StaticMethodObject).getFunction() = f +where + m.(ClassMethodObject).getFunction() = f + or + m.(StaticMethodObject).getFunction() = f select lineof(m), m.toString(), lineof(f), f.toString() - diff --git a/python/ql/test/library-tests/encoding/CheckEncoding.ql b/python/ql/test/library-tests/encoding/CheckEncoding.ql index 88e8a580027..60fc167e293 100644 --- a/python/ql/test/library-tests/encoding/CheckEncoding.ql +++ b/python/ql/test/library-tests/encoding/CheckEncoding.ql @@ -2,7 +2,7 @@ import python from File f, string encoding where -encoding = f.getSpecifiedEncoding() -or -not exists(f.getSpecifiedEncoding()) and encoding = "none" + encoding = f.getSpecifiedEncoding() + or + not exists(f.getSpecifiedEncoding()) and encoding = "none" select f.getAbsolutePath(), encoding diff --git a/python/ql/test/library-tests/exceptions/Handles.ql b/python/ql/test/library-tests/exceptions/Handles.ql index 989126b7127..620944de5b9 100644 --- a/python/ql/test/library-tests/exceptions/Handles.ql +++ b/python/ql/test/library-tests/exceptions/Handles.ql @@ -2,4 +2,4 @@ import python from ExceptFlowNode ex, Value val where ex.handledException(val, _, _) -select ex.getLocation().getStartLine(), ex.toString(), val.toString() \ No newline at end of file +select ex.getLocation().getStartLine(), ex.toString(), val.toString() diff --git a/python/ql/test/library-tests/exceptions/Legal.ql b/python/ql/test/library-tests/exceptions/Legal.ql index 37488eb082b..eb27a82d614 100644 --- a/python/ql/test/library-tests/exceptions/Legal.ql +++ b/python/ql/test/library-tests/exceptions/Legal.ql @@ -2,10 +2,9 @@ import python from ClassObject cls, string legal where -not cls.isC() and cls.isLegalExceptionType() and legal = "yes" and not cls.failedInference() -or -not cls.isC() and not cls.isLegalExceptionType() and legal = "no" and not cls.failedInference() -or -not cls.isC() and cls.failedInference(legal) - + not cls.isC() and cls.isLegalExceptionType() and legal = "yes" and not cls.failedInference() + or + not cls.isC() and not cls.isLegalExceptionType() and legal = "no" and not cls.failedInference() + or + not cls.isC() and cls.failedInference(legal) select cls.toString(), legal diff --git a/python/ql/test/library-tests/exprs/ast/AstParent.ql b/python/ql/test/library-tests/exprs/ast/AstParent.ql index 3e26f672360..f472a6f6e5b 100644 --- a/python/ql/test/library-tests/exprs/ast/AstParent.ql +++ b/python/ql/test/library-tests/exprs/ast/AstParent.ql @@ -1,6 +1,4 @@ import python -select -count(AstNode c | not exists(c.getParentNode()) and not c instanceof Module) -+ -count(AstNode c | strictcount(c.getParentNode()) > 1) \ No newline at end of file +select count(AstNode c | not exists(c.getParentNode()) and not c instanceof Module) + + count(AstNode c | strictcount(c.getParentNode()) > 1) diff --git a/python/ql/test/library-tests/exprs/ast/Child.ql b/python/ql/test/library-tests/exprs/ast/Child.ql index 0638f6c4e22..5b363a6ddb2 100644 --- a/python/ql/test/library-tests/exprs/ast/Child.ql +++ b/python/ql/test/library-tests/exprs/ast/Child.ql @@ -3,4 +3,3 @@ import python from AstNode p, AstNode c where p.getAChildNode() = c select p.getLocation().getStartLine(), p.toString(), c.getLocation().getStartLine(), c - diff --git a/python/ql/test/library-tests/exprs/compare/Test.ql b/python/ql/test/library-tests/exprs/compare/Test.ql index 7aa2102f8b8..80feac5185a 100644 --- a/python/ql/test/library-tests/exprs/compare/Test.ql +++ b/python/ql/test/library-tests/exprs/compare/Test.ql @@ -1,8 +1,6 @@ - import python import semmle.python.TestUtils - from Compare comp, Expr left, Expr right, Cmpop op where comp.compares(left, op, right) select compact_location(comp), comp.toString(), left.toString(), op.toString(), right.toString() diff --git a/python/ql/test/library-tests/exprs/strings/Strings.ql b/python/ql/test/library-tests/exprs/strings/Strings.ql index e3a757c4725..7d6a697a8ed 100644 --- a/python/ql/test/library-tests/exprs/strings/Strings.ql +++ b/python/ql/test/library-tests/exprs/strings/Strings.ql @@ -1,4 +1,3 @@ - import python from StrConst s diff --git a/python/ql/test/library-tests/filters/generated/Filter.ql b/python/ql/test/library-tests/filters/generated/Filter.ql index 39c0e2b2344..389440ffd3a 100644 --- a/python/ql/test/library-tests/filters/generated/Filter.ql +++ b/python/ql/test/library-tests/filters/generated/Filter.ql @@ -1,4 +1,3 @@ - import python import semmle.python.filters.GeneratedCode diff --git a/python/ql/test/library-tests/filters/tests/Filter.ql b/python/ql/test/library-tests/filters/tests/Filter.ql index e20231ea5fa..71d6d2c668d 100644 --- a/python/ql/test/library-tests/filters/tests/Filter.ql +++ b/python/ql/test/library-tests/filters/tests/Filter.ql @@ -1,4 +1,3 @@ - import python import semmle.python.filters.Tests diff --git a/python/ql/test/library-tests/formatting/FormatArguments.ql b/python/ql/test/library-tests/formatting/FormatArguments.ql index 19e47b7fc44..f2cc38f7e8c 100644 --- a/python/ql/test/library-tests/formatting/FormatArguments.ql +++ b/python/ql/test/library-tests/formatting/FormatArguments.ql @@ -1,10 +1,9 @@ - import python import Expressions.Formatting.AdvancedFormatting from AdvancedFormatString a, string name, int start, int end -where -name = "'" + a.getFieldName(start, end) + "'" -or -name = a.getFieldNumber(start, end).toString() +where + name = "'" + a.getFieldName(start, end) + "'" + or + name = a.getFieldNumber(start, end).toString() select a.getLocation().getStartLine(), a.getText(), start, end, name diff --git a/python/ql/test/library-tests/formatting/FormatFields.ql b/python/ql/test/library-tests/formatting/FormatFields.ql index b8a3b913355..f629a779082 100644 --- a/python/ql/test/library-tests/formatting/FormatFields.ql +++ b/python/ql/test/library-tests/formatting/FormatFields.ql @@ -1,4 +1,3 @@ - import python import Expressions.Formatting.AdvancedFormatting diff --git a/python/ql/test/library-tests/imports/Alias.ql b/python/ql/test/library-tests/imports/Alias.ql index 5a7c034d02a..a08d1c6543b 100644 --- a/python/ql/test/library-tests/imports/Alias.ql +++ b/python/ql/test/library-tests/imports/Alias.ql @@ -2,4 +2,4 @@ import python from Alias a, ImportMember i where i = a.getValue() -select a.toString(), i.getName(), a.getAsname().toString() \ No newline at end of file +select a.toString(), i.getName(), a.getAsname().toString() diff --git a/python/ql/test/library-tests/jump_to_defn/Remote.ql b/python/ql/test/library-tests/jump_to_defn/Remote.ql index 18b0ebacdc0..7602e5839d3 100644 --- a/python/ql/test/library-tests/jump_to_defn/Remote.ql +++ b/python/ql/test/library-tests/jump_to_defn/Remote.ql @@ -1,10 +1,10 @@ - import python import analysis.DefinitionTracking import analysis.CrossProjectDefinitions from Definition defn, Symbol s -where s.find() = defn.getAstNode() and -// Exclude dunder names as these vary from version to version. -not s.toString().regexpMatch(".+__") +where + s.find() = defn.getAstNode() and + // Exclude dunder names as these vary from version to version. + not s.toString().regexpMatch(".+__") select s.toString() diff --git a/python/ql/test/library-tests/jump_to_defn/Sanity.ql b/python/ql/test/library-tests/jump_to_defn/Sanity.ql index 0e4455ab09b..ba274e0aa21 100644 --- a/python/ql/test/library-tests/jump_to_defn/Sanity.ql +++ b/python/ql/test/library-tests/jump_to_defn/Sanity.ql @@ -1,4 +1,3 @@ - import python import analysis.DefinitionTracking import analysis.CrossProjectDefinitions @@ -6,11 +5,11 @@ import analysis.CrossProjectDefinitions predicate local_problem(Definition defn, string issue, string repr) { not exists(defn.toString()) and issue = "no toString()" and repr = "a local definition" or - not exists(defn.getAstNode()) and issue = "no getAstNode()" and repr = defn.toString() + not exists(defn.getAstNode()) and issue = "no getAstNode()" and repr = defn.toString() or - not exists(defn.getLocation()) and issue = "no getLocation()" and repr = defn.toString() + not exists(defn.getLocation()) and issue = "no getLocation()" and repr = defn.toString() or - count(defn.getLocation())> 1 and issue = "more than one getLocation()" and repr = defn.toString() + count(defn.getLocation()) > 1 and issue = "more than one getLocation()" and repr = defn.toString() } predicate remote_problem(Symbol s, string issue, string repr) { diff --git a/python/ql/test/library-tests/jump_to_defn/Symbol.ql b/python/ql/test/library-tests/jump_to_defn/Symbol.ql index 7f111863b06..446f6b47b51 100644 --- a/python/ql/test/library-tests/jump_to_defn/Symbol.ql +++ b/python/ql/test/library-tests/jump_to_defn/Symbol.ql @@ -1,8 +1,5 @@ - import python import analysis.CrossProjectDefinitions from Symbol symbol - select symbol.toString(), symbol.find().getLocation().toString() - diff --git a/python/ql/test/library-tests/jump_to_defn/test.ql b/python/ql/test/library-tests/jump_to_defn/test.ql index ed8bf8ab84c..0f952578997 100644 --- a/python/ql/test/library-tests/jump_to_defn/test.ql +++ b/python/ql/test/library-tests/jump_to_defn/test.ql @@ -6,6 +6,7 @@ import python import analysis.DefinitionTracking from Expr use, Definition defn -where defn = getADefinition(use) -and use.getEnclosingModule().getName() = "test" +where + defn = getADefinition(use) and + use.getEnclosingModule().getName() = "test" select use.getLocation().toString(), use.toString(), defn.toString() diff --git a/python/ql/test/library-tests/locations/elif/test.ql b/python/ql/test/library-tests/locations/elif/test.ql index ca7177e847c..b2e7f4b164d 100644 --- a/python/ql/test/library-tests/locations/elif/test.ql +++ b/python/ql/test/library-tests/locations/elif/test.ql @@ -2,4 +2,4 @@ import python from AstNode ast, Location l where ast.getLocation() = l -select ast.getAQlClass(), l.getStartLine(), l.getStartColumn(), l.getEndLine(), l.getEndColumn() \ No newline at end of file +select ast.getAQlClass(), l.getStartLine(), l.getStartColumn(), l.getEndLine(), l.getEndColumn() diff --git a/python/ql/test/library-tests/locations/implicit_concatenation/part_locations.ql b/python/ql/test/library-tests/locations/implicit_concatenation/part_locations.ql index 2687a785f1b..aac64976f75 100644 --- a/python/ql/test/library-tests/locations/implicit_concatenation/part_locations.ql +++ b/python/ql/test/library-tests/locations/implicit_concatenation/part_locations.ql @@ -1,12 +1,9 @@ import python class ImplicitConcat extends StrConst { - ImplicitConcat() { - exists(this.getAnImplicitlyConcatenatedPart()) - } + ImplicitConcat() { exists(this.getAnImplicitlyConcatenatedPart()) } } - + from StringPart s - - -select s.getLocation().getStartLine(), s.getText(), s.getLocation().getStartColumn(), s.getLocation().getEndColumn() \ No newline at end of file +select s.getLocation().getStartLine(), s.getText(), s.getLocation().getStartColumn(), + s.getLocation().getEndColumn() diff --git a/python/ql/test/library-tests/locations/implicit_concatenation/parts.ql b/python/ql/test/library-tests/locations/implicit_concatenation/parts.ql index 1b1a0d492b3..49fe354b6ee 100644 --- a/python/ql/test/library-tests/locations/implicit_concatenation/parts.ql +++ b/python/ql/test/library-tests/locations/implicit_concatenation/parts.ql @@ -1,14 +1,9 @@ import python class ImplicitConcat extends StrConst { - ImplicitConcat() { - exists(this.getAnImplicitlyConcatenatedPart()) - } + ImplicitConcat() { exists(this.getAnImplicitlyConcatenatedPart()) } } - + from StrConst s, StringPart part, int n -where - part = s.getImplicitlyConcatenatedPart(n) - - -select s.getLocation().getStartLine(), s.getText(), n, part.getText() \ No newline at end of file +where part = s.getImplicitlyConcatenatedPart(n) +select s.getLocation().getStartLine(), s.getText(), n, part.getText() diff --git a/python/ql/test/library-tests/locations/implicit_concatenation/test.ql b/python/ql/test/library-tests/locations/implicit_concatenation/test.ql index 5b2f6ae0a55..09ba3dcd1c4 100644 --- a/python/ql/test/library-tests/locations/implicit_concatenation/test.ql +++ b/python/ql/test/library-tests/locations/implicit_concatenation/test.ql @@ -1,16 +1,13 @@ import python class ImplicitConcat extends StrConst { - ImplicitConcat() { - exists(this.getAnImplicitlyConcatenatedPart()) - } + ImplicitConcat() { exists(this.getAnImplicitlyConcatenatedPart()) } } - + from StrConst s, boolean isConcat -where - s instanceof ImplicitConcat and isConcat = true - or - not s instanceof ImplicitConcat and isConcat = false - - -select s.getLocation().getStartLine(), s.getText(), isConcat, s.getText().length(), s.getLocation().getStartColumn(), s.getLocation().getEndColumn() \ No newline at end of file +where + s instanceof ImplicitConcat and isConcat = true + or + not s instanceof ImplicitConcat and isConcat = false +select s.getLocation().getStartLine(), s.getText(), isConcat, s.getText().length(), + s.getLocation().getStartColumn(), s.getLocation().getEndColumn() diff --git a/python/ql/test/library-tests/locations/negative_numbers/negative.ql b/python/ql/test/library-tests/locations/negative_numbers/negative.ql index c423cb0532c..0fe2cdcc2bc 100644 --- a/python/ql/test/library-tests/locations/negative_numbers/negative.ql +++ b/python/ql/test/library-tests/locations/negative_numbers/negative.ql @@ -1,13 +1,7 @@ import python -from Expr e, int bl, int bc, int el,int ec, string p - -where - e.getLocation().hasLocationInfo(_, bl, bc, el, ec) - and - if e.isParenthesized() then - p = "()" - else - p = "" - -select e.toString(), bl, bc, el, ec, p \ No newline at end of file +from Expr e, int bl, int bc, int el, int ec, string p +where + e.getLocation().hasLocationInfo(_, bl, bc, el, ec) and + if e.isParenthesized() then p = "()" else p = "" +select e.toString(), bl, bc, el, ec, p diff --git a/python/ql/test/library-tests/locations/nested_classes/Test.ql b/python/ql/test/library-tests/locations/nested_classes/Test.ql index 693d6f7116f..143df5fee6f 100644 --- a/python/ql/test/library-tests/locations/nested_classes/Test.ql +++ b/python/ql/test/library-tests/locations/nested_classes/Test.ql @@ -1,7 +1,5 @@ - import python from Class cls, Location l where l = cls.getLocation() - select cls.getName(), l.getStartLine(), l.getStartColumn(), l.getEndLine(), l.getEndColumn() diff --git a/python/ql/test/library-tests/modules/duplicate_name/Modules.ql b/python/ql/test/library-tests/modules/duplicate_name/Modules.ql index 536689d0f90..a6477c7d6af 100644 --- a/python/ql/test/library-tests/modules/duplicate_name/Modules.ql +++ b/python/ql/test/library-tests/modules/duplicate_name/Modules.ql @@ -1,7 +1,5 @@ - import python from string name, int mcnt where mcnt = strictcount(Module m | m.getName() = name) and mcnt > 1 select name, mcnt, strictcount(ModuleValue val | val.getName() = name) - diff --git a/python/ql/test/library-tests/modules/overlapping-paths/ModuleNames.ql b/python/ql/test/library-tests/modules/overlapping-paths/ModuleNames.ql index a3a54953513..bc7bc0526ec 100644 --- a/python/ql/test/library-tests/modules/overlapping-paths/ModuleNames.ql +++ b/python/ql/test/library-tests/modules/overlapping-paths/ModuleNames.ql @@ -1,4 +1,3 @@ - import python from Module m diff --git a/python/ql/test/library-tests/modules/spurious_init/ModuleNames.ql b/python/ql/test/library-tests/modules/spurious_init/ModuleNames.ql index a3a54953513..bc7bc0526ec 100644 --- a/python/ql/test/library-tests/modules/spurious_init/ModuleNames.ql +++ b/python/ql/test/library-tests/modules/spurious_init/ModuleNames.ql @@ -1,4 +1,3 @@ - import python from Module m diff --git a/python/ql/test/library-tests/objects/Literals.ql b/python/ql/test/library-tests/objects/Literals.ql index f83f4e722da..ad6e1181cfd 100644 --- a/python/ql/test/library-tests/objects/Literals.ql +++ b/python/ql/test/library-tests/objects/Literals.ql @@ -1,8 +1,6 @@ - /* Test that there are no literals that do not have a corresponding object. */ import python - string repr(Expr e) { result = e.(Num).getN() or result = e.(Bytes).getS() or @@ -10,7 +8,5 @@ string repr(Expr e) { } from ImmutableLiteral l -where -not exists(l.getLiteralObject()) - -select l.getLocation().getStartLine(), repr(l) \ No newline at end of file +where not exists(l.getLiteralObject()) +select l.getLocation().getStartLine(), repr(l) diff --git a/python/ql/test/library-tests/objects/Name.ql b/python/ql/test/library-tests/objects/Name.ql index 674890c01ba..c20358b9062 100644 --- a/python/ql/test/library-tests/objects/Name.ql +++ b/python/ql/test/library-tests/objects/Name.ql @@ -1,21 +1,21 @@ - import python from Object o, string name -where o.hasLongName(name) -and ( - name = "sys.modules" - or - name = "test.n" - or - name = "test.l" - or - name = "test.d" - or - name = "test.C.meth" - or - name = "test.C.cmeth" - or - name = "test.C.smeth" -) +where + o.hasLongName(name) and + ( + name = "sys.modules" + or + name = "test.n" + or + name = "test.l" + or + name = "test.d" + or + name = "test.C.meth" + or + name = "test.C.cmeth" + or + name = "test.C.smeth" + ) select name, o.toString() diff --git a/python/ql/test/library-tests/objects/Strings.ql b/python/ql/test/library-tests/objects/Strings.ql index 9fcceb58fe4..eca8dec51fd 100644 --- a/python/ql/test/library-tests/objects/Strings.ql +++ b/python/ql/test/library-tests/objects/Strings.ql @@ -1,8 +1,5 @@ - import python - from StringObject s, ControlFlowNode f where f.refersTo(s) select f.getLocation().toString(), s.getText() - diff --git a/python/ql/test/library-tests/parameters/Annotations.ql b/python/ql/test/library-tests/parameters/Annotations.ql index cceecd699f3..17b02844a44 100644 --- a/python/ql/test/library-tests/parameters/Annotations.ql +++ b/python/ql/test/library-tests/parameters/Annotations.ql @@ -1,6 +1,4 @@ - import python - from Parameter p select p.getName(), p.getAnnotation() diff --git a/python/ql/test/library-tests/parameters/Defaults.ql b/python/ql/test/library-tests/parameters/Defaults.ql index ab16913804d..ebc8215074b 100644 --- a/python/ql/test/library-tests/parameters/Defaults.ql +++ b/python/ql/test/library-tests/parameters/Defaults.ql @@ -1,6 +1,4 @@ - import python - from Parameter p select p.getName(), p.getDefault() diff --git a/python/ql/test/library-tests/parameters/Special.ql b/python/ql/test/library-tests/parameters/Special.ql index ff06b8f072d..4987599bc72 100644 --- a/python/ql/test/library-tests/parameters/Special.ql +++ b/python/ql/test/library-tests/parameters/Special.ql @@ -1,13 +1,10 @@ - - import python from Parameter p, string type where -p.isKwargs() and type = "kwargs" -or -p.isVarargs() and type = "varargs" -or -not p.isKwargs() and not p.isVarargs() and type = "normal" - + p.isKwargs() and type = "kwargs" + or + p.isVarargs() and type = "varargs" + or + not p.isKwargs() and not p.isVarargs() and type = "normal" select p.getName(), type diff --git a/python/ql/test/library-tests/regex/Alternation.ql b/python/ql/test/library-tests/regex/Alternation.ql index 210d26aad98..79622fae32e 100644 --- a/python/ql/test/library-tests/regex/Alternation.ql +++ b/python/ql/test/library-tests/regex/Alternation.ql @@ -1,8 +1,7 @@ - import python import semmle.python.regex from Regex r, int start, int end, int part_start, int part_end where r.alternationOption(start, end, part_start, part_end) -select r.getText(), start, end, r.getText().substring(start, end), - part_start, part_end, r.getText().substring(part_start, part_end) +select r.getText(), start, end, r.getText().substring(start, end), part_start, part_end, + r.getText().substring(part_start, part_end) diff --git a/python/ql/test/library-tests/regex/Characters.ql b/python/ql/test/library-tests/regex/Characters.ql index 38976fcf7c7..1444c37cd57 100644 --- a/python/ql/test/library-tests/regex/Characters.ql +++ b/python/ql/test/library-tests/regex/Characters.ql @@ -3,12 +3,9 @@ * @description Test for escaped characters */ - import python import semmle.python.regex from Regex r, int start, int end where r.character(start, end) and r.getLocation().getFile().getBaseName() = "test.py" select r.getText(), start, end - - diff --git a/python/ql/test/library-tests/regex/FirstLast.ql b/python/ql/test/library-tests/regex/FirstLast.ql index 0ca7e10cd3a..7a57eb51382 100644 --- a/python/ql/test/library-tests/regex/FirstLast.ql +++ b/python/ql/test/library-tests/regex/FirstLast.ql @@ -1,10 +1,8 @@ - - import python import semmle.python.regex predicate part(Regex r, int start, int end, string kind) { - r.lastItem(start, end) and kind = "last" + r.lastItem(start, end) and kind = "last" or r.firstItem(start, end) and kind = "first" } diff --git a/python/ql/test/library-tests/regex/GroupContents.ql b/python/ql/test/library-tests/regex/GroupContents.ql index 1b49f5d9efd..28ad5749c0a 100644 --- a/python/ql/test/library-tests/regex/GroupContents.ql +++ b/python/ql/test/library-tests/regex/GroupContents.ql @@ -1,8 +1,7 @@ - import python import semmle.python.regex from Regex r, int start, int end, int part_start, int part_end where r.groupContents(start, end, part_start, part_end) -select r.getText(), start, end, r.getText().substring(start, end), - part_start, part_end, r.getText().substring(part_start, part_end) \ No newline at end of file +select r.getText(), start, end, r.getText().substring(start, end), part_start, part_end, + r.getText().substring(part_start, part_end) diff --git a/python/ql/test/library-tests/regex/Mode.ql b/python/ql/test/library-tests/regex/Mode.ql index 7fd593075a9..02e84f86c5d 100644 --- a/python/ql/test/library-tests/regex/Mode.ql +++ b/python/ql/test/library-tests/regex/Mode.ql @@ -1,7 +1,4 @@ - import python - - import semmle.python.regex from Regex r diff --git a/python/ql/test/library-tests/regex/Qualified.ql b/python/ql/test/library-tests/regex/Qualified.ql index e40d2bf6ae7..8adf7e0426c 100644 --- a/python/ql/test/library-tests/regex/Qualified.ql +++ b/python/ql/test/library-tests/regex/Qualified.ql @@ -1,5 +1,3 @@ - - import python import semmle.python.regex diff --git a/python/ql/test/library-tests/regex/Regex.ql b/python/ql/test/library-tests/regex/Regex.ql index 220efdb4cc3..708ad82804d 100644 --- a/python/ql/test/library-tests/regex/Regex.ql +++ b/python/ql/test/library-tests/regex/Regex.ql @@ -1,10 +1,8 @@ - - import python import semmle.python.regex predicate part(Regex r, int start, int end, string kind) { - r.alternation(start, end) and kind = "choice" + r.alternation(start, end) and kind = "choice" or r.normalCharacter(start, end) and kind = "char" or diff --git a/python/ql/test/library-tests/scopes/Previous.ql b/python/ql/test/library-tests/scopes/Previous.ql index 1e7d25d7da8..00bd2b90f2a 100644 --- a/python/ql/test/library-tests/scopes/Previous.ql +++ b/python/ql/test/library-tests/scopes/Previous.ql @@ -2,4 +2,4 @@ import python from Scope s1, Scope s2 where s1.precedes(s2) -select s1.toString(), s2.toString() \ No newline at end of file +select s1.toString(), s2.toString() diff --git a/python/ql/test/library-tests/security/sensitive/Sources.ql b/python/ql/test/library-tests/security/sensitive/Sources.ql index f974c18780a..b5328a9f105 100644 --- a/python/ql/test/library-tests/security/sensitive/Sources.ql +++ b/python/ql/test/library-tests/security/sensitive/Sources.ql @@ -1,6 +1,4 @@ - import python - import semmle.python.security.SensitiveData from SensitiveData::Source src diff --git a/python/ql/test/library-tests/state_tracking/Test.ql b/python/ql/test/library-tests/state_tracking/Test.ql index e88365aad94..cfdfa7c77aa 100644 --- a/python/ql/test/library-tests/state_tracking/Test.ql +++ b/python/ql/test/library-tests/state_tracking/Test.ql @@ -1,14 +1,12 @@ - import python import Lib from ControlFlowNode f, TrackableState state, Context ctx, boolean sense where -f.getLocation().getStartLine() >= 20 and -( - state.appliesTo(f, ctx) and sense = true - or - state.mayNotApplyTo(f, ctx) and sense = false -) - + f.getLocation().getStartLine() >= 20 and + ( + state.appliesTo(f, ctx) and sense = true + or + state.mayNotApplyTo(f, ctx) and sense = false + ) select f.getLocation().toString(), f, ctx, state, sense diff --git a/python/ql/test/library-tests/state_tracking/Violations.ql b/python/ql/test/library-tests/state_tracking/Violations.ql index 8da2a0500ef..db70e7d3368 100644 --- a/python/ql/test/library-tests/state_tracking/Violations.ql +++ b/python/ql/test/library-tests/state_tracking/Violations.ql @@ -1,15 +1,12 @@ - import python import Lib from ControlFlowNode f, TrackableState state where -( - callTo(f, "exacerbate") and state = "frobnicated" - or - callTo(f, "frobnicate") and state = "initialized" -) -and -state.mayNotApplyTo(f) - + ( + callTo(f, "exacerbate") and state = "frobnicated" + or + callTo(f, "frobnicate") and state = "initialized" + ) and + state.mayNotApplyTo(f) select f.getLocation().toString(), f.toString(), state.toString() diff --git a/python/ql/test/library-tests/stmts/general/AstParent.ql b/python/ql/test/library-tests/stmts/general/AstParent.ql index b7ea6f44ac3..85e0f4947fa 100644 --- a/python/ql/test/library-tests/stmts/general/AstParent.ql +++ b/python/ql/test/library-tests/stmts/general/AstParent.ql @@ -1,8 +1,5 @@ import python /* The result of this query should always be 0, *regardless* of the database. */ - -select -count(AstNode c | not exists(c.getParentNode()) and not c instanceof Module) -+ -count(AstNode c | strictcount(c.getParentNode()) > 1) +select count(AstNode c | not exists(c.getParentNode()) and not c instanceof Module) + + count(AstNode c | strictcount(c.getParentNode()) > 1) diff --git a/python/ql/test/library-tests/stmts/general/SubExpressions.ql b/python/ql/test/library-tests/stmts/general/SubExpressions.ql index deaff1e9610..e3b5eed1ced 100644 --- a/python/ql/test/library-tests/stmts/general/SubExpressions.ql +++ b/python/ql/test/library-tests/stmts/general/SubExpressions.ql @@ -1,5 +1,5 @@ - import python from Stmt s -select s.toString(), s.getASubExpression().toString(), s.getASubExpression().getASubExpression*().toString(), s.getLocation().getStartLine() \ No newline at end of file +select s.toString(), s.getASubExpression().toString(), + s.getASubExpression().getASubExpression*().toString(), s.getLocation().getStartLine() diff --git a/python/ql/test/library-tests/stmts/raise_stmt/AST.ql b/python/ql/test/library-tests/stmts/raise_stmt/AST.ql index d9daaa8514b..62719f1179f 100644 --- a/python/ql/test/library-tests/stmts/raise_stmt/AST.ql +++ b/python/ql/test/library-tests/stmts/raise_stmt/AST.ql @@ -1,7 +1,6 @@ - - import python from AstNode parent, AstNode child where child.getParentNode() = parent -select parent.getLocation().getStartLine(), parent.toString(), child.getLocation().getStartLine(), child.toString() \ No newline at end of file +select parent.getLocation().getStartLine(), parent.toString(), child.getLocation().getStartLine(), + child.toString() diff --git a/python/ql/test/library-tests/stmts/try_stmt/AST.ql b/python/ql/test/library-tests/stmts/try_stmt/AST.ql index d9daaa8514b..62719f1179f 100644 --- a/python/ql/test/library-tests/stmts/try_stmt/AST.ql +++ b/python/ql/test/library-tests/stmts/try_stmt/AST.ql @@ -1,7 +1,6 @@ - - import python from AstNode parent, AstNode child where child.getParentNode() = parent -select parent.getLocation().getStartLine(), parent.toString(), child.getLocation().getStartLine(), child.toString() \ No newline at end of file +select parent.getLocation().getStartLine(), parent.toString(), child.getLocation().getStartLine(), + child.toString() diff --git a/python/ql/test/library-tests/stmts/with_stmt/AST.ql b/python/ql/test/library-tests/stmts/with_stmt/AST.ql index d9daaa8514b..62719f1179f 100644 --- a/python/ql/test/library-tests/stmts/with_stmt/AST.ql +++ b/python/ql/test/library-tests/stmts/with_stmt/AST.ql @@ -1,7 +1,6 @@ - - import python from AstNode parent, AstNode child where child.getParentNode() = parent -select parent.getLocation().getStartLine(), parent.toString(), child.getLocation().getStartLine(), child.toString() \ No newline at end of file +select parent.getLocation().getStartLine(), parent.toString(), child.getLocation().getStartLine(), + child.toString() diff --git a/python/ql/test/library-tests/taint/collections/TestTaint.ql b/python/ql/test/library-tests/taint/collections/TestTaint.ql index 92657b1fef9..8347bd25433 100644 --- a/python/ql/test/library-tests/taint/collections/TestTaint.ql +++ b/python/ql/test/library-tests/taint/collections/TestTaint.ql @@ -15,4 +15,5 @@ where taint_string = tainted.getTaintKind().toString() ) ) -select arg.getLocation().toString(), call.getScope().(Function).getName(), arg.toString(), taint_string +select arg.getLocation().toString(), call.getScope().(Function).getName(), arg.toString(), + taint_string diff --git a/python/ql/test/library-tests/taint/config/RockPaperScissors.ql b/python/ql/test/library-tests/taint/config/RockPaperScissors.ql index 0910f9846c4..311039a6553 100644 --- a/python/ql/test/library-tests/taint/config/RockPaperScissors.ql +++ b/python/ql/test/library-tests/taint/config/RockPaperScissors.ql @@ -1,4 +1,3 @@ - /** * @kind path-problem */ @@ -10,4 +9,5 @@ import semmle.python.security.Paths from RockPaperScissorConfig config, TaintedPathSource src, TaintedPathSink sink where config.hasFlowPath(src, sink) -select sink.getSink(), src, sink, "$@ loses to $@.", src.getNode(), src.getTaintKind().toString(), sink.getNode(), sink.getTaintKind().toString() \ No newline at end of file +select sink.getSink(), src, sink, "$@ loses to $@.", src.getNode(), src.getTaintKind().toString(), + sink.getNode(), sink.getTaintKind().toString() diff --git a/python/ql/test/library-tests/taint/config/Simple.ql b/python/ql/test/library-tests/taint/config/Simple.ql index a3acf7272f6..76e8c261048 100644 --- a/python/ql/test/library-tests/taint/config/Simple.ql +++ b/python/ql/test/library-tests/taint/config/Simple.ql @@ -1,4 +1,3 @@ - /** * @kind path-problem */ @@ -10,4 +9,5 @@ import semmle.python.security.Paths from SimpleConfig config, TaintedPathSource src, TaintedPathSink sink where config.hasFlowPath(src, sink) -select sink.getSink(), src, sink, "$@ flows to $@.", src.getNode(), src.getTaintKind().toString(), sink.getNode(), sink.getTaintKind().toString() +select sink.getSink(), src, sink, "$@ flows to $@.", src.getNode(), src.getTaintKind().toString(), + sink.getNode(), sink.getTaintKind().toString() diff --git a/python/ql/test/library-tests/taint/config/TaintedArgument.ql b/python/ql/test/library-tests/taint/config/TaintedArgument.ql index 9cbde79561b..ca351d878a5 100644 --- a/python/ql/test/library-tests/taint/config/TaintedArgument.ql +++ b/python/ql/test/library-tests/taint/config/TaintedArgument.ql @@ -1,14 +1,12 @@ - import python - - - import semmle.python.security.TaintTracking import TaintLib import semmle.python.dataflow.Implementation -from TaintTrackingImplementation config, TaintTrackingNode src, CallNode call, - TaintTrackingContext caller, CallableValue pyfunc, int arg, AttributePath path, TaintKind kind -where config instanceof TestConfig and -config.callWithTaintedArgument(src, call, caller, pyfunc, arg, path, kind) +from + TaintTrackingImplementation config, TaintTrackingNode src, CallNode call, + TaintTrackingContext caller, CallableValue pyfunc, int arg, AttributePath path, TaintKind kind +where + config instanceof TestConfig and + config.callWithTaintedArgument(src, call, caller, pyfunc, arg, path, kind) select config, src, call, caller, pyfunc, arg, path, kind diff --git a/python/ql/test/library-tests/taint/config/TestNode.ql b/python/ql/test/library-tests/taint/config/TestNode.ql index 165bf382301..02a4dd278c3 100644 --- a/python/ql/test/library-tests/taint/config/TestNode.ql +++ b/python/ql/test/library-tests/taint/config/TestNode.ql @@ -3,8 +3,7 @@ import semmle.python.security.TaintTracking import semmle.python.dataflow.Implementation import TaintLib - from TaintTrackingNode n where n.getConfiguration() instanceof TestConfig -select n.getLocation().toString(), n.getTaintKind(), n.getNode().toString(), n.getPath().toString(), n.getContext().toString() - +select n.getLocation().toString(), n.getTaintKind(), n.getNode().toString(), n.getPath().toString(), + n.getContext().toString() diff --git a/python/ql/test/library-tests/taint/config/TestSink.ql b/python/ql/test/library-tests/taint/config/TestSink.ql index 2fc42bce378..4df3f48b939 100644 --- a/python/ql/test/library-tests/taint/config/TestSink.ql +++ b/python/ql/test/library-tests/taint/config/TestSink.ql @@ -3,6 +3,5 @@ import semmle.python.security.TaintTracking import TaintLib from TestConfig config, DataFlow::Node sink, TaintKind kind - where config.isSink(sink, kind) select sink.getLocation().toString(), config, sink.toString(), kind diff --git a/python/ql/test/library-tests/taint/config/TestSource.ql b/python/ql/test/library-tests/taint/config/TestSource.ql index 338ec65fd45..191583becb7 100644 --- a/python/ql/test/library-tests/taint/config/TestSource.ql +++ b/python/ql/test/library-tests/taint/config/TestSource.ql @@ -3,6 +3,6 @@ import semmle.python.security.TaintTracking import TaintLib from TestConfig config, DataFlow::Node source, TaintKind kind - where config.isSource(source, kind) -select config, source.getLocation().toString(), source.getLocation().getStartLine(), source.toString(), kind +select config, source.getLocation().toString(), source.getLocation().getStartLine(), + source.toString(), kind diff --git a/python/ql/test/library-tests/taint/config/TestStep.ql b/python/ql/test/library-tests/taint/config/TestStep.ql index 2f702834d01..f16f2e36bb8 100644 --- a/python/ql/test/library-tests/taint/config/TestStep.ql +++ b/python/ql/test/library-tests/taint/config/TestStep.ql @@ -3,11 +3,8 @@ import semmle.python.security.TaintTracking import TaintLib import semmle.python.dataflow.Implementation - from TaintTrackingNode n, TaintTrackingNode s, TestConfig config where s = n.getASuccessor() and config = n.getConfiguration() -select - config + ":", - n.getTaintKind(), n.getLocation().toString(), n.getNode().toString(), n.getContext(), - " --> ", - s.getTaintKind(), s.getLocation().toString(), s.getNode().toString(), s.getContext() +select config + ":", n.getTaintKind(), n.getLocation().toString(), n.getNode().toString(), + n.getContext(), " --> ", s.getTaintKind(), s.getLocation().toString(), s.getNode().toString(), + s.getContext() diff --git a/python/ql/test/library-tests/taint/dataflow/Dataflow.ql b/python/ql/test/library-tests/taint/dataflow/Dataflow.ql index d758f32b2df..ced8b9a7c25 100644 --- a/python/ql/test/library-tests/taint/dataflow/Dataflow.ql +++ b/python/ql/test/library-tests/taint/dataflow/Dataflow.ql @@ -1,4 +1,3 @@ - import python import Config diff --git a/python/ql/test/library-tests/taint/dataflow/TestNode.ql b/python/ql/test/library-tests/taint/dataflow/TestNode.ql index 81bb0c0fc56..3498d5546da 100644 --- a/python/ql/test/library-tests/taint/dataflow/TestNode.ql +++ b/python/ql/test/library-tests/taint/dataflow/TestNode.ql @@ -2,4 +2,5 @@ import python import Config from TaintedNode n -select "Taint " + n.getTaintKind(), n.getLocation().toString(), n.getNode().getNode().toString(), n.getContext() +select "Taint " + n.getTaintKind(), n.getLocation().toString(), n.getNode().getNode().toString(), + n.getContext() diff --git a/python/ql/test/library-tests/taint/example/Edges.ql b/python/ql/test/library-tests/taint/example/Edges.ql index 4b975666d92..0674f3a073c 100644 --- a/python/ql/test/library-tests/taint/example/Edges.ql +++ b/python/ql/test/library-tests/taint/example/Edges.ql @@ -3,18 +3,24 @@ import semmle.python.security.TaintTracking import semmle.python.dataflow.Implementation import DilbertConfig - string shortString(TaintTrackingNode n) { - if n.getContext().isTop() then - result = n.getLocation().getStartLine() + ": " + n.getNode().toString() + n.getPath().extension() + " = " + n.getTaintKind() + if n.getContext().isTop() + then + result = + n.getLocation().getStartLine() + ": " + n.getNode().toString() + n.getPath().extension() + + " = " + n.getTaintKind() else - result = n.getLocation().getStartLine() + ": " + n.getNode().toString() + n.getPath().extension() + " = " + n.getTaintKind() + " (" + n.getContext().toString() + ")" + result = + n.getLocation().getStartLine() + ": " + n.getNode().toString() + n.getPath().extension() + + " = " + n.getTaintKind() + " (" + n.getContext().toString() + ")" } bindingset[s, len] string ljust(string s, int len) { - result = s + - " ".prefix(len-s.length()) + result = + s + + " " + .prefix(len - s.length()) } bindingset[s, len] @@ -23,7 +29,7 @@ string format(string s, int len) { s = "" and label = "[dataflow]" or s != "" and label = s - | + | result = ljust(label, len) ) } @@ -31,4 +37,3 @@ string format(string s, int len) { from TaintTrackingNode p, TaintTrackingNode s, string label where any(DilbertConfig config).(TaintTrackingImplementation).flowStep(p, s, label) select format(shortString(p), 50), format(label, 10), shortString(s) - diff --git a/python/ql/test/library-tests/taint/example/ExampleConfig.ql b/python/ql/test/library-tests/taint/example/ExampleConfig.ql index cb0c43de3d1..e3809c7a024 100644 --- a/python/ql/test/library-tests/taint/example/ExampleConfig.ql +++ b/python/ql/test/library-tests/taint/example/ExampleConfig.ql @@ -1,6 +1,6 @@ /** * @kind path-problem - * + * * An example configuration. * See ExampleConfiguration.expected for the results of running this query. */ @@ -9,7 +9,7 @@ import python import DilbertConfig import semmle.python.security.Paths - from DilbertConfig config, TaintedPathSource src, TaintedPathSink sink where config.hasFlowPath(src, sink) -select sink.getSink(), src, sink, "$@ goes to a $@.", src.getNode(), src.getTaintKind().toString(), sink.getNode(), "meeting" +select sink.getSink(), src, sink, "$@ goes to a $@.", src.getNode(), src.getTaintKind().toString(), + sink.getNode(), "meeting" diff --git a/python/ql/test/library-tests/taint/example/Nodes.ql b/python/ql/test/library-tests/taint/example/Nodes.ql index 21e315bca74..0a5ff02c2a3 100644 --- a/python/ql/test/library-tests/taint/example/Nodes.ql +++ b/python/ql/test/library-tests/taint/example/Nodes.ql @@ -3,8 +3,7 @@ import semmle.python.security.TaintTracking import semmle.python.dataflow.Implementation import DilbertConfig - from TaintTrackingNode n where n.getConfiguration() instanceof DilbertConfig -select n.getLocation().toString(), n.getNode().toString(), n.getPath().toString(), n.getContext().toString(), n.getTaintKind() - +select n.getLocation().toString(), n.getNode().toString(), n.getPath().toString(), + n.getContext().toString(), n.getTaintKind() diff --git a/python/ql/test/library-tests/taint/exception_traceback/TestNode.ql b/python/ql/test/library-tests/taint/exception_traceback/TestNode.ql index b9ec3c2ff3e..b11ef5e18e8 100644 --- a/python/ql/test/library-tests/taint/exception_traceback/TestNode.ql +++ b/python/ql/test/library-tests/taint/exception_traceback/TestNode.ql @@ -1,8 +1,7 @@ import python - import semmle.python.security.Exceptions import semmle.python.web.HttpResponse from TaintedNode node where not node.getLocation().getFile().inStdlib() -select node.getLocation(), node.getNode().getNode().toString(), node.getTaintKind() \ No newline at end of file +select node.getLocation(), node.getNode().getNode().toString(), node.getTaintKind() diff --git a/python/ql/test/library-tests/taint/exception_traceback/TestSource.ql b/python/ql/test/library-tests/taint/exception_traceback/TestSource.ql index 8e625641b77..d66d80dae40 100644 --- a/python/ql/test/library-tests/taint/exception_traceback/TestSource.ql +++ b/python/ql/test/library-tests/taint/exception_traceback/TestSource.ql @@ -1,11 +1,9 @@ import python - import semmle.python.security.Exceptions import semmle.python.web.HttpResponse - from TaintSource src, TaintKind kind -where - src.isSourceOf(kind) and +where + src.isSourceOf(kind) and not src.getLocation().getFile().inStdlib() -select src.getLocation().toString(), src.(ControlFlowNode).getNode().toString(), kind \ No newline at end of file +select src.getLocation().toString(), src.(ControlFlowNode).getNode().toString(), kind diff --git a/python/ql/test/library-tests/taint/exception_traceback/TestStep.ql b/python/ql/test/library-tests/taint/exception_traceback/TestStep.ql index 8354e2526f5..6d10a7c5ed3 100644 --- a/python/ql/test/library-tests/taint/exception_traceback/TestStep.ql +++ b/python/ql/test/library-tests/taint/exception_traceback/TestStep.ql @@ -1,5 +1,4 @@ import python - import semmle.python.security.Exceptions import semmle.python.web.HttpResponse @@ -8,7 +7,6 @@ where s = n.getASuccessor() and not n.getLocation().getFile().inStdlib() and not s.getLocation().getFile().inStdlib() -select - "Taint " + n.getTaintKind(), n.getLocation().toString(), n.getNode().toString(), n.getContext(), - " --> ", - "Taint " + s.getTaintKind(), s.getLocation().toString(), s.getNode().toString(), s.getContext() +select "Taint " + n.getTaintKind(), n.getLocation().toString(), n.getNode().toString(), + n.getContext(), " --> ", "Taint " + s.getTaintKind(), s.getLocation().toString(), + s.getNode().toString(), s.getContext() diff --git a/python/ql/test/library-tests/taint/extensions/TestNode.ql b/python/ql/test/library-tests/taint/extensions/TestNode.ql index 842c63186ba..2fa17776be3 100644 --- a/python/ql/test/library-tests/taint/extensions/TestNode.ql +++ b/python/ql/test/library-tests/taint/extensions/TestNode.ql @@ -1,8 +1,6 @@ import python - import ExtensionsLib - from TaintedNode n -select "Taint " + n.getTaintKind(), n.getLocation().toString(), n.getNode().getNode().toString(), n.getContext() - +select "Taint " + n.getTaintKind(), n.getLocation().toString(), n.getNode().getNode().toString(), + n.getContext() diff --git a/python/ql/test/library-tests/taint/extensions/TestStep.ql b/python/ql/test/library-tests/taint/extensions/TestStep.ql index 95003b44270..9005aba858e 100644 --- a/python/ql/test/library-tests/taint/extensions/TestStep.ql +++ b/python/ql/test/library-tests/taint/extensions/TestStep.ql @@ -1,11 +1,8 @@ import python - import ExtensionsLib - from TaintedNode n, TaintedNode s where s = n.getASuccessor() -select - "Taint " + n.getTaintKind(), n.getLocation().toString(), n.getNode().getNode().toString(), n.getContext(), - " --> ", - "Taint " + s.getTaintKind(), s.getLocation().toString(), s.getNode().getNode().toString(), s.getContext() +select "Taint " + n.getTaintKind(), n.getLocation().toString(), n.getNode().getNode().toString(), + n.getContext(), " --> ", "Taint " + s.getTaintKind(), s.getLocation().toString(), + s.getNode().getNode().toString(), s.getContext() diff --git a/python/ql/test/library-tests/taint/general/Contexts.ql b/python/ql/test/library-tests/taint/general/Contexts.ql index 9d3d7ec6c32..6eee5f449b2 100644 --- a/python/ql/test/library-tests/taint/general/Contexts.ql +++ b/python/ql/test/library-tests/taint/general/Contexts.ql @@ -1,10 +1,9 @@ - import python import semmle.python.dataflow.Implementation import TaintLib from CallContext context, Scope s -where exists(CallContext caller | caller.getCallee(_) = context) and -context.appliesToScope(s) +where + exists(CallContext caller | caller.getCallee(_) = context) and + context.appliesToScope(s) select s.getLocation().toString(), context, s.toString() - diff --git a/python/ql/test/library-tests/taint/general/ModuleAttribute.ql b/python/ql/test/library-tests/taint/general/ModuleAttribute.ql index 25831de268d..6a4349b4100 100644 --- a/python/ql/test/library-tests/taint/general/ModuleAttribute.ql +++ b/python/ql/test/library-tests/taint/general/ModuleAttribute.ql @@ -2,8 +2,6 @@ import python import semmle.python.dataflow.Implementation import TaintLib - from ModuleValue m, string name, TaintedNode origin, TaintTrackingImplementation impl where impl.moduleAttributeTainted(m, name, origin) - select m.toString(), name, origin.toString(), origin.getContext(), origin.getLocation().toString() diff --git a/python/ql/test/library-tests/taint/general/ParamSource.ql b/python/ql/test/library-tests/taint/general/ParamSource.ql index 664fd8b77e5..f0956d0333d 100644 --- a/python/ql/test/library-tests/taint/general/ParamSource.ql +++ b/python/ql/test/library-tests/taint/general/ParamSource.ql @@ -1,37 +1,26 @@ import python import semmle.python.security.TaintTracking - /* Standard library sink */ import semmle.python.security.injection.Command class TestKind extends TaintKind { - TestKind() { - this = "test" - } - + TestKind() { this = "test" } } class CustomSource extends TaintSource { - CustomSource() { - exists(Parameter p | + exists(Parameter p | p.asName().getId() = "arg" and this.(ControlFlowNode).getNode() = p ) } - override predicate isSourceOf(TaintKind kind) { - kind instanceof TestKind - } - - override string toString() { - result = "Source of untrusted input" - } + override predicate isSourceOf(TaintKind kind) { kind instanceof TestKind } + override string toString() { result = "Source of untrusted input" } } class SimpleSink extends TaintSink { - override string toString() { result = "Simple sink" } SimpleSink() { @@ -41,13 +30,10 @@ class SimpleSink extends TaintSink { ) } - override predicate sinks(TaintKind taint) { - taint instanceof TestKind - } - + override predicate sinks(TaintKind taint) { taint instanceof TestKind } } from TaintSource src, TaintSink sink, TaintKind srckind, TaintKind sinkkind - where src.flowsToSink(srckind, sink) and sink.sinks(sinkkind) -select srckind, src.getLocation().toString(), sink.getLocation().getStartLine(), sink.(ControlFlowNode).getNode().toString(), sinkkind +select srckind, src.getLocation().toString(), sink.getLocation().getStartLine(), + sink.(ControlFlowNode).getNode().toString(), sinkkind diff --git a/python/ql/test/library-tests/taint/general/TaintSanity.ql b/python/ql/test/library-tests/taint/general/TaintSanity.ql index ddfa5a3af32..d07828e5947 100644 --- a/python/ql/test/library-tests/taint/general/TaintSanity.ql +++ b/python/ql/test/library-tests/taint/general/TaintSanity.ql @@ -3,24 +3,27 @@ import semmle.python.dataflow.TaintTracking import semmle.python.dataflow.Implementation import TaintLib -from TaintKind taint, TaintTrackingContext c, DataFlow::Node n, string what, TaintTrackingImplementation impl +from + TaintKind taint, TaintTrackingContext c, DataFlow::Node n, string what, + TaintTrackingImplementation impl where -not exists(TaintedNode t | t.getTaintKind() = taint and t.getNode() = n and t.getContext() = c) and -( - impl.flowStep(_, n, c, _, taint, _) and what = "missing node at end of step" + not exists(TaintedNode t | t.getTaintKind() = taint and t.getNode() = n and t.getContext() = c) and + ( + impl.flowStep(_, n, c, _, taint, _) and what = "missing node at end of step" + or + impl.flowSource(n, c, _, taint) and what = "missing node for source" + ) or - impl.flowSource(n, c, _, taint) and what = "missing node for source" -) -or -exists(TaintedNode t | t.getTaintKind() = taint and t.getNode() = n and t.getContext() = c - | - not impl.flowStep(_, n, c, _, taint, _) and - not impl.flowSource(n, c, _, taint) and what = "TaintedNode with no reason" - or - impl.flowStep(t, n, c, _, taint, _) and what = "step ends where it starts" - or - impl.flowStep(t, _, _, _, _, _) and not impl.flowStep(_, n, c, _, taint, _) and - not impl.flowSource(n, c, _, taint) and what = "No predecessor and not a source" -) - + exists(TaintedNode t | t.getTaintKind() = taint and t.getNode() = n and t.getContext() = c | + not impl.flowStep(_, n, c, _, taint, _) and + not impl.flowSource(n, c, _, taint) and + what = "TaintedNode with no reason" + or + impl.flowStep(t, n, c, _, taint, _) and what = "step ends where it starts" + or + impl.flowStep(t, _, _, _, _, _) and + not impl.flowStep(_, n, c, _, taint, _) and + not impl.flowSource(n, c, _, taint) and + what = "No predecessor and not a source" + ) select n.getLocation(), taint, c, n.toString(), what diff --git a/python/ql/test/library-tests/taint/general/TestDefn.ql b/python/ql/test/library-tests/taint/general/TestDefn.ql index e793d24649b..e2791bf2e72 100644 --- a/python/ql/test/library-tests/taint/general/TestDefn.ql +++ b/python/ql/test/library-tests/taint/general/TestDefn.ql @@ -1,8 +1,7 @@ import python import TaintLib - from EssaNodeDefinition defn, TaintedNode n where n.getNode().asVariable() = defn.getVariable() -select - defn.getLocation().toString(), defn.getRepresentation(), n.getLocation().toString(), "Taint " + n.toString(), defn.getDefiningNode().getNode().toString() +select defn.getLocation().toString(), defn.getRepresentation(), n.getLocation().toString(), + "Taint " + n.toString(), defn.getDefiningNode().getNode().toString() diff --git a/python/ql/test/library-tests/taint/general/TestSanitizers.ql b/python/ql/test/library-tests/taint/general/TestSanitizers.ql index 3dca04d581e..cee31378f7d 100644 --- a/python/ql/test/library-tests/taint/general/TestSanitizers.ql +++ b/python/ql/test/library-tests/taint/general/TestSanitizers.ql @@ -1,4 +1,3 @@ - import python import semmle.python.security.TaintTracking import TaintLib @@ -6,5 +5,3 @@ import TaintLib from Sanitizer s, TaintKind taint, PyEdgeRefinement test where s.sanitizingEdge(taint, test) select s, taint, test.getLocation().toString(), test.getRepresentation() - - diff --git a/python/ql/test/library-tests/taint/general/TestSink.ql b/python/ql/test/library-tests/taint/general/TestSink.ql index d0361cc204a..422527fbee2 100644 --- a/python/ql/test/library-tests/taint/general/TestSink.ql +++ b/python/ql/test/library-tests/taint/general/TestSink.ql @@ -3,6 +3,6 @@ import semmle.python.security.TaintTracking import TaintLib from TaintSource src, TaintSink sink, TaintKind srckind, TaintKind sinkkind - where src.flowsToSink(srckind, sink) and sink.sinks(sinkkind) -select srckind, src.getLocation().toString(), sink.getLocation().getStartLine(), sink.(ControlFlowNode).getNode().toString(), sinkkind +select srckind, src.getLocation().toString(), sink.getLocation().getStartLine(), + sink.(ControlFlowNode).getNode().toString(), sinkkind diff --git a/python/ql/test/library-tests/taint/general/TestSource.ql b/python/ql/test/library-tests/taint/general/TestSource.ql index ba064220bfb..d71bab289e0 100644 --- a/python/ql/test/library-tests/taint/general/TestSource.ql +++ b/python/ql/test/library-tests/taint/general/TestSource.ql @@ -2,7 +2,6 @@ import python import semmle.python.security.TaintTracking import TaintLib - from TaintSource src, TaintKind kind where src.isSourceOf(kind) select src.getLocation().toString(), src.(ControlFlowNode).getNode().toString(), kind diff --git a/python/ql/test/library-tests/taint/general/TestStep.ql b/python/ql/test/library-tests/taint/general/TestStep.ql index 710b180501d..c6de9cad361 100644 --- a/python/ql/test/library-tests/taint/general/TestStep.ql +++ b/python/ql/test/library-tests/taint/general/TestStep.ql @@ -2,11 +2,7 @@ import python import semmle.python.security.TaintTracking import TaintLib - from TaintedNode n, TaintedNode s -where - s = n.getASuccessor() -select - n.toString(), n.getLocation().toString(), n.getNode().toString(), n.getContext(), - "-->", +where s = n.getASuccessor() +select n.toString(), n.getLocation().toString(), n.getNode().toString(), n.getContext(), "-->", s.toString(), s.getLocation().toString(), s.getNode().toString(), s.getContext() diff --git a/python/ql/test/library-tests/taint/general/TestTaint.ql b/python/ql/test/library-tests/taint/general/TestTaint.ql index 3b8bf2b4bde..904cbbbded9 100644 --- a/python/ql/test/library-tests/taint/general/TestTaint.ql +++ b/python/ql/test/library-tests/taint/general/TestTaint.ql @@ -15,4 +15,5 @@ where taint_string = tainted.getTaintKind().toString() ) ) -select arg.getLocation().toString(), call.getScope().(Function).getName(), arg.toString(), taint_string +select arg.getLocation().toString(), call.getScope().(Function).getName(), arg.toString(), + taint_string diff --git a/python/ql/test/library-tests/taint/general/TestVar.ql b/python/ql/test/library-tests/taint/general/TestVar.ql index b90760f55ce..991d3cdbfa4 100644 --- a/python/ql/test/library-tests/taint/general/TestVar.ql +++ b/python/ql/test/library-tests/taint/general/TestVar.ql @@ -1,8 +1,7 @@ import python import TaintLib - from EssaVariable var, TaintedNode n where n.getNode().asVariable() = var -select - var.getDefinition().getLocation().toString(), var.getRepresentation(), n.getLocation().toString(), "Taint " + n.toString() +select var.getDefinition().getLocation().toString(), var.getRepresentation(), + n.getLocation().toString(), "Taint " + n.toString() diff --git a/python/ql/test/library-tests/taint/namedtuple/TestTaint.ql b/python/ql/test/library-tests/taint/namedtuple/TestTaint.ql index 92657b1fef9..8347bd25433 100644 --- a/python/ql/test/library-tests/taint/namedtuple/TestTaint.ql +++ b/python/ql/test/library-tests/taint/namedtuple/TestTaint.ql @@ -15,4 +15,5 @@ where taint_string = tainted.getTaintKind().toString() ) ) -select arg.getLocation().toString(), call.getScope().(Function).getName(), arg.toString(), taint_string +select arg.getLocation().toString(), call.getScope().(Function).getName(), arg.toString(), + taint_string diff --git a/python/ql/test/library-tests/taint/strings/TestStep.ql b/python/ql/test/library-tests/taint/strings/TestStep.ql index abec09b20d6..e7c014f2eb2 100644 --- a/python/ql/test/library-tests/taint/strings/TestStep.ql +++ b/python/ql/test/library-tests/taint/strings/TestStep.ql @@ -2,12 +2,10 @@ import python import semmle.python.security.TaintTracking import Taint - from TaintedNode n, TaintedNode s -where n.getLocation().getFile().getShortName() = "test.py" and -s.getLocation().getFile().getShortName() = "test.py" and -s = n.getASuccessor() -select - "Taint " + n.getTaintKind(), n.getLocation().toString(), n.getAstNode(), n.getContext(), - " --> ", - "Taint " + s.getTaintKind(), s.getLocation().toString(), s.getAstNode(), s.getContext() +where + n.getLocation().getFile().getShortName() = "test.py" and + s.getLocation().getFile().getShortName() = "test.py" and + s = n.getASuccessor() +select "Taint " + n.getTaintKind(), n.getLocation().toString(), n.getAstNode(), n.getContext(), + " --> ", "Taint " + s.getTaintKind(), s.getLocation().toString(), s.getAstNode(), s.getContext() diff --git a/python/ql/test/library-tests/taint/strings/TestTaint.ql b/python/ql/test/library-tests/taint/strings/TestTaint.ql index 92657b1fef9..8347bd25433 100644 --- a/python/ql/test/library-tests/taint/strings/TestTaint.ql +++ b/python/ql/test/library-tests/taint/strings/TestTaint.ql @@ -15,4 +15,5 @@ where taint_string = tainted.getTaintKind().toString() ) ) -select arg.getLocation().toString(), call.getScope().(Function).getName(), arg.toString(), taint_string +select arg.getLocation().toString(), call.getScope().(Function).getName(), arg.toString(), + taint_string diff --git a/python/ql/test/library-tests/taint/unpacking/TestTaint.ql b/python/ql/test/library-tests/taint/unpacking/TestTaint.ql index 92657b1fef9..8347bd25433 100644 --- a/python/ql/test/library-tests/taint/unpacking/TestTaint.ql +++ b/python/ql/test/library-tests/taint/unpacking/TestTaint.ql @@ -15,4 +15,5 @@ where taint_string = tainted.getTaintKind().toString() ) ) -select arg.getLocation().toString(), call.getScope().(Function).getName(), arg.toString(), taint_string +select arg.getLocation().toString(), call.getScope().(Function).getName(), arg.toString(), + taint_string diff --git a/python/ql/test/library-tests/thrift/Child.ql b/python/ql/test/library-tests/thrift/Child.ql index 5645c53ddb0..ebe72889aad 100644 --- a/python/ql/test/library-tests/thrift/Child.ql +++ b/python/ql/test/library-tests/thrift/Child.ql @@ -1,4 +1,3 @@ - import external.Thrift from ThriftElement t, int n diff --git a/python/ql/test/library-tests/thrift/File.ql b/python/ql/test/library-tests/thrift/File.ql index e4f497dbd01..7d85dd40ca4 100644 --- a/python/ql/test/library-tests/thrift/File.ql +++ b/python/ql/test/library-tests/thrift/File.ql @@ -1,7 +1,4 @@ - import external.Thrift - from ThriftNamedElement t - -select t.getName(), t.getFile().getBaseName() \ No newline at end of file +select t.getName(), t.getFile().getBaseName() diff --git a/python/ql/test/library-tests/thrift/Function.ql b/python/ql/test/library-tests/thrift/Function.ql index ff891bd5ece..2161fd8ec8a 100644 --- a/python/ql/test/library-tests/thrift/Function.ql +++ b/python/ql/test/library-tests/thrift/Function.ql @@ -1,12 +1,10 @@ - import external.Thrift from ThriftFunction t, string n, ThriftElement x where -exists(int i | x = t.getArgument(i) and n = i.toString()) -or -x = t.getAThrows() and n = "throws" -or -x = t.getReturnType() and n = "returns" - -select t, n, x \ No newline at end of file + exists(int i | x = t.getArgument(i) and n = i.toString()) + or + x = t.getAThrows() and n = "throws" + or + x = t.getReturnType() and n = "returns" +select t, n, x diff --git a/python/ql/test/library-tests/thrift/References.ql b/python/ql/test/library-tests/thrift/References.ql index c6621b44e95..f40e6e0a74b 100644 --- a/python/ql/test/library-tests/thrift/References.ql +++ b/python/ql/test/library-tests/thrift/References.ql @@ -1,4 +1,3 @@ - import python import external.Thrift diff --git a/python/ql/test/library-tests/thrift/Service.ql b/python/ql/test/library-tests/thrift/Service.ql index 801379c6a2e..3f3b07e0bc0 100644 --- a/python/ql/test/library-tests/thrift/Service.ql +++ b/python/ql/test/library-tests/thrift/Service.ql @@ -1,6 +1,4 @@ - import external.Thrift - from ThriftService service, string name select service, name, service.getFunction(name) diff --git a/python/ql/test/library-tests/thrift/Test.ql b/python/ql/test/library-tests/thrift/Test.ql index 735b9ad0eae..d755d9f1d26 100644 --- a/python/ql/test/library-tests/thrift/Test.ql +++ b/python/ql/test/library-tests/thrift/Test.ql @@ -1,7 +1,5 @@ - import external.Thrift from string cls where any(ThriftElement t).getAQlClass() = cls select cls.prefix(6) - diff --git a/python/ql/test/library-tests/thrift/Value.ql b/python/ql/test/library-tests/thrift/Value.ql index 7cf83b1df65..b42ae96d6ca 100644 --- a/python/ql/test/library-tests/thrift/Value.ql +++ b/python/ql/test/library-tests/thrift/Value.ql @@ -1,5 +1,4 @@ - import external.Thrift from ThriftElement t -select t, t.getValue() \ No newline at end of file +select t, t.getValue() diff --git a/python/ql/test/library-tests/types/attributes/Test.ql b/python/ql/test/library-tests/types/attributes/Test.ql index a92064a2551..a012b0d3a15 100644 --- a/python/ql/test/library-tests/types/attributes/Test.ql +++ b/python/ql/test/library-tests/types/attributes/Test.ql @@ -2,5 +2,5 @@ import python from ClassObject cls, ClassObject start, string name, Object val where not name.substring(0, 2) = "__" and val = cls.lookupMro(start, name) -select -cls.getOrigin().getLocation().getStartLine(), cls.toString(), start.toString(), name, val.toString(), val.getOrigin().getLocation().getStartLine() \ No newline at end of file +select cls.getOrigin().getLocation().getStartLine(), cls.toString(), start.toString(), name, + val.toString(), val.getOrigin().getLocation().getStartLine() diff --git a/python/ql/test/library-tests/types/classattr/ClassAttribute.ql b/python/ql/test/library-tests/types/classattr/ClassAttribute.ql index 6895020718e..6e023dcada5 100644 --- a/python/ql/test/library-tests/types/classattr/ClassAttribute.ql +++ b/python/ql/test/library-tests/types/classattr/ClassAttribute.ql @@ -8,12 +8,11 @@ import python from ClassObject cls, string name, string kind where -not cls.isC() and -not name.matches("\\_\\_%\\_\\_") and -( - cls.hasAttribute(name) and kind = "has" - or - cls.declaresAttribute(name) and kind = "declares" -) -select cls.toString(), kind ,name - + not cls.isC() and + not name.matches("\\_\\_%\\_\\_") and + ( + cls.hasAttribute(name) and kind = "has" + or + cls.declaresAttribute(name) and kind = "declares" + ) +select cls.toString(), kind, name diff --git a/python/ql/test/library-tests/types/classattr/ClassMember.ql b/python/ql/test/library-tests/types/classattr/ClassMember.ql index b76851dd43d..1357deb0da9 100644 --- a/python/ql/test/library-tests/types/classattr/ClassMember.ql +++ b/python/ql/test/library-tests/types/classattr/ClassMember.ql @@ -7,12 +7,12 @@ import python from ClassObject cls, string name, string kind, Object o -where -not cls.isC() and -not name.matches("\\_\\_%\\_\\_") and -( - o = cls.lookupAttribute(name) and kind = "has" - or - o = cls.declaredAttribute(name) and kind = "declares" -) +where + not cls.isC() and + not name.matches("\\_\\_%\\_\\_") and + ( + o = cls.lookupAttribute(name) and kind = "has" + or + o = cls.declaredAttribute(name) and kind = "declares" + ) select cls.toString(), kind, name, o.toString() diff --git a/python/ql/test/library-tests/types/classattr/SpecialAttribute.ql b/python/ql/test/library-tests/types/classattr/SpecialAttribute.ql index cdfd29b8d91..26e9ad08c26 100644 --- a/python/ql/test/library-tests/types/classattr/SpecialAttribute.ql +++ b/python/ql/test/library-tests/types/classattr/SpecialAttribute.ql @@ -1,14 +1,13 @@ - import python from ClassObject cls, string name, string kind, Object o -where -not cls.isC() and -name.matches("\\_\\_%\\_\\_") and -not o = theObjectType().lookupAttribute(name) and -( - o = cls.lookupAttribute(name) and kind = "has" - or - o = cls.declaredAttribute(name) and kind = "declares" -) +where + not cls.isC() and + name.matches("\\_\\_%\\_\\_") and + not o = theObjectType().lookupAttribute(name) and + ( + o = cls.lookupAttribute(name) and kind = "has" + or + o = cls.declaredAttribute(name) and kind = "declares" + ) select cls.toString(), kind, name, o.toString() diff --git a/python/ql/test/library-tests/types/classes/FailedInference.ql b/python/ql/test/library-tests/types/classes/FailedInference.ql index df5e2ccf14f..192cf696fbf 100644 --- a/python/ql/test/library-tests/types/classes/FailedInference.ql +++ b/python/ql/test/library-tests/types/classes/FailedInference.ql @@ -1,11 +1,6 @@ - import python import semmle.python.pointsto.PointsTo from ClassValue cls, string reason - -where -Types::failedInference(cls, reason) - +where Types::failedInference(cls, reason) select cls, reason - diff --git a/python/ql/test/library-tests/types/classes/duplicate_base.ql b/python/ql/test/library-tests/types/classes/duplicate_base.ql index 4f865754088..47e975c4560 100644 --- a/python/ql/test/library-tests/types/classes/duplicate_base.ql +++ b/python/ql/test/library-tests/types/classes/duplicate_base.ql @@ -1,7 +1,5 @@ - import python from ClassObject cls where cls.hasDuplicateBases() select cls.toString() - diff --git a/python/ql/test/library-tests/types/exceptions/ExitRaises.ql b/python/ql/test/library-tests/types/exceptions/ExitRaises.ql index efa1f66b8d8..62be45dce8e 100644 --- a/python/ql/test/library-tests/types/exceptions/ExitRaises.ql +++ b/python/ql/test/library-tests/types/exceptions/ExitRaises.ql @@ -2,5 +2,4 @@ import python from RaisingNode r, Scope s, ClassObject cls where r.viableExceptionalExit(s, cls) - select r.getLocation().getStartLine(), r, s.toString(), cls diff --git a/python/ql/test/library-tests/types/exceptions/Handles.ql b/python/ql/test/library-tests/types/exceptions/Handles.ql index 51ceba1a6fb..601f2632392 100644 --- a/python/ql/test/library-tests/types/exceptions/Handles.ql +++ b/python/ql/test/library-tests/types/exceptions/Handles.ql @@ -1,5 +1,3 @@ - - import python from ExceptFlowNode n, ClassObject cls diff --git a/python/ql/test/library-tests/types/exceptions/Impossible.ql b/python/ql/test/library-tests/types/exceptions/Impossible.ql index e215a7e96ca..69c658edba6 100644 --- a/python/ql/test/library-tests/types/exceptions/Impossible.ql +++ b/python/ql/test/library-tests/types/exceptions/Impossible.ql @@ -1,20 +1,19 @@ - - import python from RaisingNode r, ControlFlowNode n, string kind -where r.unlikelySuccessor(n) and -( - r.getATrueSuccessor() = n and kind = "true" - or - r.getAFalseSuccessor() = n and kind = "false" - or - r.getAnExceptionalSuccessor() = n and kind = "exceptional" - or - not r.getATrueSuccessor() = n and - not r.getAFalseSuccessor() = n and - not r.getAnExceptionalSuccessor() = n and - kind = "normal" - -) -select r.getLocation().getStartLine(), n.getLocation().getStartLine(), r.getNode().toString(), n.getNode().toString(), kind +where + r.unlikelySuccessor(n) and + ( + r.getATrueSuccessor() = n and kind = "true" + or + r.getAFalseSuccessor() = n and kind = "false" + or + r.getAnExceptionalSuccessor() = n and kind = "exceptional" + or + not r.getATrueSuccessor() = n and + not r.getAFalseSuccessor() = n and + not r.getAnExceptionalSuccessor() = n and + kind = "normal" + ) +select r.getLocation().getStartLine(), n.getLocation().getStartLine(), r.getNode().toString(), + n.getNode().toString(), kind diff --git a/python/ql/test/library-tests/types/exceptions/LineRaises.ql b/python/ql/test/library-tests/types/exceptions/LineRaises.ql index f1f51952d00..933eb8d59bb 100644 --- a/python/ql/test/library-tests/types/exceptions/LineRaises.ql +++ b/python/ql/test/library-tests/types/exceptions/LineRaises.ql @@ -1,13 +1,12 @@ - import python from RaisingNode r, string type -where +where type = r.getARaisedType().toString() or type = "Unknown" and r.raisesUnknownType() or not exists(r.getARaisedType()) and - not r.raisesUnknownType() and type = "None" - + not r.raisesUnknownType() and + type = "None" select r.getNode().getLocation().getStartLine(), type diff --git a/python/ql/test/library-tests/types/exceptions/Raises.ql b/python/ql/test/library-tests/types/exceptions/Raises.ql index b003fd03dfa..aa477f718a2 100644 --- a/python/ql/test/library-tests/types/exceptions/Raises.ql +++ b/python/ql/test/library-tests/types/exceptions/Raises.ql @@ -1,13 +1,12 @@ - import python from PyFunctionObject f, string type -where +where type = f.getARaisedType().toString() or type = "Unknown" and f.raisesUnknownType() or not exists(f.getARaisedType()) and - not f.raisesUnknownType() and type = "None" - -select f.toString(), type \ No newline at end of file + not f.raisesUnknownType() and + type = "None" +select f.toString(), type diff --git a/python/ql/test/library-tests/types/exceptions/Reraises.ql b/python/ql/test/library-tests/types/exceptions/Reraises.ql index 9edcdf57b4b..699eb325f8c 100644 --- a/python/ql/test/library-tests/types/exceptions/Reraises.ql +++ b/python/ql/test/library-tests/types/exceptions/Reraises.ql @@ -1,6 +1,4 @@ - import python from ReraisingNode r - -select r.getLocation().getStartLine(), r, r.getARaisedType().toString() \ No newline at end of file +select r.getLocation().getStartLine(), r, r.getARaisedType().toString() diff --git a/python/ql/test/library-tests/types/exceptions/Viable.ql b/python/ql/test/library-tests/types/exceptions/Viable.ql index 544b0a0d0b6..e28fa1a907c 100644 --- a/python/ql/test/library-tests/types/exceptions/Viable.ql +++ b/python/ql/test/library-tests/types/exceptions/Viable.ql @@ -1,7 +1,6 @@ - - import python from RaisingNode r, ControlFlowNode n, ClassObject ex where r.viableExceptionEdge(n, ex) -select r.getLocation().getStartLine(), n.getLocation().getStartLine(), r.getNode().toString(), n.getNode().toString(), ex.toString() +select r.getLocation().getStartLine(), n.getLocation().getStartLine(), r.getNode().toString(), + n.getNode().toString(), ex.toString() diff --git a/python/ql/test/library-tests/types/functions/Zope.ql b/python/ql/test/library-tests/types/functions/Zope.ql index 91b828b2ff2..ca1c1a0f596 100644 --- a/python/ql/test/library-tests/types/functions/Zope.ql +++ b/python/ql/test/library-tests/types/functions/Zope.ql @@ -1,4 +1,3 @@ - import python import semmle.python.libraries.Zope diff --git a/python/ql/test/library-tests/types/properties/Deleters.ql b/python/ql/test/library-tests/types/properties/Deleters.ql index e57f5917e6e..ad99ceb387d 100644 --- a/python/ql/test/library-tests/types/properties/Deleters.ql +++ b/python/ql/test/library-tests/types/properties/Deleters.ql @@ -1,5 +1,4 @@ import python from PythonPropertyObject p - select p.toString(), p.getDeleter().toString() diff --git a/python/ql/test/library-tests/types/properties/Getters.ql b/python/ql/test/library-tests/types/properties/Getters.ql index 2d495ccfc2f..5f232858696 100644 --- a/python/ql/test/library-tests/types/properties/Getters.ql +++ b/python/ql/test/library-tests/types/properties/Getters.ql @@ -1,5 +1,4 @@ import python from PythonPropertyObject p - select p.toString(), p.getGetter().toString() diff --git a/python/ql/test/library-tests/types/properties/PythonProperties.ql b/python/ql/test/library-tests/types/properties/PythonProperties.ql index 91281c321a0..858326d6ac0 100644 --- a/python/ql/test/library-tests/types/properties/PythonProperties.ql +++ b/python/ql/test/library-tests/types/properties/PythonProperties.ql @@ -1,5 +1,4 @@ import python -from PythonPropertyObject p - +from PythonPropertyObject p select p.toString() diff --git a/python/ql/test/library-tests/types/properties/Setters.ql b/python/ql/test/library-tests/types/properties/Setters.ql index 4e13e54db63..871e6f9145f 100644 --- a/python/ql/test/library-tests/types/properties/Setters.ql +++ b/python/ql/test/library-tests/types/properties/Setters.ql @@ -1,5 +1,4 @@ import python from PythonPropertyObject p - select p.toString(), p.getSetter().toString() diff --git a/python/ql/test/library-tests/variables/definitions/test.ql b/python/ql/test/library-tests/variables/definitions/test.ql index 9abee816b3a..a3f0fab8155 100644 --- a/python/ql/test/library-tests/variables/definitions/test.ql +++ b/python/ql/test/library-tests/variables/definitions/test.ql @@ -1,5 +1,4 @@ import python from DefinitionNode d - select d.getLocation().getStartLine(), d.getLocation().getStartColumn(), d.toString() diff --git a/python/ql/test/library-tests/variables/scopes/free.ql b/python/ql/test/library-tests/variables/scopes/free.ql index 1e15bb3a312..65789e76a52 100644 --- a/python/ql/test/library-tests/variables/scopes/free.ql +++ b/python/ql/test/library-tests/variables/scopes/free.ql @@ -1,7 +1,8 @@ import python from LocalVariable v, Scope inner -where v.escapes() and inner = v.getAnAccess().getScope() and -inner != v.getScope() +where + v.escapes() and + inner = v.getAnAccess().getScope() and + inner != v.getScope() select v.toString(), v.getScope().toString(), inner.toString() - diff --git a/python/ql/test/library-tests/variables/scopes/globals.ql b/python/ql/test/library-tests/variables/scopes/globals.ql index 8d200aa81b0..65e572c2ab4 100644 --- a/python/ql/test/library-tests/variables/scopes/globals.ql +++ b/python/ql/test/library-tests/variables/scopes/globals.ql @@ -2,4 +2,3 @@ import python from GlobalVariable l select l.toString(), l.getScope().toString() - diff --git a/python/ql/test/library-tests/variables/scopes/locals.ql b/python/ql/test/library-tests/variables/scopes/locals.ql index 264c5e9b7d1..62814925fe9 100644 --- a/python/ql/test/library-tests/variables/scopes/locals.ql +++ b/python/ql/test/library-tests/variables/scopes/locals.ql @@ -1,10 +1,8 @@ import python from LocalVariable l, string kind -where -l instanceof FastLocalVariable and kind = "fast" -or -l instanceof NameLocalVariable and kind = "name" - +where + l instanceof FastLocalVariable and kind = "fast" + or + l instanceof NameLocalVariable and kind = "name" select l, l.getScope(), kind - diff --git a/python/ql/test/library-tests/variables/scopes/lookup.ql b/python/ql/test/library-tests/variables/scopes/lookup.ql index c7a776c7caa..248cd62b911 100644 --- a/python/ql/test/library-tests/variables/scopes/lookup.ql +++ b/python/ql/test/library-tests/variables/scopes/lookup.ql @@ -2,15 +2,17 @@ import python from NameNode n, string l where -n.isLoad() and ( - n.isGlobal() and l = "global" - or - n.isLocal() and l = "local" - or - n.isNonLocal() and l = "non-local" - or - not n.isGlobal() and not n.isLocal() and - not n.isNonLocal() and - l = "none" -) + n.isLoad() and + ( + n.isGlobal() and l = "global" + or + n.isLocal() and l = "local" + or + n.isNonLocal() and l = "non-local" + or + not n.isGlobal() and + not n.isLocal() and + not n.isNonLocal() and + l = "none" + ) select n.getLocation().getStartLine(), n.toString(), l diff --git a/python/ql/test/library-tests/variables/scopes/scopes.ql b/python/ql/test/library-tests/variables/scopes/scopes.ql index b87a45c9939..b722b89e51e 100644 --- a/python/ql/test/library-tests/variables/scopes/scopes.ql +++ b/python/ql/test/library-tests/variables/scopes/scopes.ql @@ -1,4 +1,3 @@ - import python from Variable v, Scope s diff --git a/python/ql/test/library-tests/web/client/requests/ClientHttpRequests.ql b/python/ql/test/library-tests/web/client/requests/ClientHttpRequests.ql index cbeed6c2e4b..52fd7ff218e 100644 --- a/python/ql/test/library-tests/web/client/requests/ClientHttpRequests.ql +++ b/python/ql/test/library-tests/web/client/requests/ClientHttpRequests.ql @@ -1,11 +1,7 @@ import python - import semmle.python.web.Http import semmle.python.web.ClientHttpRequest from Client::HttpRequest req, string method -where - if exists(req.getMethodUpper()) - then method = req.getMethodUpper() - else method = "" +where if exists(req.getMethodUpper()) then method = req.getMethodUpper() else method = "" select req, req.getAUrlPart(), method diff --git a/python/ql/test/library-tests/web/client/six/ClientHttpRequests.ql b/python/ql/test/library-tests/web/client/six/ClientHttpRequests.ql index cbeed6c2e4b..52fd7ff218e 100644 --- a/python/ql/test/library-tests/web/client/six/ClientHttpRequests.ql +++ b/python/ql/test/library-tests/web/client/six/ClientHttpRequests.ql @@ -1,11 +1,7 @@ import python - import semmle.python.web.Http import semmle.python.web.ClientHttpRequest from Client::HttpRequest req, string method -where - if exists(req.getMethodUpper()) - then method = req.getMethodUpper() - else method = "" +where if exists(req.getMethodUpper()) then method = req.getMethodUpper() else method = "" select req, req.getAUrlPart(), method diff --git a/python/ql/test/library-tests/web/client/stdlib/ClientHttpRequests.ql b/python/ql/test/library-tests/web/client/stdlib/ClientHttpRequests.ql index cbeed6c2e4b..52fd7ff218e 100644 --- a/python/ql/test/library-tests/web/client/stdlib/ClientHttpRequests.ql +++ b/python/ql/test/library-tests/web/client/stdlib/ClientHttpRequests.ql @@ -1,11 +1,7 @@ import python - import semmle.python.web.Http import semmle.python.web.ClientHttpRequest from Client::HttpRequest req, string method -where - if exists(req.getMethodUpper()) - then method = req.getMethodUpper() - else method = "" +where if exists(req.getMethodUpper()) then method = req.getMethodUpper() else method = "" select req, req.getAUrlPart(), method diff --git a/python/ql/test/query-tests/Metrics/ratios/CodeRatio.ql b/python/ql/test/query-tests/Metrics/ratios/CodeRatio.ql index 545453e93eb..8525edcb8b8 100644 --- a/python/ql/test/query-tests/Metrics/ratios/CodeRatio.ql +++ b/python/ql/test/query-tests/Metrics/ratios/CodeRatio.ql @@ -1,7 +1,6 @@ - import python from Module m, ModuleMetrics mm where mm = m.getMetrics() and mm.getNumberOfLines() > 0 -select m, 100.0 * ((float)mm.getNumberOfLinesOfCode() / (float)mm.getNumberOfLines()) as ratio -order by ratio desc \ No newline at end of file +select m, 100.0 * (mm.getNumberOfLinesOfCode().(float) / mm.getNumberOfLines().(float)) as ratio + order by ratio desc diff --git a/python/ql/test/query-tests/Resources/Dataflow.ql b/python/ql/test/query-tests/Resources/Dataflow.ql index ee92ee981c3..4e2cf15b50d 100644 --- a/python/ql/test/query-tests/Resources/Dataflow.ql +++ b/python/ql/test/query-tests/Resources/Dataflow.ql @@ -1,16 +1,14 @@ - import python import Resources.FileOpen - from EssaVariable v, EssaDefinition def, string open, string exit -where def = v.getDefinition() and v.getSourceVariable().getName().charAt(0) = "f" and -( - var_is_open(v, _) and open = "open" - or - not var_is_open(v, _) and open = "closed" -) -and -if BaseFlow::reaches_exit(v) then exit = "exit" else exit = "" - +where + def = v.getDefinition() and + v.getSourceVariable().getName().charAt(0) = "f" and + ( + var_is_open(v, _) and open = "open" + or + not var_is_open(v, _) and open = "closed" + ) and + if BaseFlow::reaches_exit(v) then exit = "exit" else exit = "" select v.getRepresentation() + " = " + v.getDefinition().getRepresentation(), open, exit diff --git a/python/ql/test/query-tests/Security/CWE-327/TestNode.ql b/python/ql/test/query-tests/Security/CWE-327/TestNode.ql index 046378e4ea1..50305f21a2e 100644 --- a/python/ql/test/query-tests/Security/CWE-327/TestNode.ql +++ b/python/ql/test/query-tests/Security/CWE-327/TestNode.ql @@ -1,6 +1,5 @@ import python import semmle.python.security.TaintTracking - import python import semmle.python.security.SensitiveData import semmle.python.security.Crypto