Categorize functions in pep8-naming (#624)

This commit is contained in:
Charlie Marsh 2022-11-06 15:29:49 -05:00 committed by GitHub
parent cea9e34942
commit 1cd82d588b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 292 additions and 173 deletions

View file

@ -1,6 +1,7 @@
use std::collections::BTreeMap;
use std::sync::atomic::{AtomicUsize, Ordering};
use rustpython_ast::{Expr, Keyword};
use rustpython_parser::ast::{Located, Location};
fn id() -> usize {
@ -30,9 +31,17 @@ pub struct FunctionScope {
pub uses_locals: bool,
}
#[derive(Clone, Debug, Default)]
pub struct ClassScope<'a> {
pub name: &'a str,
pub bases: &'a [Expr],
pub keywords: &'a [Keyword],
pub decorator_list: &'a [Expr],
}
#[derive(Clone, Debug)]
pub enum ScopeKind {
Class,
pub enum ScopeKind<'a> {
Class(ClassScope<'a>),
Function(FunctionScope),
Generator,
Module,
@ -40,15 +49,15 @@ pub enum ScopeKind {
}
#[derive(Clone, Debug)]
pub struct Scope {
pub struct Scope<'a> {
pub id: usize,
pub kind: ScopeKind,
pub kind: ScopeKind<'a>,
pub import_starred: bool,
pub values: BTreeMap<String, Binding>,
}
impl Scope {
pub fn new(kind: ScopeKind) -> Self {
impl<'a> Scope<'a> {
pub fn new(kind: ScopeKind<'a>) -> Self {
Scope {
id: id(),
kind,