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

[easy] undefined name in Lib/test/mock_socket.py #84642

Closed
vstinner opened this issue Apr 30, 2020 · 11 comments
Closed

[easy] undefined name in Lib/test/mock_socket.py #84642

vstinner opened this issue Apr 30, 2020 · 11 comments
Labels
3.9 only security fixes easy tests Tests in the Lib/test dir

Comments

@vstinner
Copy link
Member

BPO 40462
Nosy @vstinner, @corona10, @miss-islington, @furkanonder
PRs
  • bpo-40462: fix variable and function names #19832
  • bpo-40462: Fix typo in test_json #20094
  • 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 2020-05-14.23:02:41.255>
    created_at = <Date 2020-04-30.23:50:30.182>
    labels = ['easy', 'tests', '3.9']
    title = '[easy] undefined name in Lib/test/mock_socket.py'
    updated_at = <Date 2020-05-14.23:29:08.116>
    user = 'https://github.com/vstinner'

    bugs.python.org fields:

    activity = <Date 2020-05-14.23:29:08.116>
    actor = 'furkanonder'
    assignee = 'none'
    closed = True
    closed_date = <Date 2020-05-14.23:02:41.255>
    closer = 'vstinner'
    components = ['Tests']
    creation = <Date 2020-04-30.23:50:30.182>
    creator = 'vstinner'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 40462
    keywords = ['patch', 'newcomer friendly']
    message_count = 11.0
    messages = ['367812', '367813', '367814', '367816', '367829', '367841', '367842', '368157', '368874', '368875', '368879']
    nosy_count = 4.0
    nosy_names = ['vstinner', 'corona10', 'miss-islington', 'furkanonder']
    pr_nums = ['19832', '20094']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue40462'
    versions = ['Python 3.9']

    @vstinner
    Copy link
    Member Author

    pyflakes found the following issues in sendall():

    Lib/test/mock_socket.py:95:21 undefined name 'data'
    Lib/test/mock_socket.py:96:28 undefined name 'data'
    Lib/test/mock_socket.py:97:20 undefined name 'data'

    Code:

        def sendall(self, buffer, flags=None):
            self.last = data
            self.output.append(data)
            return len(data)
    
        def send(self, data, flags=None):
            self.last = data
            self.output.append(data)
            return len(data)

    I guess that sendall() buffer parameter should be renamed to data.

    @vstinner vstinner added 3.9 only security fixes tests Tests in the Lib/test dir easy labels Apr 30, 2020
    @vstinner
    Copy link
    Member Author

    Another one:

    Lib/test/test_frame.py:53:17 undefined name 'inner'

    I guess that self.inner() should be used instead of inner(). In practice, it's dead code, but fixing it would make pyflakes happier :-)

    @vstinner
    Copy link
    Member Author

    Another one:

    Lib/test/test_json/test_recursion.py:55:24 undefined name 'pyjson'

    Code:

        def test_defaultrecursion(self):
            class RecursiveJSONEncoder(self.json.JSONEncoder):
                recurse = False
                def default(self, o):
                    if o is JSONTestObject:
                        if self.recurse:
                            return [JSONTestObject]
                        else:
                            return 'JSONTestObject'
                    return pyjson.JSONEncoder.default(o)

    Here I'm not sure. *Maybe* pyjson.JSONEncoder should be replaced with self.json.JSONEncoder?

    @vstinner
    Copy link
    Member Author

    vstinner commented May 1, 2020

    Another one:

    Lib/unittest/test/test_program.py:191:40 undefined name 'hasInstallHandler'

    Code:

        def testBufferCatchFailfast(self):
            program = self.program
            for arg, attr in (('buffer', 'buffer'), ('failfast', 'failfast'),
                          ('catch', 'catchbreak')):
                if attr == 'catch' and not hasInstallHandler:
                    continue
                ...

    attr is never equal to 'catch' and so it's just dead code which can be removed.

    @furkanonder
    Copy link
    Mannequin

    furkanonder mannequin commented May 1, 2020

    Hello,
    I sent a PR that corrects variable and function names.
    I'm not sure how to fix it for Lib/test/test_json/test_recursion.py:55:24 so I didn't make any changes.

    @miss-islington
    Copy link
    Contributor

    New changeset 719e14d by Furkan Önder in branch 'master':
    bpo-40462: fix variable and function names (GH-19832)
    719e14d

    @corona10
    Copy link
    Member

    corona10 commented May 1, 2020

    @vstinner
    IMHO we should create backport patch for 3.8 and 3.7
    3.8 and 3.7 has same codes for this.

    https://github.com/python/cpython/blob/3.8/Lib/test/mock_socket.py#L95

    @vstinner
    Copy link
    Member Author

    vstinner commented May 5, 2020

    IMHO we should create backport patch for 3.8 and 3.7

    It's deadcode, I don't think that it's worth it. But it's up to you. If you consider that it's worth it, go ahead and backport the fix.

    @vstinner
    Copy link
    Member Author

    New changeset 4b972fa by Victor Stinner in branch 'master':
    bpo-40462: Fix typo in test_json (GH-20094)
    4b972fa

    @vstinner
    Copy link
    Member Author

    Thanks for the fix Furkan Önder!

    @furkanonder
    Copy link
    Mannequin

    furkanonder mannequin commented May 14, 2020

    You are welcome :=)

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.9 only security fixes easy tests Tests in the Lib/test dir
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants