Skip to content

command line interface of symtable module is broken #85098

Description

@isidentical
BPO 40926
Nosy @benjaminp, @pablogsal, @isidentical
PRs
  • bpo-40926: Improve & fix command line usage of symtable #20757
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = None
    created_at = <Date 2020-06-09.10:20:39.563>
    labels = ['type-bug', 'library', '3.10']
    title = 'command line interface of symtable module is broken'
    updated_at = <Date 2020-06-09.10:40:22.701>
    user = 'https://github.com/isidentical'

    bugs.python.org fields:

    activity = <Date 2020-06-09.10:40:22.701>
    actor = 'BTaskaya'
    assignee = 'none'
    closed = False
    closed_date = None
    closer = None
    components = ['Library (Lib)']
    creation = <Date 2020-06-09.10:20:39.563>
    creator = 'BTaskaya'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 40926
    keywords = ['patch']
    message_count = 1.0
    messages = ['371088']
    nosy_count = 3.0
    nosy_names = ['benjamin.peterson', 'pablogsal', 'BTaskaya']
    pr_nums = ['20757']
    priority = 'normal'
    resolution = None
    stage = 'patch review'
    status = 'open'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue40926'
    versions = ['Python 3.10']

    Linked PRs

    Activity

    1. isidentical commented on Jun 9, 2020

      @isidentical
      SponsorMemberAuthor

      (.venv) (Python 3.10.0a0) [ 1:11ÖS ] [ isidentical@x200:~ ]
      $ cat t.py
      import x
      a = 1
      print(x)

      (.venv) (Python 3.10.0a0) [ 1:11ÖS ] [ isidentical@x200:~ ]
      $ python -m symtable t.py
      <symbol '_symtable'> True False
      <symbol 'USE'> True False
      <symbol 'DEF_GLOBAL'> True False
      <symbol 'DEF_NONLOCAL'> True False
      <symbol 'DEF_LOCAL'> True False
      ...

      It can clearly seen that the initial argument [t.py] is completely ignored, and this script prints out the symtable.py itself. This is because the script uses argv[0] (itself) instead of argv[1] (the first argument). I also find this output quite poor since we don't know what these boolean values are;

      <symbol 'DEF_LOCAL'> True False

      The fix I had in my mind is printing all properties instead of 2 boolean values

       $ ./cpython/cpython/python -m symtable t.py
      <symbol 'x'> ==> {'local', 'imported', 'referenced'}
      <symbol 'a'> ==> {'local', 'assigned'}
      <symbol 'print'> ==> {'referenced', 'global'}
    2. added
      stdlibStandard Library Python modules in the Lib/ directory
      type-bugAn unexpected behavior, bug, or error
      on Jun 9, 2020
    3. transferred this issue fromon Apr 10, 2022
    4. serhiy-storchaka commented on Sep 7, 2023

      @serhiy-storchaka
      Member

      I also worked on improving the CLI of symtable. I do not remember why I did not finish the work and did not touch the code for 3.5 years. In any case I show it in #109112.

    5. serhiy-storchaka commented on Sep 7, 2023

      @serhiy-storchaka
      Member

      Example of the output:

      $ ./python -m symtable Lib/symtable.py 
      local symbol '_symtable': def_import
      local symbol 'USE': use, def_import
      local symbol 'DEF_GLOBAL': def_import
      local symbol 'DEF_NONLOCAL': def_import
      local symbol 'DEF_LOCAL': def_import
      local symbol 'DEF_PARAM': def_import
      local symbol 'DEF_IMPORT': def_import
      local symbol 'DEF_BOUND': def_import
      local symbol 'DEF_ANNOT': def_import
      local symbol 'SCOPE_OFF': def_import
      local symbol 'SCOPE_MASK': def_import
      local symbol 'FREE': def_import
      local symbol 'LOCAL': def_import
      local symbol 'GLOBAL_IMPLICIT': def_import
      local symbol 'GLOBAL_EXPLICIT': def_import
      local symbol 'CELL': def_import
      local symbol 'weakref': def_import
      local symbol '__all__': def_local
      local symbol 'symtable': use, def_local
          local symbol 'code': use, def_param
          local symbol 'filename': use, def_param
          local symbol 'compile_type': use, def_param
          local symbol 'top': use, def_local
          global_implicit symbol '_symtable': use
          global_implicit symbol '_newSymbolTable': use
      
      local symbol 'SymbolTableFactory': use, def_local
          local symbol '__init__': def_local
              local symbol 'self': use, def_param
              global_implicit symbol 'weakref': use
      
          local symbol 'new': def_local
              local symbol 'self': def_param
              local symbol 'table': use, def_param
              local symbol 'filename': use, def_param
              global_implicit symbol '_symtable': use
              global_implicit symbol 'Function': use
              global_implicit symbol 'Class': use
              global_implicit symbol 'SymbolTable': use
      
          local symbol '__call__': def_local
              local symbol 'self': use, def_param
              local symbol 'table': use, def_param
              local symbol 'filename': use, def_param
              local symbol 'key': use, def_local
              local symbol 'obj': use, def_local
      
      ...
      

      It outputs the scope separately from flags. It prints not only top-level symbols, but also symbols in nested namespaces.

      It also changes the repr of Symbol.

    6. serhiy-storchaka commented on Sep 8, 2023

      @serhiy-storchaka
      Member

      After some thought I changed the output formatЖ

      $ ./python -m symtable Lib/symtable.py
      symbol table for module from file 'Lib/symtable.py':
          local symbol '_symtable': def_import
          local symbol 'USE': use, def_import
          local symbol 'DEF_GLOBAL': def_import
          local symbol 'DEF_NONLOCAL': def_import
          local symbol 'DEF_LOCAL': def_import
          local symbol 'DEF_PARAM': def_import
          local symbol 'DEF_IMPORT': def_import
          local symbol 'DEF_BOUND': def_import
          local symbol 'DEF_ANNOT': def_import
          local symbol 'SCOPE_OFF': def_import
          local symbol 'SCOPE_MASK': def_import
          local symbol 'FREE': def_import
          local symbol 'LOCAL': def_import
          local symbol 'GLOBAL_IMPLICIT': def_import
          local symbol 'GLOBAL_EXPLICIT': def_import
          local symbol 'CELL': def_import
          local symbol 'weakref': def_import
          local symbol '__all__': def_local
          local symbol 'symtable': def_local
          local symbol 'SymbolTableFactory': use, def_local
          local symbol '_newSymbolTable': def_local
      ...
          local symbol 'sys': use, def_import
          local symbol 'n': use, def_local
      
          symbol table for function 'symtable':
              local symbol 'code': use, def_param
              local symbol 'filename': use, def_param
              local symbol 'compile_type': use, def_param
              local symbol 'top': use, def_local
              global_implicit symbol '_symtable': use
              global_implicit symbol '_newSymbolTable': use
      
          symbol table for class 'SymbolTableFactory':
              local symbol '__init__': def_local
              local symbol 'new': def_local
              local symbol '__call__': def_local
      
              symbol table for function '__init__':
                  local symbol 'self': use, def_param
                  global_implicit symbol 'weakref': use
      
      ...
      

      Now nested symbol tables are output after symbols and include header with some table related information. It also helps when specify several input files.

    7. added a commit that references this issue on Nov 7, 2023
    8. added a commit that references this issue on Nov 8, 2023
    9. added a commit that references this issue on Feb 11, 2024
    10. added a commit that references this issue on Sep 2, 2024
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      3.10 (EOL)end of lifestdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions