Skip to content

2to3 fix_exitfunc suggests duplicated import of atexit module #83864

Closed

Description

@ilya-palachev
BPO 39683
Nosy @phsilva, @ilya-palachev
PRs
  • bpo-39683: 2to3 fix_exitfunc suggests duplicated import of atexit module #18654
  • Superseder
  • bpo-45544: Close 2to3 issues and list them here
  • 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 = <Date 2021-10-20.22:55:43.676>
    created_at = <Date 2020-02-19.02:18:46.103>
    labels = ['type-bug', 'expert-2to3']
    title = '2to3 fix_exitfunc suggests duplicated import of atexit module'
    updated_at = <Date 2021-10-20.22:55:43.676>
    user = 'https://github.com/ilya-palachev'

    bugs.python.org fields:

    activity = <Date 2021-10-20.22:55:43.676>
    actor = 'iritkatriel'
    assignee = 'none'
    closed = True
    closed_date = <Date 2021-10-20.22:55:43.676>
    closer = 'iritkatriel'
    components = ['2to3 (2.x to 3.x conversion tool)']
    creation = <Date 2020-02-19.02:18:46.103>
    creator = 'ilya'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 39683
    keywords = ['patch']
    message_count = 1.0
    messages = ['362245']
    nosy_count = 2.0
    nosy_names = ['phsilva', 'ilya']
    pr_nums = ['18654']
    priority = 'normal'
    resolution = 'wont fix'
    stage = 'resolved'
    status = 'closed'
    superseder = '45544'
    type = 'behavior'
    url = 'https://bugs.python.org/issue39683'
    versions = []

    Activity

    1. ilya-palachev commented on Feb 19, 2020

      ilya-palachevmannequin
      MannequinAuthor

      Consider the following code:

      import sys
      
      def foo():
          print(1)
      
      def bar():
          print(2)
      
      if input("case: ") == 1:
          sys.exitfunc = foo
      else:
          sys.exitfunc = bar

      2to3 -f exitfunc suggests to fix it as follows:

      --- a.py	(original)
      +++ a.py	(refactored)
      @@ -1,4 +1,6 @@
       import sys
      +import atexit
      +import atexit
       
       def foo():
           print(1)
      @@ -7,6 +9,6 @@
           print(2)
       
       if input("case: ") == 1:
      -    sys.exitfunc = foo
      +    atexit.register(foo)
       else:
      -    sys.exitfunc = bar
      +    atexit.register(bar)

      So it seems that it produces one import of atexit module per each use of sys.exitfunc.

    2. transferred this issue fromon Apr 10, 2022
    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

      topic-2to3type-bugAn unexpected behavior, bug, or error

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions