Split a dotted name into an import path and a final prefix that is to be completed. Examples: 'foo.bar' -> 'foo', 'bar' 'foo.' -> 'foo', '' '.foo' -> '.', 'foo'
(self, dotted_name: str)
| 210 | return pkgutil.iter_modules(search_locations) |
| 211 | |
| 212 | def get_path_and_prefix(self, dotted_name: str) -> tuple[str, str]: |
| 213 | """ |
| 214 | Split a dotted name into an import path and a |
| 215 | final prefix that is to be completed. |
| 216 | |
| 217 | Examples: |
| 218 | 'foo.bar' -> 'foo', 'bar' |
| 219 | 'foo.' -> 'foo', '' |
| 220 | '.foo' -> '.', 'foo' |
| 221 | """ |
| 222 | if '.' not in dotted_name: |
| 223 | return '', dotted_name |
| 224 | if dotted_name.startswith('.'): |
| 225 | stripped = dotted_name.lstrip('.') |
| 226 | dots = '.' * (len(dotted_name) - len(stripped)) |
| 227 | if '.' not in stripped: |
| 228 | return dots, stripped |
| 229 | path, prefix = stripped.rsplit('.', 1) |
| 230 | return dots + path, prefix |
| 231 | path, prefix = dotted_name.rsplit('.', 1) |
| 232 | return path, prefix |
| 233 | |
| 234 | def format_completion(self, path: str, module: str) -> str: |
| 235 | if path == '' or path.endswith('.'): |