mirror of
https://github.com/pytorch/pytorch.git
synced 2025-11-11 22:34:53 +08:00
[JIT] Make NoneType annotation_str emit NoneType instead of None (#54642)
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/54642 Test Plan: Imported from OSS Reviewed By: SplitInfinity Differential Revision: D27314174 Pulled By: jamesr66a fbshipit-source-id: 153e9aa4ab781fa1d49d9d55a2e487bf7b04f0d7
This commit is contained in:
committed by
Facebook GitHub Bot
parent
1e9ad6e5cd
commit
3db2333d09
@ -11562,6 +11562,15 @@ dedent """
|
||||
return x
|
||||
''')
|
||||
|
||||
def test_parse_none_type_annotation(self):
|
||||
cu = torch.jit.CompilationUnit('''
|
||||
def foo(x : NoneType) -> NoneType:
|
||||
return x
|
||||
''')
|
||||
|
||||
foo_code = cu.find_function('foo').code
|
||||
FileCheck().check(": None").check("-> None").run(foo_code)
|
||||
|
||||
def test_zip_enumerate_modulelist(self):
|
||||
class Sub(torch.nn.Module):
|
||||
def __init__(self):
|
||||
|
||||
@ -119,7 +119,8 @@ namespace jit {
|
||||
_(TK_WITH_ITEM, "withitem", "") \
|
||||
_(TK_AS, "as", "as") \
|
||||
_(TK_PROP, "property", "") \
|
||||
_(TK_ELLIPSIS, "Ellipsis", "Ellipsis")
|
||||
_(TK_ELLIPSIS, "Ellipsis", "Ellipsis") \
|
||||
_(TK_NONE_TYPE, "NoneType", "NoneType")
|
||||
|
||||
enum TokenKind {
|
||||
// we use characters to represent themselves so skip all valid characters
|
||||
|
||||
@ -115,7 +115,8 @@ struct ParserImpl {
|
||||
} break;
|
||||
case TK_TRUE:
|
||||
case TK_FALSE:
|
||||
case TK_NONE: {
|
||||
case TK_NONE:
|
||||
case TK_NONE_TYPE: {
|
||||
auto k = L.cur().kind;
|
||||
auto r = L.cur().range;
|
||||
prefix = create_compound(k, r, {});
|
||||
|
||||
@ -60,13 +60,14 @@ TypePtr SchemaTypeParser::parseBaseType() {
|
||||
{"int", IntType::get()},
|
||||
{"bool", BoolType::get()},
|
||||
{"None", NoneType::get()},
|
||||
{"NoneType", NoneType::get()},
|
||||
{"Capsule", CapsuleType::get()},
|
||||
{"Any", at::AnyType::get()},
|
||||
{"AnyClassType", at::AnyClassType::get()},
|
||||
{"AnyEnumType", at::AnyEnumType::get()},
|
||||
};
|
||||
auto tok = L.cur();
|
||||
if (!L.nextIf(TK_NONE)) {
|
||||
if (!L.nextIf(TK_NONE) && !L.nextIf(TK_NONE_TYPE)) {
|
||||
L.expect(TK_IDENT);
|
||||
}
|
||||
std::string text = tok.text();
|
||||
|
||||
@ -203,6 +203,9 @@ c10::optional<std::string> ScriptTypeParser::parseBaseTypeName(
|
||||
case TK_NONE: {
|
||||
return "None";
|
||||
}
|
||||
case TK_NONE_TYPE: {
|
||||
return "NoneType";
|
||||
}
|
||||
case '.': {
|
||||
auto select = Select(expr);
|
||||
const std::string& name = select.selector().name();
|
||||
|
||||
@ -17,6 +17,7 @@ const std::unordered_map<std::string, TypePtr>& string_to_type_lut() {
|
||||
// parsing serialized methods that use implicit conversions to Scalar
|
||||
{"number", NumberType::get()},
|
||||
{"None", NoneType::get()},
|
||||
{"NoneType", NoneType::get()},
|
||||
{"Any", AnyType::get()},
|
||||
{"Capsule", CapsuleType::get()},
|
||||
{"list", AnyListType::get()},
|
||||
|
||||
@ -292,6 +292,7 @@ struct Expr : public TreeView {
|
||||
case TK_TRUE:
|
||||
case TK_FALSE:
|
||||
case TK_NONE:
|
||||
case TK_NONE_TYPE:
|
||||
case TK_CAST:
|
||||
case TK_APPLY:
|
||||
case '.':
|
||||
|
||||
Reference in New Issue
Block a user