This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Type variable substitution in type instances
Type: behavior Stage: resolved
Components: Interpreter Core Versions: Python 3.5
process
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: Nosy List: BTaskaya, gvanrossum, skrah
Priority: normal Keywords:

Created on 2015-09-13 13:52 by skrah, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (4)
msg250565 - (view) Author: Stefan Krah (skrah) * (Python committer) Date: 2015-09-13 13:52
If a type scheme is instantiated, should the type variables in the
class body be substituted?  This is an example (typed by hand on
a locked down Windows machine, may contain errors):


alpha = TypeVar('alpha')
beta = TypeVar('beta')

class ABTuple(Generic[alpha, beta]):
    def __init__(self, a : alpha, b : beta):
        self.value = (a, b)

get_type_hints(ABTuple.__init__)
 ==> {'b': ~beta, 'a': ~alpha}


IntIntTuple = ABTuple[int, int]

IntIntTuple
 ==> __main__.ABTuple[int, int]

get_type_hints(IntIntTuple.__init__)
{'b': ~beta, 'a': ~alpha}
      ^^^^^^      ^^^^^^


Since the type has been specialized, these should ideally be 'int'.
msg250580 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2015-09-13 17:40
Good question. Let's discuss this in the type hinting / pep 484 tracker:

https://github.com/ambv/typehinting/issues/156
msg358957 - (view) Author: Batuhan Taskaya (BTaskaya) * (Python committer) Date: 2019-12-28 19:05
It looks like the issue in typing tracker closed, can we also close this?
msg358979 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2019-12-29 05:16
Yup, see comment in https://github.com/python/typing/pull/308 regarding #156.
History
Date User Action Args
2022-04-11 14:58:20adminsetgithub: 69274
2019-12-29 05:16:12gvanrossumsetstatus: open -> closed
resolution: rejected
messages: + msg358979

stage: resolved
2019-12-28 19:05:09BTaskayasetnosy: + BTaskaya
messages: + msg358957
2015-09-13 17:40:16gvanrossumsetmessages: + msg250580
2015-09-13 13:52:18skrahcreate