Skip to content

Wrapper/Proxy Generic Type #802

Open
@hatal175

Description

@hatal175

I've been putting some work into typeshed pull requests and I've noticed some places where I could really have used a Proxy Generic class - meaning I can inherit from Proxy[T] and that means that whatever attributes T has, Proxy[T] also has. We don't want to directly mark this as inheritance since then the distinction of a proxy is lost.

The examples I ran into are ProxyType and CallableProxyType in weakref or SynchronizedBase in multiprocessing,csharedtypes.
A big one would be unittest.Mock (See python/mypy#1188).
I'm sure other cases exist,

Advantages:

  • Representing a proxy type easily
  • Allowing type checkers to enforce typing

Disadvantages:

  • Functions that get T won't accept Proxy[T] as an argument. Although the current state is probably something similar.

I'd really like to hear some opinions on the idea.

Metadata

Metadata

Assignees

No one assigned

    Labels

    topic: featureDiscussions about new features for Python's type annotations

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions