Skip to content

Commit fa60c30

Browse files
committed
MNT: import time: avoid textwrap in core library
1 parent ea965e4 commit fa60c30

File tree

2 files changed

+33
-35
lines changed

2 files changed

+33
-35
lines changed

numpy/core/overrides.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import collections
33
import functools
44
import os
5-
import textwrap
65

76
from numpy.core._multiarray_umath import (
87
add_docstring, implement_array_function, _get_implementing_args)
@@ -163,13 +162,13 @@ def decorator(implementation):
163162
# more interpettable name. Otherwise, the original function does not
164163
# show up at all in many cases, e.g., if it's written in C or if the
165164
# dispatcher gets an invalid keyword argument.
166-
source = textwrap.dedent("""
167-
@functools.wraps(implementation)
168-
def {name}(*args, **kwargs):
169-
relevant_args = dispatcher(*args, **kwargs)
170-
return implement_array_function(
171-
implementation, {name}, relevant_args, args, kwargs)
172-
""").format(name=implementation.__name__)
165+
source = """
166+
@functools.wraps(implementation)
167+
def {name}(*args, **kwargs):
168+
relevant_args = dispatcher(*args, **kwargs)
169+
return implement_array_function(
170+
implementation, {name}, relevant_args, args, kwargs)
171+
""".format(name=implementation.__name__)
173172

174173
source_object = compile(
175174
source, filename='<__array_function__ internals>', mode='exec')

numpy/ma/core.py

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import sys
2626
import operator
2727
import warnings
28-
import textwrap
2928
import re
3029
from functools import reduce
3130

@@ -2445,32 +2444,32 @@ def _recursive_printoption(result, mask, printopt):
24452444

24462445
# For better or worse, these end in a newline
24472446
_legacy_print_templates = dict(
2448-
long_std=textwrap.dedent("""\
2449-
masked_%(name)s(data =
2450-
%(data)s,
2451-
%(nlen)s mask =
2452-
%(mask)s,
2453-
%(nlen)s fill_value = %(fill)s)
2454-
"""),
2455-
long_flx=textwrap.dedent("""\
2456-
masked_%(name)s(data =
2457-
%(data)s,
2458-
%(nlen)s mask =
2459-
%(mask)s,
2460-
%(nlen)s fill_value = %(fill)s,
2461-
%(nlen)s dtype = %(dtype)s)
2462-
"""),
2463-
short_std=textwrap.dedent("""\
2464-
masked_%(name)s(data = %(data)s,
2465-
%(nlen)s mask = %(mask)s,
2466-
%(nlen)s fill_value = %(fill)s)
2467-
"""),
2468-
short_flx=textwrap.dedent("""\
2469-
masked_%(name)s(data = %(data)s,
2470-
%(nlen)s mask = %(mask)s,
2471-
%(nlen)s fill_value = %(fill)s,
2472-
%(nlen)s dtype = %(dtype)s)
2473-
""")
2447+
long_std="""\
2448+
masked_%(name)s(data =
2449+
%(data)s,
2450+
%(nlen)s mask =
2451+
%(mask)s,
2452+
%(nlen)s fill_value = %(fill)s)
2453+
""",
2454+
long_flx="""\
2455+
masked_%(name)s(data =
2456+
%(data)s,
2457+
%(nlen)s mask =
2458+
%(mask)s,
2459+
%(nlen)s fill_value = %(fill)s,
2460+
%(nlen)s dtype = %(dtype)s)
2461+
""",
2462+
short_std="""\
2463+
masked_%(name)s(data = %(data)s,
2464+
%(nlen)s mask = %(mask)s,
2465+
%(nlen)s fill_value = %(fill)s)
2466+
""",
2467+
short_flx="""\
2468+
masked_%(name)s(data = %(data)s,
2469+
%(nlen)s mask = %(mask)s,
2470+
%(nlen)s fill_value = %(fill)s,
2471+
%(nlen)s dtype = %(dtype)s)
2472+
"""
24742473
)
24752474

24762475
###############################################################################

0 commit comments

Comments
 (0)