@@ -102,6 +102,19 @@ def parse(cls, name):
102102 name = name .split ("." , 1 )[- 1 ]
103103 return cls (name )
104104
105+ @property
106+ def python_target (self ):
107+ bounds = [
108+ [(7 , 0 ), black .mode .TargetVersion .PY27 ],
109+ [(10 , 17 ), black .mode .TargetVersion .PY36 ],
110+ [(15 , 0 ), black .mode .TargetVersion .PY37 ],
111+ [(16 , 3 ), black .mode .TargetVersion .PY310 ],
112+ ]
113+ for bound , target in reversed (bounds ):
114+ if bound <= self .ints :
115+ return target
116+ raise RuntimeError (f"Cannot determine python target for { self .name } " )
117+
105118
106119@dataclass (order = True )
107120class Inherit :
@@ -116,7 +129,7 @@ def apply_on(self, version: Version) -> bool:
116129 return self .born <= version < self .dead
117130
118131
119- _NEXT_MAJOR = 17
132+ _NEXT_MAJOR = 18
120133_VERSIONS = {Version (f"{ major } .0" ) for major in range (7 , _NEXT_MAJOR )}
121134_VERSIONS |= {Version (f"saas-{ saas } " ) for saas in range (1 , 19 )}
122135_VERSIONS |= {Version (f"saas-{ major } .{ minor } " ) for major in range (11 , _NEXT_MAJOR ) for minor in range (1 , 6 )}
@@ -396,7 +409,7 @@ def main(options: Namespace):
396409 if fname in IGNORED_FILES or "test" in fname :
397410 continue
398411 code , _ = _read_python_source (pyfile )
399- node = black .lib2to3_parse (code )
412+ node = black .lib2to3_parse (code , [ version . python_target ] )
400413 try :
401414 list (visitor .visit (node ))
402415 except Exception :
0 commit comments