Skip to content

Classes should not inherit from Any #1446

Closed

Description

@emmatyping

Several classes in typeshed inherit from Any, and should not.

$ ag "class .*\(Any\)"
stdlib\3\multiprocessing\context.pyi
118:    class ForkProcess(Any):  # type: ignore
124:    class SpawnProcess(Any):  # type: ignore
130:    class ForkServerProcess(Any):  # type: ignore
148:    class SpawnProcess(Any):  # type: ignore

stdlib\3\types.pyi
81:class SimpleNamespace(Any): ...  # type: ignore

stdlib\3\unittest\mock.pyi
34:    class NonCallableMock(Any):

tests\pytype_blacklist.txt
11:# Because of 'class ForkProcess(Any):  # type: ignore'

third_party\3\jwt\algorithms.pyi
3:class Algorithm(Any): ...  # type: ignore

As can be seen, all but one of these are type-ignore'd and thus not picked up by mypy.

The multiprocessing classes have # TODO: type should be BaseProcess once a stub in multiprocessing.process exists, so that should be okay to change, as that module is there.

The types.pyi SimpleNameSpace needed my __setattr__ implementation.

Apparently the same for NonCallableMock

JWT stubs just seem very incomplete.

Activity

  1. JelleZijlstra commented on Jul 4, 2017

    @JelleZijlstra
    Member

    Feel free to send some PRs. :)

  2. srittau commented on Sep 11, 2018

    @srittau
    Collaborator

    Updated list:

    stdlib/3/multiprocessing/context.pyi
    134:    class ForkProcess(Any):  # type: ignore
    140:    class SpawnProcess(Any):  # type: ignore
    146:    class ForkServerProcess(Any):  # type: ignore
    164:    class SpawnProcess(Any):  # type: ignore
    
    third_party/3/jwt/algorithms.pyi
    3:class Algorithm(Any): ...  # type: ignore
    
    third_party/2and3/google/protobuf/internal/containers.pyi
    51:class Mapping(Any): ...
    

    Some are fixed, the protobuf one is new, but is marked explicitly as "not yet typed".

  3. added a commit that references this issue on Oct 21, 2018
  4. added a commit that references this issue on Oct 23, 2018
  5. hauntsaninja commented on Jan 8, 2020

    @hauntsaninja
    Collaborator

    Looks like it's only the protobuf containers one left. Is it worth adding a test to prevent the addition of Any others?

  6. srittau commented on Jan 8, 2020

    @srittau
    Collaborator

    I think adding a test to flake8-pyi would make sense.

  7. JelleZijlstra commented on Jan 8, 2020

    @JelleZijlstra
    Member

    It would be better to turn on mypy's --disallow-subclassing-any flag (maybe with a type ignore for the protobuf ones).

  8. srittau commented on Jan 8, 2020

    @srittau
    Collaborator

    Good point.

  9. added a commit that references this issue on Jan 8, 2020
    19da5ff
  10. added a commit that references this issue on Jan 8, 2020
    fdeae5d
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

    stubs: improvementImprove/refactor existing annotations, other stubs issues

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions