Skip to content

Annotating custom constructor methods for generic types. #2025

Answered by erictraut
randolf-scholz asked this question in Q&A
Discussion options

You must be logged in to vote

Any idea why it fails to bind V=int (or possibly V=Literal[3])?

Yes, Foo.new binds Foo[Any, Any] to the new method. The types of class-scoped type variables are inferred from argument types only when you call a constructor. This doesn't work for other methods. In other cases, the specialization comes from the bound class — in this case, Foo or Foo[Any, Any] since you haven't specified any default values for the type variables.

Replies: 1 comment 6 replies

Comment options

You must be logged in to vote
6 replies
@randolf-scholz
Comment options

@erictraut
Comment options

Answer selected by randolf-scholz
@randolf-scholz
Comment options

@randolf-scholz
Comment options

@randolf-scholz
Comment options

@bzoracler
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy