Skip to content

tuple does not define __new__ #2091

Closed
Closed

Description

@ltworf

Reporting python/mypy#4991 here.

This code to make a subclass of tuple does not pass the test.

class A(tuple):
    def __new__(cls, fields):
        return super(A, cls).__new__(cls, tuple(fields))

With those settings:

python_version=3.5
warn_unused_ignores=True
warn_redundant_casts=True
strict_optional=True
scripts_are_modules=True
check_untyped_defs=True

Using mypy 0.590

And it results in

/tmp/test.py:3: error: Too many arguments for "__new__" of "object"

Activity

  1. ltworf commented on May 3, 2018

    @ltworf
    ContributorAuthor

    It can be called with

    tuple.__new__(tuple,[1,2,3])
    tuple.__new__(tuple)
    

    So I think the type should be:

        def __new__(cls: Type[_T], iterable: Iterable[Any]=tuple()) -> _T: ...
    
  2. ltworf commented on May 3, 2018

    @ltworf
    ContributorAuthor

    Seems I did some mistake

    ./stdlib/3/builtins.pyi:585:56: Y011 Default values for typed arguments must be "..."
    ./stdlib/3/builtins.pyi:585:56: B008 Do not perform calls in argument defaults. The call is performed only once at function definition time. All calls to your function will reuse the result of that definition-time call. If this is intended, assign the function call to a module-level variable and use that variable as a default value.

    The calls in default is fine, since tuple() is not mutable though.

  3. added a commit that references this issue on May 9, 2018
    d289c20
  4. added a commit that references this issue on May 29, 2018
    3456ab2
  5. added a commit that references this issue on Jul 3, 2018
  6. added 2 commits that reference this issue on Jan 23, 2019
    4a5c664
    f96121d
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

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions