Skip to content

BUG: delay calls of array repr in getlimits #9113

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 15, 2017

Conversation

matthew-brett
Copy link
Contributor

Delay use of array repr until needed for string representations of the
float info parameters. This is to allow getlimits to be imported early
without pulling in too much of the repr machinery.

See: #8983 (comment)

@ahaldane
Copy link
Member

Yep, this fixes the circular import problem from #8983.

I was just reading this code myself to see how to fix it. My thought was to delay creation of _KNOWN_TYPES by defining

_KNOWN_TYPES = None
def _get_known_types():
    global _KNOWN_TYPES

    if _KNOWN_TYPES is not None:
        return _KNOWN_TYPES

    ... (indented definition of _KNOWN_TYPES goes here ...

but I haven't properly thought through all the performance implications that you probably know about.

This PR looks good to me, let's just wait for tests to pass.

@ahaldane
Copy link
Member

The __main__ clause doesn't seem to work:

python2 ./getlimits.py 
Traceback (most recent call last):
  File "./getlimits.py", line 10, in <module>
    from .machar import MachAr
ValueError: Attempted relative import in non-package

(the other files in this directory which have such a clause work properly).

@charris charris added this to the 1.13.0 release milestone May 13, 2017
@charris
Copy link
Member

charris commented May 15, 2017

The main clause doesn't seem to work:

Should be removed. Scripts cannot use absolute_imports as they do not run in the right context. That clause dates back to 2006 and was probably used for debugging.

Delay use of array repr until needed for string representations of the
float info parameters.  This is to allow getlimits to be imported early
without pulling in too much of the repr machinery.

See: numpy#8983 (comment)
Does not work, and shouldn't be there.
@matthew-brett matthew-brett changed the title WIP: delay calls of array repr in getlimits MRG: delay calls of array repr in getlimits May 15, 2017
@charris charris changed the title MRG: delay calls of array repr in getlimits BUG: delay calls of array repr in getlimits May 15, 2017
@charris charris merged commit bfac9bb into numpy:master May 15, 2017
@charris
Copy link
Member

charris commented May 15, 2017

Thanks Matthew. I expect we can do more in this regard, but this is a good start and fixes the immediate problem.

@ahaldane
Copy link
Member

Thanks for moving this one forward @charris, and thanks for the fix @matthew-brett

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants