Skip to content
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

Use a dict to de-duplicate filenames, and thus reduce the size of the to_dict() #38

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ShaheedHaque
Copy link

Here is the patch I had in mind for #37. I've left the doctest's failing like this so you can see what the functional change is (and also because I'm not yet familiar enough with doctest :-)):

367     >>> import json
368     >>> from pprint import pprint
369     >>> try:
Differences (unified diff with -expected +actual):
    @@ -1,17 +1,19 @@
    -{'tb_frame': {'f_code': {'co_filename': '<doctest README.rst[...]>',
    -                         'co_name': '<module>'},
    +{'tb_frame': {'f_code': {'co_filename': 3, 'co_name': '<module>'},
                   'f_globals': {'__name__': '__main__'}},
      'tb_lineno': 2,
    - 'tb_next': {'tb_frame': {'f_code': {'co_filename': ...
    -                                     'co_name': 'inner_2'},
    + 'tb_next': {'tb_frame': {'f_code': {'co_filename': 2, 'co_name': 'inner_2'},
                               'f_globals': {'__name__': '__main__'}},
                  'tb_lineno': 2,
    -             'tb_next': {'tb_frame': {'f_code': {'co_filename': ...
    +             'tb_next': {'tb_frame': {'f_code': {'co_filename': 1,
                                                      'co_name': 'inner_1'},
                                           'f_globals': {'__name__': '__main__'}},
                              'tb_lineno': 2,
    -                         'tb_next': {'tb_frame': {'f_code': {'co_filename': ...
    +                         'tb_next': {'tb_frame': {'f_code': {'co_filename': 0,
                                                                  'co_name': 'inner_0'},
                                                       'f_globals': {'__name__': '__main__'}},
                                          'tb_lineno': 2,
    -                                     'tb_next': None}}}}
    +                                     'tb_next': None}}},
    + 'zip': {'<doctest README.rst[3]>': 0,
    +         '<doctest README.rst[40]>': 3,
    +         '<doctest README.rst[4]>': 1,
    +         '<doctest README.rst[5]>': 2}}

The basic change is that the co_filename, which often contains non-trivial filenames and duplicates too, stores an integer instead, and an extra "zip" dict at the top level provides the de-dupe service.

One other thing: for reasons I don't quite understand, on my dev system, though not in these tests, the f_globals dict also has a __file__ which I also took care of via "zip"...I don't understand why that field is not present here. It also stores the filename, and is a major cause of duplicates for my setup. (Yes, I'm baffled by this).

@luckydonald
Copy link

I feel like the zip dict should be reversed to make lookup easier. {3: "<doctest README.rst[40]>"}.

Also the zip thing isn't very expected.

Maybe we can borrow syntax from other such config systems, to stay familiar?
I'm thinking about the object refs in openapi, or the yaml references.

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

Successfully merging this pull request may close these issues.

2 participants