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

Empty typing.NamedTuple creation is not tested #89443

Closed
sobolevn opened this issue Sep 24, 2021 · 5 comments
Closed

Empty typing.NamedTuple creation is not tested #89443

sobolevn opened this issue Sep 24, 2021 · 5 comments
Labels
3.9 only security fixes 3.10 only security fixes 3.11 only security fixes tests Tests in the Lib/test dir type-bug An unexpected behavior, bug, or error

Comments

@sobolevn
Copy link
Member

BPO 45280
Nosy @ambv, @miss-islington, @sobolevn
PRs
  • bpo-45280: Add test for empty NamedTuple in test_typing #28559
  • [3.9] bpo-45280: Add test for empty NamedTuple in test_typing (GH-28559) #28570
  • [3.10] bpo-45280: Add test for empty NamedTuple in test_typing (GH-28559) #28571
  • 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-09-26.17:10:10.836>
    created_at = <Date 2021-09-24.11:23:41.528>
    labels = ['type-bug', 'tests', '3.9', '3.10', '3.11']
    title = 'Empty typing.NamedTuple creation is not tested'
    updated_at = <Date 2021-09-26.17:10:10.835>
    user = 'https://github.com/sobolevn'

    bugs.python.org fields:

    activity = <Date 2021-09-26.17:10:10.835>
    actor = 'lukasz.langa'
    assignee = 'none'
    closed = True
    closed_date = <Date 2021-09-26.17:10:10.836>
    closer = 'lukasz.langa'
    components = ['Tests']
    creation = <Date 2021-09-24.11:23:41.528>
    creator = 'sobolevn'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 45280
    keywords = ['patch']
    message_count = 5.0
    messages = ['402557', '402669', '402672', '402673', '402674']
    nosy_count = 3.0
    nosy_names = ['lukasz.langa', 'miss-islington', 'sobolevn']
    pr_nums = ['28559', '28570', '28571']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue45280'
    versions = ['Python 3.9', 'Python 3.10', 'Python 3.11']

    @sobolevn
    Copy link
    Member Author

    While working on mypy support of NamedTuples (python/mypy#11047), I've noticed that currently when testing typing.NamedTuple cases like:

    1. N = NamedTuple('N')

    and

    class N(NamedTuple):
        ...

    are ignored.

    However, this is an important corner-cases, we need to be sure that use can create empty named tuples if needed.

    Related position in code:

    def test_namedtuple_errors(self):
    with self.assertRaises(TypeError):
    NamedTuple.__new__()
    with self.assertRaises(TypeError):
    NamedTuple()
    with self.assertRaises(TypeError):
    NamedTuple('Emp', [('name', str)], None)
    with self.assertRaises(ValueError):
    NamedTuple('Emp', [('_name', str)])
    with self.assertRaises(TypeError):
    NamedTuple(typename='Emp', name=str, id=int)
    with self.assertRaises(TypeError):
    NamedTuple('Emp', fields=[('name', str), ('id', int)])

    I will send a PR add these two cases.

    @sobolevn sobolevn added 3.9 only security fixes 3.10 only security fixes 3.11 only security fixes tests Tests in the Lib/test dir type-bug An unexpected behavior, bug, or error labels Sep 24, 2021
    @ambv
    Copy link
    Contributor

    ambv commented Sep 26, 2021

    New changeset f56268a by Nikita Sobolev in branch 'main':
    bpo-45280: Add test for empty NamedTuple in test_typing (GH-28559)
    f56268a

    @ambv
    Copy link
    Contributor

    ambv commented Sep 26, 2021

    New changeset 08e387a by Miss Islington (bot) in branch '3.9':
    bpo-45280: Add test for empty NamedTuple in test_typing (GH-28559) (GH-28570)
    08e387a

    @ambv
    Copy link
    Contributor

    ambv commented Sep 26, 2021

    New changeset d452b29 by Miss Islington (bot) in branch '3.10':
    bpo-45280: Add test for empty NamedTuple in test_typing (GH-28559) (GH-28571)
    d452b29

    @ambv
    Copy link
    Contributor

    ambv commented Sep 26, 2021

    Thanks, Nikita! ✨ 🍰 ✨

    @ambv ambv closed this as completed Sep 26, 2021
    @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 3.10 only security fixes 3.11 only security fixes tests Tests in the Lib/test dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants