@@ -2097,45 +2097,41 @@ impl<'a> Checker<'a> {
2097
2097
fn visit_exports ( & mut self ) {
2098
2098
let snapshot = self . semantic . snapshot ( ) ;
2099
2099
2100
- let exports: Vec < ( & str , TextRange ) > = self
2100
+ let exports: Vec < & ast :: ExprStringLiteral > = self
2101
2101
. semantic
2102
2102
. global_scope ( )
2103
2103
. get_all ( "__all__" )
2104
2104
. map ( |binding_id| & self . semantic . bindings [ binding_id] )
2105
2105
. filter_map ( |binding| match & binding. kind {
2106
- BindingKind :: Export ( Export { names } ) => {
2107
- Some ( names. iter ( ) . map ( |name| ( * name, binding. range ( ) ) ) )
2108
- }
2106
+ BindingKind :: Export ( Export { names } ) => Some ( names. iter ( ) . copied ( ) ) ,
2109
2107
_ => None ,
2110
2108
} )
2111
2109
. flatten ( )
2112
2110
. collect ( ) ;
2113
2111
2114
- for ( name , range) in exports {
2115
- if let Some ( binding_id) = self . semantic . global_scope ( ) . get ( name ) {
2112
+ for ast :: ExprStringLiteral { value , range } in exports {
2113
+ if let Some ( binding_id) = self . semantic . global_scope ( ) . get ( value . to_str ( ) ) {
2116
2114
// Mark anything referenced in `__all__` as used.
2117
- // TODO(charlie): `range` here should be the range of the name in `__all__`, not
2118
- // the range of `__all__` itself.
2119
2115
self . semantic
2120
- . add_global_reference ( binding_id, ExprContext :: Load , range) ;
2116
+ . add_global_reference ( binding_id, ExprContext :: Load , * range) ;
2121
2117
} else {
2122
2118
if self . semantic . global_scope ( ) . uses_star_imports ( ) {
2123
2119
if self . enabled ( Rule :: UndefinedLocalWithImportStarUsage ) {
2124
2120
self . diagnostics . push ( Diagnostic :: new (
2125
2121
pyflakes:: rules:: UndefinedLocalWithImportStarUsage {
2126
- name : ( * name ) . to_string ( ) ,
2122
+ name : value . to_string ( ) ,
2127
2123
} ,
2128
- range,
2124
+ * range,
2129
2125
) ) ;
2130
2126
}
2131
2127
} else {
2132
2128
if self . enabled ( Rule :: UndefinedExport ) {
2133
2129
if !self . path . ends_with ( "__init__.py" ) {
2134
2130
self . diagnostics . push ( Diagnostic :: new (
2135
2131
pyflakes:: rules:: UndefinedExport {
2136
- name : ( * name ) . to_string ( ) ,
2132
+ name : value . to_string ( ) ,
2137
2133
} ,
2138
- range,
2134
+ * range,
2139
2135
) ) ;
2140
2136
}
2141
2137
}
0 commit comments