mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-30 07:07:42 +00:00
Enable callers to specify import-style preferences in Importer
(#4717)
This commit is contained in:
parent
ea31229be0
commit
f47a517e79
7 changed files with 116 additions and 34 deletions
|
@ -31,6 +31,7 @@ pub struct Alias<'a> {
|
|||
}
|
||||
|
||||
impl<'a> Import<'a> {
|
||||
/// Creates a new `Import` to import the specified module.
|
||||
pub fn module(name: &'a str) -> Self {
|
||||
Self {
|
||||
name: Alias {
|
||||
|
@ -41,6 +42,20 @@ impl<'a> Import<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a> ImportFrom<'a> {
|
||||
/// Creates a new `ImportFrom` to import a member from the specified module.
|
||||
pub fn member(module: &'a str, name: &'a str) -> Self {
|
||||
Self {
|
||||
module: Some(module),
|
||||
name: Alias {
|
||||
name,
|
||||
as_name: None,
|
||||
},
|
||||
level: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Display for AnyImport<'_> {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
match self {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue