@@ -38,7 +38,7 @@ diagnosis of malformed type aliases downstream.
3838
3939The following examples each include an illustration of some of the suboptimal
4040or confusing behaviors resulting from existing implicit alias declarations.
41- We also introduce explicit aliases of the format :code: ` TypeName: TypeAlias = Expression `
41+ We also introduce explicit aliases of the format `` TypeName: TypeAlias = Expression ` `
4242here for the sake of comparison, but the syntax is discussed in further detail
4343in later sections.
4444
@@ -50,10 +50,10 @@ Forward References:
5050 MyType = "ClassName"
5151 def foo() -> MyType: ...
5252
53- This code snippet should not error so long as :code: ` ClassName ` is defined
53+ This code snippet should not error so long as `` ClassName ` ` is defined
5454later on. However, a type checker is forced to assume that MyType is a value
5555assignment rather than a type alias, and therefore may throw spurious errors
56- that (1) :code: ` MyType ` is an unannotated global string, and (2) :code: ` MyType `
56+ that (1) `` MyType `` is an unannotated global string, and (2) `` MyType ` `
5757cannot be used as a return annotation because it is not a valid type.
5858
5959::
@@ -62,7 +62,7 @@ cannot be used as a return annotation because it is not a valid type.
6262 def foo() -> MyType: ...
6363
6464Explicit aliases remove ambiguity so neither of the above errors will be
65- thrown. Additionally, if something is wrong with :code: ` ClassName `
65+ thrown. Additionally, if something is wrong with `` ClassName ` `
6666(i.e., it’s not actually defined later), the type checker can throw an error.
6767
6868
@@ -74,11 +74,11 @@ Error Messaging:
7474 MyType1 = InvalidType
7575 MyType2 = MyGeneric(int) # i.e., intention was MyGeneric[int]
7676
77- A type checker should warn on this code snippet that :code: ` InvalidType ` is not
77+ A type checker should warn on this code snippet that `` InvalidType ` ` is not
7878a valid type, and therefore cannot be used to annotate an expression or to
7979construct a type alias. Instead, type checkers are forced to throw spurious
80- errors that (1) :code: ` MyType ` is a global expression missing an annotation,
81- and (2) :code: ` MyType ` is not a valid type in all usages of :code: ` MyType `
80+ errors that (1) `` MyType ` ` is a global expression missing an annotation,
81+ and (2) `` MyType `` is not a valid type in all usages of `` MyType ` `
8282across the codebase.
8383
8484::
@@ -87,9 +87,9 @@ across the codebase.
8787 MyType2: TypeAlias = MyGeneric(int)
8888
8989With explicit aliases, the type checker has enough information to error on the
90- actual definition of the bad type alias, and explain why: that :code: ` MyGeneric(int) `
91- and code:` InvalidType ` are not valid types. When the value expression is no longer
92- evaluated as a global value, unactionable type errors on all usages of :code: ` MyType `
90+ actual definition of the bad type alias, and explain why: that `` MyGeneric(int) ` `
91+ and `` InvalidType ` ` are not valid types. When the value expression is no longer
92+ evaluated as a global value, unactionable type errors on all usages of `` MyType ` `
9393across the codebase can be suppressed.
9494
9595Scope Restrictions:
@@ -101,8 +101,8 @@ Scope Restrictions:
101101 def foo() -> None:
102102 x = ClassName
103103
104- The outer :code: ` x ` is a valid type alias, but type checkers must error if the
105- inner :code: ` x ` is ever used as a type because type aliases cannot be defined
104+ The outer `` x ` ` is a valid type alias, but type checkers must error if the
105+ inner `` x ` ` is ever used as a type because type aliases cannot be defined
106106inside a nested scope.
107107This is confusing because the alias declaration rule is not explicit, and because
108108a type error will not be thrown on the location of the inner type alias declaration
@@ -158,7 +158,7 @@ Explicit syntax:
158158
159159Note: The examples above illustrate implicit and explicit alias declarations in
160160isolation. For the sake of backwards compatibility, type checkers should support
161- both simultaneously, meaning an untyped global expression :code: ` x = int ` will
161+ both simultaneously, meaning an untyped global expression `` x = int ` ` will
162162still be considered a valid type alias.
163163
164164
@@ -192,11 +192,11 @@ This looks a lot like an uninitialized variable.
192192 MyType = TypeAlias[int]
193193
194194Along with the option above, this format potentially adds confusion around
195- what the runtime value of :code: ` MyType ` is.
195+ what the runtime value of `` MyType ` ` is.
196196
197197
198- In comparison, the chosen syntax option :code: ` MyType: TypeAlias = int ` is
199- appealing because it still sticks with the :code: ` MyType = int ` assignment
198+ In comparison, the chosen syntax option `` MyType: TypeAlias = int ` ` is
199+ appealing because it still sticks with the `` MyType = int ` ` assignment
200200syntax, and adds some information for the type checker purely as an annotation.
201201
202202
0 commit comments