From 6671837bcffeca741049265562bad89a282f6921 Mon Sep 17 00:00:00 2001 From: Rick Gutleber Date: Wed, 3 Jan 2024 10:42:31 -0500 Subject: [PATCH] changes based on pylint feedback --- pylintrc | 5 ++--- rpn/math/factorise.py | 35 ++++++++++++++--------------------- rpn/math/rpnNumberTheory.py | 5 +++-- rpn/special/rpnLocation.py | 1 - 4 files changed, 19 insertions(+), 27 deletions(-) diff --git a/pylintrc b/pylintrc index 8256d6a..0369ec4 100644 --- a/pylintrc +++ b/pylintrc @@ -514,10 +514,9 @@ known-third-party=enchant # Couples of modules and preferred modules, separated by a comma. preferred-modules= - [EXCEPTIONS] # Exceptions that will emit a warning when being caught. Defaults to # "BaseException, Exception". -overgeneral-exceptions=BaseException, - Exception +overgeneral-exceptions=builtins.BaseException, + builtins.Exception diff --git a/rpn/math/factorise.py b/rpn/math/factorise.py index 17d6778..59ccae2 100644 --- a/rpn/math/factorise.py +++ b/rpn/math/factorise.py @@ -3,31 +3,24 @@ # pylint: disable=invalid-name from builtins import ValueError -from math import sqrt, log2, ceil, floor +from math import gcd, sqrt, log2, ceil, floor import random import sys -if sys.version_info[ 0 ] == 3 and sys.version_info[ 1 ] >= 9: - from math import gcd -else: - from fractions import gcd - -""" -This script factorises a natural number given as a command line -parameter into its prime factors. It first attempts to use trial -division to find very small factors, then uses Brent's version of the -Pollard rho algorithm [1] to find slightly larger factors. If any large -factors remain, it uses the Self-Initializing Quadratic Sieve (SIQS) [2] -to factorise those. - -[1] Brent, Richard P. 'An improved Monte Carlo factorization algorithm.' - BIT Numerical Mathematics 20.2 (1980): 176-184. - -[2] Contini, Scott Patrick. 'Factoring integers with the self- - initializing quadratic sieve.' (1997). -""" - +# This script factorises a natural number given as a command line +# parameter into its prime factors. It first attempts to use trial +# division to find very small factors, then uses Brent's version of the +# Pollard rho algorithm [1] to find slightly larger factors. If any large +# factors remain, it uses the Self-Initializing Quadratic Sieve (SIQS) [2] +# to factorise those. +# +# [1] Brent, Richard P. 'An improved Monte Carlo factorization algorithm.' +# BIT Numerical Mathematics 20.2 (1980): 176-184. +# +# [2] Contini, Scott Patrick. 'Factoring integers with the self- +# initializing quadratic sieve.' (1997). +3 # Some tuning parameters MAX_DIGITS_POLLARD = 30 POLLARD_QUICK_ITERATIONS = 20 diff --git a/rpn/math/rpnNumberTheory.py b/rpn/math/rpnNumberTheory.py index 0cba1fb..0839d0e 100644 --- a/rpn/math/rpnNumberTheory.py +++ b/rpn/math/rpnNumberTheory.py @@ -37,7 +37,7 @@ from rpn.util.rpnSettings import setAccuracy from rpn.util.rpnUtils import getMPFIntegerAsString, listArgFunctionEvaluator, \ listAndOneArgFunctionEvaluator, oneArgFunctionEvaluator, setAccuracyForN, \ - twoArgFunctionEvaluator, parallel + twoArgFunctionEvaluator from rpn.util.rpnValidator import argValidator, ComplexValidator, IntValidator, ListValidator, RealValidator @@ -1579,7 +1579,8 @@ def getAliquotSequenceGenerator( n, k ): if b == 1: break - elif b in results: + + if b in results: break a = b diff --git a/rpn/special/rpnLocation.py b/rpn/special/rpnLocation.py index 4a6456a..0e7360a 100644 --- a/rpn/special/rpnLocation.py +++ b/rpn/special/rpnLocation.py @@ -12,7 +12,6 @@ # #****************************************************************************** -import datetime import ephem import pendulum