@@ -1813,10 +1813,7 @@ def need_annotation_for_var(
18131813 type_dec = "<type>"
18141814 if not node .type .type :
18151815 # partial None
1816- if options .use_or_syntax ():
1817- recommended_type = f"{ type_dec } | None"
1818- else :
1819- recommended_type = f"Optional[{ type_dec } ]"
1816+ recommended_type = f"{ type_dec } | None"
18201817 elif node .type .type .fullname in reverse_builtin_aliases :
18211818 # partial types other than partial None
18221819 name = node .type .type .fullname .partition ("." )[2 ]
@@ -2713,17 +2710,9 @@ def format_literal_value(typ: LiteralType) -> str:
27132710 )
27142711
27152712 if len (union_items ) == 1 and isinstance (get_proper_type (union_items [0 ]), NoneType ):
2716- return (
2717- f"{ literal_str } | None"
2718- if options .use_or_syntax ()
2719- else f"Optional[{ literal_str } ]"
2720- )
2713+ return f"{ literal_str } | None"
27212714 elif union_items :
2722- return (
2723- f"{ literal_str } | { format_union (union_items )} "
2724- if options .use_or_syntax ()
2725- else f"Union[{ ', ' .join (format_union_items (union_items ))} , { literal_str } ]"
2726- )
2715+ return f"{ literal_str } | { format_union (union_items )} "
27272716 else :
27282717 return literal_str
27292718 else :
@@ -2734,17 +2723,9 @@ def format_literal_value(typ: LiteralType) -> str:
27342723 )
27352724 if print_as_optional :
27362725 rest = [t for t in typ .items if not isinstance (get_proper_type (t ), NoneType )]
2737- return (
2738- f"{ format (rest [0 ])} | None"
2739- if options .use_or_syntax ()
2740- else f"Optional[{ format (rest [0 ])} ]"
2741- )
2726+ return f"{ format (rest [0 ])} | None"
27422727 else :
2743- s = (
2744- format_union (typ .items )
2745- if options .use_or_syntax ()
2746- else f"Union[{ ', ' .join (format_union_items (typ .items ))} ]"
2747- )
2728+ s = format_union (typ .items )
27482729 return s
27492730 elif isinstance (typ , NoneType ):
27502731 return "None"
0 commit comments