Skip to content

Commit a9942cb

Browse files
committed
Some commentary about dot notation for accessing Member
1 parent c3dd997 commit a9942cb

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

pep.rst

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1321,6 +1321,40 @@ Support TypeScript style pattern matching in subtype checking
13211321
This would almost certainly only be possible if we also decide not to
13221322
care about runtime evaluation, as above.
13231323

1324+
Support dot notation to access ``Members`` components
1325+
-----------------------------------------------------
1326+
1327+
Code would read quite a bit nicer if we could write ``m.name`` instead
1328+
of ``GetName[m]``. A general mechanism to support that might look
1329+
like::
1330+
1331+
class Member[N: str, T, Q: MemberQuals = typing.Never, D = typing.Never]:
1332+
type name = N
1333+
type tp = T
1334+
type quals = Q
1335+
type definer = D
1336+
1337+
We considered this but rejected it due to runtime implementation
1338+
concerns: an expression like ``Member[Literal["x", int]].name`` would
1339+
need to return an object that captures both the content of the type
1340+
alias while maintaining the ``_GenericAlias`` of the applied class so
1341+
that type variables may be substituted for.
1342+
1343+
We may have been mistaken about the runtime evaluation difficulty,
1344+
though: if we required a special base class in order for a type to use
1345+
this feature, it should work without too much trouble, and without
1346+
causing any backporting or compatibility problems.
1347+
1348+
We wouldn't be able to have the operation lift over unions or the like
1349+
(unless we were willing to modify ``__getattr__`` for
1350+
``types.UnionType`` and ``typing._UnionGenericAlias`` to do so!)
1351+
1352+
That just leave semantic and philosophical concerns: it arguably makes
1353+
the model more complicated, but a lot of code will read much nicer.
1354+
1355+
TODO: Should we do this?
1356+
1357+
13241358
Replace ``IsSub`` with something weaker than "assignable to" checking
13251359
---------------------------------------------------------------------
13261360

0 commit comments

Comments
 (0)