From 5466741b6958e1fe588675f4fb7d182c05f462da Mon Sep 17 00:00:00 2001 From: Mark Mayo Date: Thu, 25 May 2023 13:51:32 +1200 Subject: [PATCH] language cleanups cleaned imports updated assertregexpmatches to assertregex simplied if checks tidied whitespace --- failures-to-investigate/freshsales.py | 9 +++++---- failures-to-investigate/freshsales2.py | 9 +++++---- failures-to-investigate/freshsales3.py | 9 +++++---- icecream/__init__.py | 9 +++++---- icecream/builtins.py | 1 - icecream/coloring.py | 6 +++--- icecream/icecream.py | 14 +++++++------- setup.py | 7 ++++--- tests/test_icecream.py | 10 ++++++---- tests/test_install.py | 8 ++++---- 10 files changed, 44 insertions(+), 38 deletions(-) diff --git a/failures-to-investigate/freshsales.py b/failures-to-investigate/freshsales.py index b6a314a..a913e33 100644 --- a/failures-to-investigate/freshsales.py +++ b/failures-to-investigate/freshsales.py @@ -5,12 +5,14 @@ # # License _!_ -from os.path import abspath, dirname, join as pjoin import pprint import sys import time +from os.path import abspath, dirname +from os.path import join as pjoin import requests + from icecream import ic _corePath = abspath(pjoin(dirname(__file__), '../')) @@ -18,7 +20,6 @@ sys.path.append(_corePath) from common.utils import lget - DEFAULT_FIRST_NAME = 'there' DEFAULT_LAST_NAME = '-' FRESH_SALES_API_KEY = 'P3bYheaquAHH1_hNxhMUDQ' @@ -215,7 +216,7 @@ def createAndOrAssociateCompanyWithContact(websiteUrl, contact): 'id': companyToAdd['id'], # There can only be one primary Company associated with a # Contact. See https://www.freshsales.io/api/#create_contact. - 'is_primary': False if companies else True, + 'is_primary': not companies, } companies.append(companyData) @@ -242,7 +243,7 @@ def upgradeContactWhoSubmittedSplashPage(contact, websiteUrl): def noteContactSubmittedPepSplashPage(contact, websiteUrl): createAndOrAssociateCompanyWithContact(websiteUrl, contact) - + PEP = 9000004543 updateContact(contact['id'], { 'custom_field': { diff --git a/failures-to-investigate/freshsales2.py b/failures-to-investigate/freshsales2.py index 9fdbe01..fafb6ee 100644 --- a/failures-to-investigate/freshsales2.py +++ b/failures-to-investigate/freshsales2.py @@ -5,13 +5,15 @@ # # License _!_ -from os.path import abspath, dirname, join as pjoin import pprint import sys import time +from os.path import abspath, dirname +from os.path import join as pjoin from urllib.parse import urlparse import requests + from icecream import ic _corePath = abspath(pjoin(dirname(__file__), '../')) @@ -19,7 +21,6 @@ sys.path.append(_corePath) from common.utils import lget, stripStringStart - DEFAULT_FIRST_NAME = 'there' DEFAULT_LAST_NAME = '-' FRESH_SALES_API_KEY = 'P3bYheaquAHH1_hNxhMUDQ' @@ -228,7 +229,7 @@ def createAndOrAssociateCompanyWithContact(websiteUrl, contact): 'id': companyToAdd['id'], # There can only be one primary Company associated with a # Contact. See https://www.freshsales.io/api/#create_contact. - 'is_primary': False if companies else True, + 'is_primary': not companies, } companies.append(companyData) @@ -255,7 +256,7 @@ def upgradeContactWhoSubmittedSplashPage(contact, websiteUrl): def noteContactSubmittedPepSplashPage(contact, websiteUrl): createAndOrAssociateCompanyWithContact(websiteUrl, contact) - + PEP = 9000004543 updateContact(contact['id'], { 'custom_field': { diff --git a/failures-to-investigate/freshsales3.py b/failures-to-investigate/freshsales3.py index 209c3df..39c5a2f 100644 --- a/failures-to-investigate/freshsales3.py +++ b/failures-to-investigate/freshsales3.py @@ -5,13 +5,15 @@ # # License _!_ -from os.path import abspath, dirname, join as pjoin import pprint import sys import time +from os.path import abspath, dirname +from os.path import join as pjoin from urllib.parse import urlparse import requests + from icecream import ic _corePath = abspath(pjoin(dirname(__file__), '../')) @@ -19,7 +21,6 @@ sys.path.append(_corePath) from common.utils import lget, stripStringStart - DEFAULT_FIRST_NAME = 'there' DEFAULT_LAST_NAME = '-' FRESH_SALES_API_KEY = 'P3bYheaquAHH1_hNxhMUDQ' @@ -235,7 +236,7 @@ def createAndOrAssociateCompanyWithContact(websiteUrl, contact): 'id': companyToAdd['id'], # There can only be one primary Company associated with a # Contact. See https://www.freshsales.io/api/#create_contact. - 'is_primary': False if companies else True, + 'is_primary': not companies, } companies.append(companyData) @@ -262,7 +263,7 @@ def upgradeContactWhoSubmittedSplashPage(contact, websiteUrl): def noteContactSubmittedPepSplashPage(contact, websiteUrl): createAndOrAssociateCompanyWithContact(websiteUrl, contact) - + PEP = 9000004543 updateContact(contact['id'], { 'custom_field': { diff --git a/icecream/__init__.py b/icecream/__init__.py index 0a9393d..8198ae5 100644 --- a/icecream/__init__.py +++ b/icecream/__init__.py @@ -10,11 +10,12 @@ # License: MIT # -from os.path import dirname, join as pjoin - -from .icecream import * # noqa -from .builtins import install, uninstall +from os.path import dirname +from os.path import join as pjoin # Import all variables in __version__.py without explicit imports. from . import __version__ +from .builtins import install, uninstall +from .icecream import * # noqa + globals().update(dict((k, v) for k, v in __version__.__dict__.items())) diff --git a/icecream/builtins.py b/icecream/builtins.py index 67136e0..4596b9f 100644 --- a/icecream/builtins.py +++ b/icecream/builtins.py @@ -12,7 +12,6 @@ import icecream - try: builtins = __import__('__builtin__') except ImportError: diff --git a/icecream/coloring.py b/icecream/coloring.py index b577be3..801f89c 100644 --- a/icecream/coloring.py +++ b/icecream/coloring.py @@ -11,9 +11,9 @@ # from pygments.style import Style -from pygments.token import ( - Text, Name, Error, Other, String, Number, Keyword, Generic, Literal, - Comment, Operator, Whitespace, Punctuation) +from pygments.token import (Comment, Error, Generic, Keyword, Literal, Name, + Number, Operator, Other, Punctuation, String, Text, + Whitespace) # Solarized: https://ethanschoonover.com/solarized/ diff --git a/icecream/icecream.py b/icecream/icecream.py index 435518f..6c7ef28 100644 --- a/icecream/icecream.py +++ b/icecream/icecream.py @@ -14,13 +14,13 @@ from __future__ import print_function import ast +import functools import inspect import pprint import sys import warnings -from datetime import datetime -import functools from contextlib import contextmanager +from datetime import datetime from os.path import basename, realpath from textwrap import dedent @@ -31,12 +31,12 @@ # terminals and thus whether to use Terminal256Formatter or # TerminalTrueColorFormatter. from pygments.formatters import Terminal256Formatter -from pygments.lexers import PythonLexer as PyLexer, Python3Lexer as Py3Lexer +from pygments.lexers import Python3Lexer as Py3Lexer +from pygments.lexers import PythonLexer as PyLexer from .coloring import SolarizedDark - -PYTHON2 = (sys.version_info[0] == 2) +PYTHON2 = sys.version_info[0] == 2 _absent = object() _arg_source_missing = object() @@ -172,7 +172,7 @@ def unsupport_py2(*args, **kwargs): func = functools.singledispatch(func) # add unregister based on https://stackoverflow.com/a/25951784 - closure = dict(zip(func.register.__code__.co_freevars, + closure = dict(zip(func.register.__code__.co_freevars, func.register.__closure__)) registry = closure['registry'].cell_contents dispatch_cache = closure['dispatch_cache'].cell_contents @@ -366,7 +366,7 @@ def configureOutput(self, prefix=_absent, outputFunction=_absent, if includeContext is not _absent: self.includeContext = includeContext - + if contextAbsPath is not _absent: self.contextAbsPath = contextAbsPath diff --git a/setup.py b/setup.py index df3d31d..8ecbf87 100644 --- a/setup.py +++ b/setup.py @@ -13,10 +13,11 @@ import os import sys -from os.path import dirname, join as pjoin -from setuptools import setup, find_packages, Command -from setuptools.command.test import test as TestCommand +from os.path import dirname +from os.path import join as pjoin +from setuptools import Command, find_packages, setup +from setuptools.command.test import test as TestCommand meta = {} with open(pjoin('icecream', '__version__.py')) as f: diff --git a/tests/test_icecream.py b/tests/test_icecream.py index 40497ba..cbcb6c9 100644 --- a/tests/test_icecream.py +++ b/tests/test_icecream.py @@ -19,11 +19,13 @@ from StringIO import StringIO except ImportError: # Python 3.x. from io import StringIO + from contextlib import contextmanager -from os.path import basename, splitext, realpath +from os.path import basename, realpath, splitext import icecream -from icecream import ic, argumentToString, stderrPrint, NO_SOURCE_AVAILABLE_WARNING_MESSAGE +from icecream import (NO_SOURCE_AVAILABLE_WARNING_MESSAGE, argumentToString, + ic, stderrPrint) TEST_PAIR_DELIMITER = '| ' MY_FILENAME = basename(__file__) @@ -505,7 +507,7 @@ def testContextAbsPathMultiLine(self): pair = parseOutputIntoPairs(out, err, 3)[1][0] assert pair == ('multilineStr', ic.argToStringFunction(multilineStr)) - + def testFormat(self): with disableColoring(), captureStandardStreams() as (out, err): """comment"""; noop(); ic( # noqa @@ -595,7 +597,7 @@ def testMultilineContainerArgs(self): list(range(15))]) lines = err.getvalue().strip().splitlines() - self.assertRegexpMatches( + self.assertRegex( lines[0], r'ic\| test_icecream.py:\d+ in testMultilineContainerArgs\(\)', ) diff --git a/tests/test_install.py b/tests/test_install.py index 61f9a79..39759d4 100644 --- a/tests/test_install.py +++ b/tests/test_install.py @@ -12,11 +12,11 @@ import unittest -import icecream -from test_icecream import ( - disableColoring, captureStandardStreams, parseOutputIntoPairs) - from install_test_import import runMe +from test_icecream import (captureStandardStreams, disableColoring, + parseOutputIntoPairs) + +import icecream class TestIceCreamInstall(unittest.TestCase):