Skip to content

Commit

Permalink
issue #10827 member variable with type annotation and not used anywhe…
Browse files Browse the repository at this point in the history
…re of python class is missed

Handle type annotation for class variables
  • Loading branch information
albert-github committed Apr 29, 2024
1 parent e059191 commit a1a68d7
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions src/pyscanner.l
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ static void initParser(yyscan_t yyscanner);
static void initEntry(yyscan_t yyscanner);
static void newEntry(yyscan_t yyscanner);
static void addEntry(yyscan_t yyscanner);
static void docVariable(yyscan_t yyscanner,const char *name);
static void docVariable(yyscan_t yyscanner,const QCString &name);
static void newVariable(yyscan_t yyscanner);
static void addVariable(yyscan_t yyscanner);
static void newFunction(yyscan_t yyscanner);
Expand Down Expand Up @@ -544,6 +544,14 @@ ID [a-z_A-Z%]+{IDSYM}*
docVariable(yyscanner,&yytext[5]);
newEntry(yyscanner);
}
"self."{IDENTIFIER}{B}:{B}{IDENTIFIER}/{B}"=" { // with typing
QCString inp(yytext);
int i=inp.find(':');
docVariable(yyscanner,inp.mid(5,i-5).stripWhiteSpace());
yyextra->current->type = inp.mid(i+1).stripWhiteSpace();
yyextra->startInit = false;
newEntry(yyscanner);
}
"cls."{IDENTIFIER}/{B}[,)] {
DBG_CTX((stderr,"Found class method variable %s in %s at %d\n",&yytext[4],qPrint(yyextra->current_root->name),yyextra->yyLineNr));
docVariable(yyscanner,&yytext[4]);
Expand All @@ -554,6 +562,14 @@ ID [a-z_A-Z%]+{IDSYM}*
docVariable(yyscanner,&yytext[4]);
newEntry(yyscanner);
}
"cls."{IDENTIFIER}{B}:{B}{IDENTIFIER}/{B}"=" { // with typing
QCString inp(yytext);
int i=inp.find(':');
docVariable(yyscanner,inp.mid(4,i-4).stripWhiteSpace());
yyextra->current->type = inp.mid(i+1).stripWhiteSpace();
yyextra->startInit = false;
newEntry(yyscanner);
}
{TRIDOUBLEQUOTE} { // start of a comment block
initTriDoubleQuoteBlock(yyscanner);
BEGIN(TripleComment);
Expand Down Expand Up @@ -1757,9 +1773,18 @@ static void setProtection(yyscan_t yyscanner)
}
}

static void docVariable(yyscan_t yyscanner,const char *name)
static void docVariable(yyscan_t yyscanner,const QCString &name)
{
struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
for (auto &v : yyextra->current_root->children())
{
if (v->name == name)
{
v->section=EntryType::makeVariable();
yyextra->current = v;
return;
}
}
yyextra->current->name = name;
yyextra->current->section=EntryType::makeVariable();
yyextra->current->fileName = yyextra->fileName;
Expand Down

0 comments on commit a1a68d7

Please sign in to comment.