types -> typez as the name mirrors a python core library name.
authorScott Gasch <[email protected]>
Sun, 5 Mar 2023 02:15:52 +0000 (18:15 -0800)
committerScott Gasch <[email protected]>
Sun, 5 Mar 2023 02:15:52 +0000 (18:15 -0800)
16 files changed:
docs/pyutils.rst
examples/wordle/wordle.py
src/pyutils/collectionz/interval_tree.py
src/pyutils/graph.py
src/pyutils/math_utils.py
src/pyutils/parallelize/executors.py
src/pyutils/typez/__init__.py [moved from src/pyutils/types/__init__.py with 100% similarity]
src/pyutils/typez/centcount.py [moved from src/pyutils/types/centcount.py with 99% similarity]
src/pyutils/typez/histogram.py [moved from src/pyutils/types/histogram.py with 100% similarity]
src/pyutils/typez/money.py [moved from src/pyutils/types/money.py with 99% similarity]
src/pyutils/typez/rate.py [moved from src/pyutils/types/rate.py with 100% similarity]
src/pyutils/typez/simple.py [moved from src/pyutils/types/simple.py with 100% similarity]
src/pyutils/typez/type_utils.py [moved from src/pyutils/types/type_utils.py with 100% similarity]
tests/typez/centcount_test.py [moved from tests/types/centcount_test.py with 98% similarity]
tests/typez/money_test.py [moved from tests/types/money_test.py with 98% similarity]
tests/typez/rate_test.py [moved from tests/types/rate_test.py with 95% similarity]

index aff3220fec9d2178cf3f059c5fdad56023731d90..888b660c3ef9ba11d52d2b4cd839507b1fb0034e 100644 (file)
@@ -55,7 +55,7 @@ Most code includes inline documentation and doctests.  I've tried to
 organize it into logical packages based on the code's functionality.
 Note that when words would collide with a Python standard library or
 reserved keyword I've used a 'z' at the end, e.g. 'collectionz'
-instead of 'collections'.
+instead of 'collections' and 'typez' instead of 'types'.
 
 There's some example code that uses various features of this project checked
 in under `examples/ <https://wannabe.guru.org/gitweb/?p=pyutils.git;a=tree;f=examples;h=d9744bf2b171ba7a9ff21ae1d3862b673647fff4;hb=HEAD>`_ that you can check out.  See the `README <http://wannabe.guru.org/gitweb/?p=pyutils.git;a=blob_plain;f=examples/README;hb=HEAD>`__ in that directory for more information
index ca7930a384f203b0360cd1355ac82b146540181e..a3042eee1c8486c8382a62fe3c8e3c096bf8c263 100755 (executable)
@@ -24,7 +24,7 @@ from pyutils.files import file_utils
 from pyutils.parallelize import executors
 from pyutils.parallelize import parallelize as par
 from pyutils.parallelize import smart_future
-from pyutils.types import histogram
+from pyutils.typez import histogram
 
 logger = logging.getLogger(__name__)
 args = config.add_commandline_args(
@@ -574,7 +574,7 @@ class AutoPlayer(object):
         self.position_hash = {}
         filename = config.config['hash_file']
         if filename is not None and file_utils.is_readable(filename):
-            logger.debug(f'Initializing position hash from {filename}...')
+            logger.debug('Initializing position hash from %s...', filename)
             with open(filename, 'r') as rf:
                 for line in rf:
                     line = line[:-1]
@@ -589,13 +589,13 @@ class AutoPlayer(object):
                     fprint = fprint.strip()
                     word = word.strip()
                     self.position_hash[(count, fprint)] = word
-            logger.debug(f'...hash contains {len(self.position_hash)} entries.')
+            logger.debug('...hash contains %s entries.', len(self.position_hash))
 
         # All legal solutions pre-sorted by length.
         self.all_possible_solutions_by_length = defaultdict(list)
         filename = config.config['solutions_file']
         if filename is not None and file_utils.is_readable(filename):
-            logger.debug(f'Initializing valid solution word list from {filename}...')
+            logger.debug('Initializing valid solution word list from %s...', filename)
             with open(filename) as rf:
                 for word in rf:
                     word = word[:-1]
@@ -609,7 +609,7 @@ class AutoPlayer(object):
         self.all_possible_guesses_by_length = defaultdict(list)
         filename = config.config['guesses_file']
         if filename is not None and file_utils.is_readable(filename):
-            logger.debug(f'Initializing legal guess word list from {filename}...')
+            logger.debug('Initializing legal guess word list from %s...', filename)
             with open(filename) as rf:
                 for word in rf:
                     word = word[:-1]
@@ -756,7 +756,7 @@ class AutoPlayer(object):
         out = ''
         for letter, weight in sorted(letter_frequency.items(), key=lambda x: -x[1]):
             out += f'{letter}:{weight}, '
-        if len(out):
+        if len(out) > 0:
             out = out[:-2]
             logger.debug(out)
 
@@ -766,7 +766,7 @@ class AutoPlayer(object):
             pop = letter_position_frequency[n]
             for letter, weight in sorted(pop.items(), key=lambda x: -x[1]):
                 out += f'pos{n}:{letter}@{weight:.5f}, '
-        if len(out):
+        if len(out) > 0:
             out = out[:-2]
             logger.debug(out)
 
@@ -780,7 +780,7 @@ class AutoPlayer(object):
         template = self.word_state.get_template()
         possible_solutions = self.get_all_possible_solutions()
         num_possible_solutions = len(possible_solutions)
-        fprint = hashlib.md5(possible_solutions.__repr__().encode('ascii')).hexdigest()
+        fprint = hashlib.md5(repr(possible_solutions).encode('ascii')).hexdigest()
 
         n = num_possible_solutions
         logger.debug(
@@ -797,7 +797,7 @@ class AutoPlayer(object):
                 )
             )
         logger.debug(
-            f'Letter count restrictions: {self.word_state.letters_in_solution}'
+            'Letter count restrictions: %s', self.word_state.letters_in_solution
         )
         if num_possible_solutions == 0:
             logger.error('No possible solutions?!')
@@ -812,7 +812,7 @@ class AutoPlayer(object):
         # Check the hash table for a precomputed best guess.
         elif self.position_in_hash(num_possible_solutions, fprint):
             guess = self.position_hash[(num_possible_solutions, fprint)]
-            logger.debug(f'hash hit: {guess}')
+            logger.debug('hash hit: %s', guess)
             return guess
 
         # If there are just a few solutions possible, brute force the
@@ -821,7 +821,7 @@ class AutoPlayer(object):
         # large numbers of solutions.
         elif num_possible_solutions < 20:
             logger.debug(
-                f'Only {num_possible_solutions} solutions; using brute force strategy.'
+                'Only %d solutions; using brute force strategy.', num_possible_solutions
             )
             return self.brute_force_internal(
                 possible_solutions,
@@ -834,7 +834,7 @@ class AutoPlayer(object):
         # guesses via brute force.
         elif num_possible_solutions < 100:
             logger.debug(
-                f'Only {num_possible_solutions} solutions; using hybrid strategy.'
+                'Only %d solutions; using hybrid strategy.', num_possible_solutions
             )
             return self.hybrid_search(possible_solutions)
 
@@ -842,7 +842,7 @@ class AutoPlayer(object):
         # fast heuristics (i.e. letter frequency).
         else:
             logger.debug(
-                f'There are {num_possible_solutions} solutions; using fast heuristics.'
+                'There are %s solutions; using fast heuristics.', num_possible_solutions
             )
             return self.heuristics_search(possible_solutions)
 
@@ -969,7 +969,7 @@ class AutoPlayer(object):
             elif guess_entropy == best_entropy and best_count < 15:
                 logger.debug(f'{label}: #{n}: {guess} with {guess_entropy:.5f} bits')
                 best_count += 1
-        logger.debug(f'{label}: best guess is {best_guess}.')
+        logger.debug('%s: best guess is %s.', label, best_guess)
         return best_guess
 
     def hybrid_search(self, possible_solutions: List[Word]) -> Optional[Word]:
@@ -1154,7 +1154,7 @@ def cheat():
     if not avoid:
         avoid = ''
     avoid = avoid.lower()
-    letters_to_avoid = set([letter for letter in avoid])
+    letters_to_avoid = set(list(avoid))
 
     # Initialize the set of letters we know are in the solution but
     # not where, yet.
@@ -1528,7 +1528,7 @@ def play() -> None:
         if guess == solution:
             print('Nice!')
             break
-        elif num_guesses >= 6:
+        if num_guesses >= 6:
             print('Better luck next time.')
             print(padding + f'{solution}')
             break
index 4a8bdd806cec001bca5a87b963eab6368bbd9c58..0a88a3d844b2ba71b84f0e2a244cd56caa17cd9b 100644 (file)
@@ -14,7 +14,7 @@ from typing import Any, Generator, Optional
 from overrides import overrides
 
 from pyutils.collectionz import bst
-from pyutils.types.simple import Numeric
+from pyutils.typez.simple import Numeric
 
 
 @total_ordering
index 411eb1303cf9819d7f4b91b69ccae4e5d292ec4c..faa0ec3ef69edf186dce6752289beb6cf4dda700 100644 (file)
@@ -10,7 +10,7 @@ import math
 from typing import Dict, Generator, List, Optional, Set, Tuple
 
 from pyutils import list_utils
-from pyutils.types.simple import Numeric
+from pyutils.typez.simple import Numeric
 
 
 class Graph(object):
index 9de20522feaaadc8bc7bf23fa7759335f184dddd..4ceee8cb838a788660a979d3bd864e81f3fa735a 100644 (file)
@@ -11,7 +11,7 @@ from heapq import heappop, heappush
 from typing import Dict, List, Optional, Tuple
 
 from pyutils import dict_utils
-from pyutils.types.simple import Numeric
+from pyutils.typez.simple import Numeric
 
 
 class NumericPopulation(object):
index e5cfcfe14a1534d4db3be77f98408f549aa64ca9..fd8cc7cdc31ce221059e66bcc68f53873135d4cb 100644 (file)
@@ -57,7 +57,7 @@ from typing import Any, Callable, Dict, List, Optional, Set
 import cloudpickle  # type: ignore
 from overrides import overrides
 
-import pyutils.types.histogram as hist
+import pyutils.typez.histogram as hist
 from pyutils import (
     argparse_utils,
     config,
@@ -70,7 +70,7 @@ from pyutils.ansi import bg, fg, reset, underline
 from pyutils.decorator_utils import singleton
 from pyutils.exec_utils import cmd_exitcode, cmd_in_background, run_silently
 from pyutils.parallelize.thread_utils import background_thread
-from pyutils.types import type_utils
+from pyutils.typez import type_utils
 
 logger = logging.getLogger(__name__)
 
similarity index 99%
rename from src/pyutils/types/centcount.py
rename to src/pyutils/typez/centcount.py
index 58a8274439974ac3ef34af977ec25c30f0867364..a17060d56d414e3a61416cef0ac629823986ad2a 100644 (file)
@@ -41,7 +41,7 @@ numbers).
     of this and decide whether it's suitable for your
     application.
 
-See also the :class:`pyutils.types.Money` class which uses Python
+See also the :class:`pyutils.typez.Money` class which uses Python
 Decimals (see: https://docs.python.org/3/library/decimal.html) to
 represent monetary amounts.
 """
similarity index 99%
rename from src/pyutils/types/money.py
rename to src/pyutils/typez/money.py
index 3a23afc5ca90fe525c77b519e36cdd922d8ef593..5eafd636bed88b6fba4ce6170b255d8a749a6f58 100644 (file)
@@ -11,7 +11,7 @@ another, and has a strict mode which disallows comparison or
 aggregation with non-:class:`Money` operands (i.e. no comparison or
 aggregation with literal numbers).
 
-See also :class:`pyutils.types.centcount.CentCount` which represents
+See also :class:`pyutils.typez.centcount.CentCount` which represents
 monetary amounts as an integral number of cents.
 """
 
similarity index 98%
rename from tests/types/centcount_test.py
rename to tests/typez/centcount_test.py
index 62181f4d5b41e8abea040c9db0ddbc0be212c208..f5cc4ca09d35803739808e4dca5169a4371b71eb 100755 (executable)
@@ -7,7 +7,7 @@
 import unittest
 
 from pyutils import unittest_utils
-from pyutils.types.centcount import CentCount
+from pyutils.typez.centcount import CentCount
 
 
 class TestCentCount(unittest.TestCase):
similarity index 98%
rename from tests/types/money_test.py
rename to tests/typez/money_test.py
index 524f10339705f60e999dc6abfcfbeeaa63a67668..9b87eb82a1712f392e142e7c29405feed04c5995 100755 (executable)
@@ -8,7 +8,7 @@ import unittest
 from decimal import Decimal
 
 from pyutils import unittest_utils
-from pyutils.types.money import Money
+from pyutils.typez.money import Money
 
 
 class TestMoney(unittest.TestCase):
similarity index 95%
rename from tests/types/rate_test.py
rename to tests/typez/rate_test.py
index 15449ebfed96ff58b5a8da3b6ede9ade2e79719c..ff9dcdd97647c1a45fce9db1cf05885c8ebcc309 100755 (executable)
@@ -7,8 +7,8 @@
 import unittest
 
 from pyutils import unittest_utils
-from pyutils.types.money import Money
-from pyutils.types.rate import Rate
+from pyutils.typez.money import Money
+from pyutils.typez.rate import Rate
 
 
 class TestRate(unittest.TestCase):